Browse Source

type ok

main
SimonBurdy 4 years ago
parent
commit
205c08d802
  1. 6376
      package-lock.json
  2. 16
      src/App.tsx
  3. 4
      src/TodoItem.tsx
  4. 3402
      yarn.lock

6376
package-lock.json
File diff suppressed because it is too large
View File

16
src/App.tsx

@ -1,15 +1,15 @@
import { useState } from 'react';
import { useState } from 'react';
import { faker } from '@faker-js/faker'; import { faker } from '@faker-js/faker';
import { TodoItem } from './TodoItem'; import { TodoItem } from './TodoItem';
import { nanoid } from 'nanoid'; import { nanoid } from 'nanoid';
const generateFakeTodoItem = () => ({
const generateFakeTodoItem = ():{ label:string , status:string , id:string} => ({
label: faker.hacker.phrase(), label: faker.hacker.phrase(),
status: faker.random.arrayElement(['open', 'done', 'archived']), status: faker.random.arrayElement(['open', 'done', 'archived']),
id: nanoid(), id: nanoid(),
}); });
const generateNTodo = (size) => {
const generateNTodo = (size: number):{ label:string , status:string , id:string}[] => {
return Array.from(Array(size).keys()).map(generateFakeTodoItem); return Array.from(Array(size).keys()).map(generateFakeTodoItem);
}; };
@ -32,12 +32,12 @@ const initialList = [
...generateNTodo(10), ...generateNTodo(10),
]; ];
function App() {
function App(): JSX.Element {
const [todoList, setTodoList] = useState(initialList); const [todoList, setTodoList] = useState(initialList);
const updater = (id, newStatus) => {
setTodoList((oldList) =>
oldList.map((it) => {
const updater = (id:string, newStatus:string):void=> {
setTodoList((oldList:{ label:string , status:string , id:string}[]):{ label:string , status:string , id:string}[] =>
oldList.map((it:{ label:string , status:string , id:string}) => {
if (it.id !== id) { if (it.id !== id) {
return it; return it;
} }
@ -57,7 +57,7 @@ function App() {
key={item.id} key={item.id}
label={item.label} label={item.label}
status={item.status} status={item.status}
onChecked={(newState) => updater(item.id, newState)}
onChecked={(newState:string):void => updater(item.id, newState)}
/> />
))} ))}
</div> </div>

4
src/TodoItem.tsx

@ -1,6 +1,6 @@
import clsx from 'clsx'; import clsx from 'clsx';
export const TodoItem = ({ status, label, onChecked }) => {
export const TodoItem = ({ status, label, onChecked }:{status:string, label:string, onChecked:(state:string)=> void} ):JSX.Element=> {
return ( return (
<div <div
className={clsx('p-4 flex items-center', { className={clsx('p-4 flex items-center', {
@ -17,7 +17,7 @@ export const TodoItem = ({ status, label, onChecked }) => {
disabled={status === 'archived'} disabled={status === 'archived'}
type="checkbox" type="checkbox"
className="rounded text-pink-500 ml-8 cursor-pointer disabled:cursor-not-allowed disabled:bg-black disabled:hover:bg-black" className="rounded text-pink-500 ml-8 cursor-pointer disabled:cursor-not-allowed disabled:bg-black disabled:hover:bg-black"
onChange={() => onChecked(status === 'open' ? 'done' : 'open')}
onChange={():void=> onChecked(status === 'open' ? 'done' : 'open')}
/> />
</div> </div>
); );

3402
yarn.lock
File diff suppressed because it is too large
View File

Loading…
Cancel
Save