Skip to content

Commit

Permalink
asdasdada
Browse files Browse the repository at this point in the history
  • Loading branch information
sinner1993 committed Dec 24, 2024
1 parent 8d91581 commit eaaec8b
Show file tree
Hide file tree
Showing 10 changed files with 251 additions and 99 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ Implement the ability to add TODOs to the `TodoList` implemented in the **Static
- 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).
- Open one more terminal and run tests with `npm test` to ensure your solution is correct.
- Replace `<your_account>` with your Github username in the [DEMO LINK](https://<your_account>.github.io/react_add-todo-form/) and add it to the PR description.
- Replace `<your_account>` with your Github username in the [DEMO LINK](https://sinner1993.github.io/react_add-todo-form/) and add it to the PR description.
73 changes: 34 additions & 39 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
"@fortawesome/fontawesome-free": "^6.5.2",
"bulma": "^1.0.1",
"classnames": "^2.5.1",
"react": "^18.3.1",
"react-dom": "^18.3.1"
"react": "^19.0.0",
"react-dom": "^19.0.0"
},
"devDependencies": {
"@cypress/react18": "^2.0.1",
"@mate-academy/scripts": "^1.8.5",
"@mate-academy/scripts": "^1.9.12",
"@mate-academy/students-ts-config": "*",
"@mate-academy/stylelint-config": "*",
"@types/node": "^20.14.10",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@types/react": "^18.3.18",
"@types/react-dom": "^18.3.5",
"@typescript-eslint/parser": "^7.16.0",
"@vitejs/plugin-react": "^4.3.1",
"cypress": "^13.13.0",
Expand All @@ -39,7 +39,7 @@
"prettier": "^3.3.2",
"sass": "^1.77.8",
"stylelint": "^16.7.0",
"typescript": "^5.2.2",
"typescript": "^5.7.2",
"vite": "^5.3.1"
},
"scripts": {
Expand Down
78 changes: 28 additions & 50 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,61 +1,39 @@
import React, { useState } from 'react';
import './App.scss';

// import usersFromServer from './api/users';
// import todosFromServer from './api/todos';
import usersFromServer from './api/users';
import todosFromServer from './api/todos';
import { TodoList } from './components/TodoList';
import { FormPost } from './components/formPost/formPost';
import { ToDo, User } from './types/types';

export const App = () => {
return (
<div className="App">
<h1>Add todo form</h1>

<form action="/api/todos" method="POST">
<div className="field">
<input type="text" data-cy="titleInput" />
<span className="error">Please enter a title</span>
</div>

<div className="field">
<select data-cy="userSelect">
<option value="0" disabled>
Choose a user
</option>
</select>

<span className="error">Please choose a user</span>
</div>

<button type="submit" data-cy="submitButton">
Add
</button>
</form>

<section className="TodoList">
<article data-id="1" className="TodoInfo TodoInfo--completed">
<h2 className="TodoInfo__title">delectus aut autem</h2>
const getUser = (userId: number): User | null => {
return usersFromServer.find(user => user.id === userId) || null;
};

<a className="UserInfo" href="mailto:Sincere@april.biz">
Leanne Graham
</a>
</article>
const initiaTodos: ToDo[] = todosFromServer.map(todo => ({
...todo,
user: getUser(todo.userId),
}));

<article data-id="15" className="TodoInfo TodoInfo--completed">
<h2 className="TodoInfo__title">delectus aut autem</h2>
export const App: React.FC = () => {
const [todos, setTodos] = useState<ToDo[]>(initiaTodos);

<a className="UserInfo" href="mailto:Sincere@april.biz">
Leanne Graham
</a>
</article>
const highestId = Math.max(...todos.map(todo => todo.id));

<article data-id="2" className="TodoInfo">
<h2 className="TodoInfo__title">
quis ut nam facilis et officia qui
</h2>
const addPosts = (newToDo: ToDo) => {
setTodos(prev => [...prev, newToDo]);
};

<a className="UserInfo" href="mailto:Julianne.OConner@kory.org">
Patricia Lebsack
</a>
</article>
</section>
return (
<div className="App">
<h1>Add todo form</h1>
<FormPost
onSubmit={addPosts}
users={usersFromServer}
heighestId={highestId}
/>
<TodoList todos={todos} />
</div>
);
};
20 changes: 19 additions & 1 deletion src/components/TodoInfo/TodoInfo.tsx
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
export const TodoInfo = () => {};
import React from 'react';
import { UserInfo } from '../UserInfo';
import { ToDo } from '../../types/types';

type Props = {
todo: ToDo;
};

export const TodoInfo: React.FC<Props> = ({ todo }) => {
return (
<article
data-id={todo.id}
className={`TodoInfo TodoInfo--${todo.completed && 'completed'}`}
>
<h2 className="TodoInfo__title">{todo.title}</h2>
{todo.user && <UserInfo user={todo.user} />}
</article>
);
};
18 changes: 17 additions & 1 deletion src/components/TodoList/TodoList.tsx
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
export const TodoList = () => {};
import { ToDo } from '../../types/types';
import { TodoInfo } from '../TodoInfo';
import React from 'react';

type Props = {
todos: ToDo[];
};

export const TodoList: React.FC<Props> = ({ todos }) => {
return (
<section className="TodoList">
{todos.map((todo, indx) => {
return <TodoInfo key={indx} todo={todo} />;
})}
</section>
);
};
15 changes: 14 additions & 1 deletion src/components/UserInfo/UserInfo.tsx
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
export const UserInfo = () => {};
import React from 'react';
import { User } from '../../types/types';

type Props = {
user: User;
};

export const UserInfo: React.FC<Props> = ({ user }: { user: User }) => {
return (
<a className="UserInfo" href={`mailto:${user?.email}`}>
{user.name}
</a>
);
};
Loading

0 comments on commit eaaec8b

Please sign in to comment.