Skip to content

Commit

Permalink
made solution
Browse files Browse the repository at this point in the history
  • Loading branch information
futdevelop committed Feb 21, 2025
1 parent c867b63 commit a93f0a4
Show file tree
Hide file tree
Showing 11 changed files with 276 additions and 143 deletions.
150 changes: 8 additions & 142 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,156 +1,22 @@
/* eslint-disable jsx-a11y/control-has-associated-label */
import React from 'react';
import React, { useContext } from 'react';

Check failure on line 2 in src/App.tsx

View workflow job for this annotation

GitHub Actions / run_linter (20.x)

'useContext' is defined but never used
import { TodoHeader } from './components/TodoHeader';
import { TodoFooter } from './components/TodoFooter';
import { TodoList } from './components/TodoList';
import { TodoContext } from './context/TodoContext';

Check failure on line 6 in src/App.tsx

View workflow job for this annotation

GitHub Actions / run_linter (20.x)

'TodoContext' is defined but never used

export const App: React.FC = () => {
return (
<div className="todoapp">
<h1 className="todoapp__title">todos</h1>

<div className="todoapp__content">
<header className="todoapp__header">
{/* this button should have `active` class only if all todos are completed */}
<button
type="button"
className="todoapp__toggle-all active"
data-cy="ToggleAllButton"
/>
<TodoHeader />

{/* Add a todo on form submit */}
<form>
<input
data-cy="NewTodoField"
type="text"
className="todoapp__new-todo"
placeholder="What needs to be done?"
/>
</form>
</header>

<section className="todoapp__main" data-cy="TodoList">
{/* This is a completed todo */}
<div data-cy="Todo" className="todo completed">
<label className="todo__status-label">
<input
data-cy="TodoStatus"
type="checkbox"
className="todo__status"
checked
/>
</label>

<span data-cy="TodoTitle" className="todo__title">
Completed Todo
</span>

{/* Remove button appears only on hover */}
<button type="button" className="todo__remove" data-cy="TodoDelete">
×
</button>
</div>

{/* This todo is an active todo */}
<div data-cy="Todo" className="todo">
<label className="todo__status-label">
<input
data-cy="TodoStatus"
type="checkbox"
className="todo__status"
/>
</label>

<span data-cy="TodoTitle" className="todo__title">
Not Completed Todo
</span>

<button type="button" className="todo__remove" data-cy="TodoDelete">
×
</button>
</div>

{/* This todo is being edited */}
<div data-cy="Todo" className="todo">
<label className="todo__status-label">
<input
data-cy="TodoStatus"
type="checkbox"
className="todo__status"
/>
</label>

{/* This form is shown instead of the title and remove button */}
<form>
<input
data-cy="TodoTitleField"
type="text"
className="todo__title-field"
placeholder="Empty todo will be deleted"
value="Todo is being edited now"
/>
</form>
</div>

{/* This todo is in loadind state */}
<div data-cy="Todo" className="todo">
<label className="todo__status-label">
<input
data-cy="TodoStatus"
type="checkbox"
className="todo__status"
/>
</label>

<span data-cy="TodoTitle" className="todo__title">
Todo is being saved now
</span>

<button type="button" className="todo__remove" data-cy="TodoDelete">
×
</button>
</div>
</section>
<TodoList />

{/* Hide the footer if there are no todos */}
<footer className="todoapp__footer" data-cy="Footer">
<span className="todo-count" data-cy="TodosCounter">
3 items left
</span>

{/* Active link should have the 'selected' class */}
<nav className="filter" data-cy="Filter">
<a
href="#/"
className="filter__link selected"
data-cy="FilterLinkAll"
>
All
</a>

<a
href="#/active"
className="filter__link"
data-cy="FilterLinkActive"
>
Active
</a>

<a
href="#/completed"
className="filter__link"
data-cy="FilterLinkCompleted"
>
Completed
</a>
</nav>

{/* this button should be disabled if there are no completed todos */}
<button
type="button"
className="todoapp__clear-completed"
data-cy="ClearCompletedButton"
>
Clear completed
</button>
</footer>
<TodoFooter />
</div>
</div>
);
Expand Down
41 changes: 41 additions & 0 deletions src/components/TodoFooter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React from 'react';

type TodoFooterProps = {};

export const TodoFooter: React.FC<TodoFooterProps> = () => {
return (
<footer className="todoapp__footer" data-cy="Footer">
<span className="todo-count" data-cy="TodosCounter">
3 items left
</span>

{/* Active link should have the 'selected' class */}
<nav className="filter" data-cy="Filter">
<a href="#/" className="filter__link selected" data-cy="FilterLinkAll">
All
</a>

<a href="#/active" className="filter__link" data-cy="FilterLinkActive">
Active
</a>

<a
href="#/completed"
className="filter__link"
data-cy="FilterLinkCompleted"
>
Completed
</a>
</nav>

{/* this button should be disabled if there are no completed todos */}
<button
type="button"
className="todoapp__clear-completed"
data-cy="ClearCompletedButton"
>
Clear completed
</button>
</footer>
);
};
32 changes: 32 additions & 0 deletions src/components/TodoHeader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React, { useCallback, useContext } from 'react';

Check failure on line 1 in src/components/TodoHeader.tsx

View workflow job for this annotation

GitHub Actions / run_linter (20.x)

'useCallback' is defined but never used
import { TodoContext } from '../context/TodoContext';
import { Todo } from '../type';

Check failure on line 3 in src/components/TodoHeader.tsx

View workflow job for this annotation

GitHub Actions / run_linter (20.x)

'Todo' is defined but never used

type TodoHeaderProps = {};

export const TodoHeader: React.FC<TodoHeaderProps> = () => {
const { todos, setTodos } = useContext(TodoContext);

Check failure on line 8 in src/components/TodoHeader.tsx

View workflow job for this annotation

GitHub Actions / run_linter (20.x)

'setTodos' is assigned a value but never used

console.log(todos)

Check failure on line 10 in src/components/TodoHeader.tsx

View workflow job for this annotation

GitHub Actions / run_linter (20.x)

Unexpected console statement

return (
<header className="todoapp__header">
{/* this button should have `active` class only if all todos are completed */}
<button
type="button"
className="todoapp__toggle-all active"
data-cy="ToggleAllButton"
/>

{/* Add a todo on form submit */}
<form>
<input
data-cy="NewTodoField"
type="text"
className="todoapp__new-todo"
placeholder="What needs to be done?"
/>
</form>
</header>
);
};
11 changes: 11 additions & 0 deletions src/components/TodoItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react';

type TodoItemProps = {};

export const TodoItem: React.FC<TodoItemProps> = () => {
return (
<div>

</div>
);
};
90 changes: 90 additions & 0 deletions src/components/TodoList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import React from 'react';

type TodoListProps = {};

export const TodoList: React.FC<TodoListProps> = () => {
return (
<section className="todoapp__main" data-cy="TodoList">
{/* This is a completed todo */}
<div data-cy="Todo" className="todo completed">
<label className="todo__status-label">

Check failure on line 10 in src/components/TodoList.tsx

View workflow job for this annotation

GitHub Actions / run_linter (20.x)

A form label must be associated with a control
<input
data-cy="TodoStatus"
type="checkbox"
className="todo__status"
checked
/>
</label>

<span data-cy="TodoTitle" className="todo__title">
Completed Todo
</span>

{/* Remove button appears only on hover */}
<button type="button" className="todo__remove" data-cy="TodoDelete">
×
</button>
</div>

{/* This todo is an active todo */}
<div data-cy="Todo" className="todo">
<label className="todo__status-label">

Check failure on line 31 in src/components/TodoList.tsx

View workflow job for this annotation

GitHub Actions / run_linter (20.x)

A form label must be associated with a control
<input
data-cy="TodoStatus"
type="checkbox"
className="todo__status"
/>
</label>

<span data-cy="TodoTitle" className="todo__title">
Not Completed Todo
</span>

<button type="button" className="todo__remove" data-cy="TodoDelete">
×
</button>
</div>

{/* This todo is being edited */}
<div data-cy="Todo" className="todo">
<label className="todo__status-label">

Check failure on line 50 in src/components/TodoList.tsx

View workflow job for this annotation

GitHub Actions / run_linter (20.x)

A form label must be associated with a control
<input
data-cy="TodoStatus"
type="checkbox"
className="todo__status"
/>
</label>

{/* This form is shown instead of the title and remove button */}
<form>
<input
data-cy="TodoTitleField"
type="text"
className="todo__title-field"
placeholder="Empty todo will be deleted"
value="Todo is being edited now"
/>
</form>
</div>

{/* This todo is in loadind state */}
<div data-cy="Todo" className="todo">
<label className="todo__status-label">

Check failure on line 72 in src/components/TodoList.tsx

View workflow job for this annotation

GitHub Actions / run_linter (20.x)

A form label must be associated with a control
<input
data-cy="TodoStatus"
type="checkbox"
className="todo__status"
/>
</label>

<span data-cy="TodoTitle" className="todo__title">
Todo is being saved now
</span>

<button type="button" className="todo__remove" data-cy="TodoDelete">
×
</button>
</div>
</section>
);
};
Loading

0 comments on commit a93f0a4

Please sign in to comment.