Skip to content

Commit f66dfc3

Browse files
committed
add in-progress button in each item
1 parent cae9274 commit f66dfc3

File tree

3 files changed

+63
-4
lines changed

3 files changed

+63
-4
lines changed

src/App/NewTodoInput/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@ const NewTodoTextInput: React.FC = () => {
1919
const todo: Todo = {
2020
bodyText: textInput.current.value,
2121
completed: false,
22+
inProgress: false,
2223
id: UUID(),
2324
}
2425

2526
// add new TODO to entire TodoList
26-
setAppState({ todoList: [todo, ...appState.todoList] })
27+
setAppState({
28+
todoList: [todo, ...appState.todoList],
29+
})
2730

2831
// reset text input UI value
2932
textInput.current.value = ''

src/App/TodoList/Item/index.tsx

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,19 @@ const Item: React.FC<Props> = ({ todo }) => {
8080
setAppState({ todoList: removed })
8181
}
8282

83-
const handleTodoTextEdit = (e: React.ChangeEvent<HTMLInputElement>, onEdit: Todo['id']): void => { /* eslint-disable-line prettier/prettier */
83+
const setInprogress = (id: Todo['id']) => {
84+
let temp: TodoListType = appState.todoList.map((t) =>
85+
t.inProgress ? { ...t, inProgress: false } : t
86+
)
87+
temp = temp.map((t) => (t.id === id ? { ...t, inProgress: true } : t))
88+
setAppState({ todoList: temp })
89+
}
90+
91+
const handleTodoTextEdit = (
92+
e: React.ChangeEvent<HTMLInputElement>,
93+
onEdit: Todo['id']
94+
): void => {
95+
/* eslint-disable-line prettier/prettier */
8496
const edited = appState.todoList.map((t: Todo): Todo => {
8597
if (t.id === onEdit) {
8698
return { ...t, bodyText: e.target.value }
@@ -112,13 +124,25 @@ const Item: React.FC<Props> = ({ todo }) => {
112124
/>
113125

114126
{/* eslint-disable jsx-a11y/no-noninteractive-element-interactions, jsx-a11y/click-events-have-key-events */}
127+
115128
<label
116129
onClick={onClick}
117130
data-cy="todo-body-text"
118131
data-testid="todo-body-text"
119132
>
120133
{todo.bodyText}
121134
</label>
135+
{!todo.completed && todo.inProgress && (
136+
<span className="inProgressActiveBadeg">In Progress</span>
137+
)}
138+
{!todo.completed && !todo.inProgress && (
139+
<span
140+
className="inProgressBadeg"
141+
onClick={() => setInprogress(todo.id)}
142+
>
143+
In Progress
144+
</span>
145+
)}
122146
{/* eslint-enable jsx-a11y/no-noninteractive-element-interactions, jsx-a11y/click-events-have-key-events */}
123147
<button
124148
className="destroy"
@@ -132,8 +156,12 @@ const Item: React.FC<Props> = ({ todo }) => {
132156
onBlur={(e: React.FocusEvent<HTMLInputElement>) => onBlurEdit(e)}
133157
className="edit"
134158
value={todo.bodyText}
135-
onChange={(e: React.ChangeEvent<HTMLInputElement>) => handleTodoTextEdit(e, todo.id)} /* eslint-disable-line prettier/prettier */
136-
onKeyDown={(e: React.KeyboardEvent<HTMLInputElement>) => submitEditText(e)} /* eslint-disable-line prettier/prettier */
159+
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
160+
handleTodoTextEdit(e, todo.id)
161+
} /* eslint-disable-line prettier/prettier */
162+
onKeyDown={(e: React.KeyboardEvent<HTMLInputElement>) =>
163+
submitEditText(e)
164+
} /* eslint-disable-line prettier/prettier */
137165
data-cy="todo-edit-input"
138166
data-testid="todo-edit-input"
139167
/>

src/App/TodoList/Item/style.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ export const Layout = styled.div`
3535
margin: 0 0 0 43px;
3636
}
3737
38+
.view {
39+
display: flex;
40+
align-items: center;
41+
justify-content: space-between;
42+
}
43+
3844
.editing .view {
3945
display: none;
4046
}
@@ -111,4 +117,26 @@ export const Layout = styled.div`
111117
.editing:last-child {
112118
margin-bottom: -1px;
113119
}
120+
121+
.inProgressActiveBadeg {
122+
padding: 3px 5px;
123+
border-radius: 3px;
124+
font-size: 0.5em;
125+
background-color: #f39c12;
126+
color: white;
127+
font-weight: 600;
128+
margin-right: 70px;
129+
cursor: pointer;
130+
}
131+
132+
.inProgressBadeg {
133+
padding: 3px 5px;
134+
border-radius: 3px;
135+
font-size: 0.5em;
136+
background-color: #bdc3c7;
137+
color: white;
138+
font-weight: 600;
139+
margin-right: 70px;
140+
cursor: pointer;
141+
}
114142
`

0 commit comments

Comments
 (0)