Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/app/todoSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ export const counterSlice = createSlice({
state.todos = state.todos.filter(todo => todo.id !== action.payload)
},
toggleCheckTodo: (state, action: PayloadAction<TodoItem['id']>) => {
// Fix me please =\
state.todos = state.todos.map((todo) => {
if (todo.id === action.payload) {
return {...todo, checked: !todo.checked}
}
return todo
})
},
},
})
Expand Down
7 changes: 2 additions & 5 deletions src/components/Checkbox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,21 @@ type CheckboxTypes = {
checked: boolean
onDelete: () => void
text: string
onKeyUp: (e: React.KeyboardEvent<HTMLDivElement>) => void
}

export const Checkbox = ({ checked, text, onClick, onDelete, onKeyUp }: CheckboxTypes) => (
export const Checkbox = ({ checked, text, onClick, onDelete }: CheckboxTypes) => (
<div className="checkbox">
<div
tabIndex={0}
role="checkbox"
aria-checked
className="checkbox-content"
onClick={onClick}
onKeyUp={onKeyUp}
>
<input
tabIndex={-1}
type="checkbox"
checked={checked}
onChange={onClick}
defaultChecked={checked}
/>
<span className={checked ? "checkbox-checked" : ""}>{text}</span>
</div>
Expand Down
5 changes: 4 additions & 1 deletion src/components/Form/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import React, { KeyboardEvent, useState } from "react"
import { TodoActions } from "../../app/store"
import "./form.scss"


export const TodoForm = () => {
const [task, setTask] = useState("")

const handleAddTodo = () => {
// Исправить добавления задания
TodoActions.createTodo(task)
setTask("")
}

const handleKeyUp = (e: KeyboardEvent) => {
Expand Down
15 changes: 5 additions & 10 deletions src/components/List/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,23 @@ import * as React from "react"
import { Checkbox } from "../Checkbox"
import "./list.scss"
import { useAppSelector } from "../../app/hooks"
import { TodoActions } from "../../app/store"

export const TodoList = () => {
const todos = useAppSelector(state => state.todo.todos)
const completeTodos = todos.filter(todo => todo.checked)

const handleDelete = (id: number) => {
// Исправить удаление задания
TodoActions.deleteTodo(id)
}

const toggleCheck = (id: number) => {
// Исправить завершение задания
}

const handleKeyUp = (e: React.KeyboardEvent<HTMLDivElement>, id: number) => {
if (e.keyCode === 13) {
toggleCheck(id)
}
TodoActions.toggleCheckTodo(id)
}

return (
<div className="todo-list">
<span className="todo-list-title">Список заданий</span>
<span className="todo-list-title">Список заданий {todos.length ? `(${completeTodos.length}/${todos.length})` : ''}</span>
{todos.length ? (
<div className="todo-list-content">
{todos.map((todoItem) => (
Expand All @@ -31,7 +27,6 @@ export const TodoList = () => {
text={todoItem.text}
checked={todoItem.checked}
onClick={() => toggleCheck(todoItem.id)}
onKeyUp={(e) => handleKeyUp(e, todoItem.id)}
onDelete={() => handleDelete(todoItem.id)}
/>
))}
Expand Down
1 change: 1 addition & 0 deletions src/components/List/list.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
&-content {
display: flex;
justify-content: center;
flex-direction: column;
}
}

Expand Down