Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution #764

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ Implement the ability to edit a todo title on double click:

- Implement a solution following the [React task guideline](https://github.com/mate-academy/react_task-guideline#react-tasks-guideline).
- Use the [React TypeScript cheat sheet](https://mate-academy.github.io/fe-program/js/extra/react-typescript).
- Replace `<your_account>` with your Github username in the [DEMO LINK](https://<your_account>.github.io/react_todo-app-with-api/) and add it to the PR description.
- Replace `<your_account>` with your Github username in the [DEMO LINK](https://Pa1eOrc.github.io/react_todo-app-with-api/) and add it to the PR description.
23 changes: 5 additions & 18 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
/* eslint-disable max-len */
/* eslint-disable jsx-a11y/control-has-associated-label */
import React from 'react';
import { UserWarning } from './UserWarning';

const USER_ID = 0;
import { TodoProvider } from './components/TodoContext/TodoContext';
import { TodoApp } from './components/TodoApp/TodoApp';

export const App: React.FC = () => {
if (!USER_ID) {
return <UserWarning />;
}

return (
<section className="section container">
<p className="title is-4">
Copy all you need from the prev task:
<br />
<a href="https://github.com/mate-academy/react_todo-app-add-and-delete#react-todo-app-add-and-delete">React Todo App - Add and Delete</a>
</p>

<p className="subtitle">Styles are already copied</p>
</section>
<TodoProvider>
<TodoApp />
</TodoProvider>
);
};
20 changes: 20 additions & 0 deletions src/api/todos.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Todo } from '../types/Todo';
import { client } from '../utils/fetchClient';

export const getTodos = (userId: number) => {
return client.get<Todo[]>(`/todos?userId=${userId}`);
};

export const deleteTodo = (id: number) => {
return client.delete(`/todos/${id}`);
};

export const createTodo = ({ userId, title, completed }: Omit<Todo, 'id'>) => {
return client.post<Todo>('/todos', { userId, title, completed });
};

export const updateTodo = ({
id, userId, title, completed,
}: Todo) => {
return client.patch<Todo>(`/todos/${id}`, { userId, title, completed });
};
32 changes: 32 additions & 0 deletions src/components/TempoTodoItem/TempoTodoItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from 'react';
import { Todo } from '../../types/Todo';

type Props = {
tempoTodo: Todo;
};

export const TempoTodoItem: React.FC<Props> = ({ tempoTodo }) => {
return (
<div className="todo">
<label className="todo__status-label">
<input
type="checkbox"
className="todo__status"
title="chekbox"
/>
</label>

<span className="todo__title">{tempoTodo.title}</span>
<button
type="button"
className="todo__remove"
>
×
</button>
<div className="modal overlay is-active">
<div className="modal-background has-background-white-ter" />
<div className="loader" />
</div>
</div>
);
};
40 changes: 40 additions & 0 deletions src/components/TodoApp/TodoApp.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* eslint-disable jsx-a11y/control-has-associated-label */
import React, { useState } from 'react';
import { TodoHeader } from '../TodoHeader/TodoHeader';
import { TodoList } from '../TodoList/TodoList';
import { TodoFooter } from '../TodoFooter/TodoFooter';
import { TodoNotification } from '../TodoNotification/TodoNotification';
import { useTodo } from '../TodoContext/TodoContext';
import { Filter } from '../../types/Enum';

export const TodoApp: React.FC = () => {
const { todos, tempoTodo } = useTodo();
const [selectedFilter, setSelectedFilter] = useState(Filter.All);

return (
<div className="todoapp">
<h1 className="todoapp__title">todos</h1>

<div className="todoapp__content">
<TodoHeader />

{(!!todos.length || tempoTodo) && (
<>
<TodoList
todos={todos}
tempoTodo={tempoTodo}
selectedFilter={selectedFilter}
/>

<TodoFooter
selectedFilter={selectedFilter}
selectTheFilter={setSelectedFilter}
/>
</>
)}
</div>

<TodoNotification />
</div>
);
};
Loading
Loading