diff --git a/src/App.tsx b/src/App.tsx index adaf800..28aee1b 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,10 +1,23 @@ -import React, { useEffect, useState } from 'react'; +import { useState } from 'react'; import './App.css'; import deLocale from 'date-fns/locale/de'; -import { AppBar, Box, Button, Paper, Toolbar, Typography } from '@mui/material'; +import { AppBar, Box, Button, createTheme, CssBaseline, Paper, ThemeProvider, Toolbar, Typography } from '@mui/material'; import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns'; import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider'; import { Todos } from './components/Todos'; +import { Dinos } from './components/Dinos'; + +const theme = createTheme({ + palette: { + mode: 'dark', + primary: { + main: '#aa00ff', + }, + secondary: { + main: '#00b0ff', + }, + }, +}); function Calendar(){ return( @@ -12,14 +25,6 @@ return( ) } -function Dinos(){ -return( -
- Dinos -
-) -} - function Overview(){ return (
@@ -41,6 +46,8 @@ function App() { const [page,setPage] = useState("Overview"); return ( <> + + @@ -70,6 +77,7 @@ function App() {
+ ); } diff --git a/src/components/Dinos.tsx b/src/components/Dinos.tsx new file mode 100644 index 0000000..b8409c2 --- /dev/null +++ b/src/components/Dinos.tsx @@ -0,0 +1,216 @@ +import React, {useState } from 'react'; +import { Box, Button, Card, CardActions, CardContent, Dialog, DialogActions, DialogContent, DialogTitle, Tab, Tabs, TextField, Typography } from '@mui/material'; +import { DatePicker } from '@mui/x-date-pickers'; +import DeleteOutlineRoundedIcon from '@mui/icons-material/DeleteOutlineRounded'; +import EditRoundedIcon from '@mui/icons-material/EditRounded'; +import CakeRoundedIcon from '@mui/icons-material/CakeRounded'; +import EventRoundedIcon from '@mui/icons-material/EventRounded'; +import { useLocalStorage } from '../hooks/useLocalStorage'; + +type Dino = { + name: string, + snames: string, + surname: string, + id: string, + birthday?: string, + description: string, + last?: string +} + +interface TabPanelProps { + children?: React.ReactNode; + id: string; + selected: string; + } + +function TabPanel(props: TabPanelProps) { + const { children, selected, id } = props; + + return ( + + ); + } + +function ShowDino({dino}: {dino: Dino}){ + return( + + + {dino.name} {dino.snames && dino.snames} {dino.surname} + {dino.description && {dino.description}} + {dino.birthday && {(new Date(dino.birthday)).toLocaleDateString()}} + {dino.last && {(new Date(dino.last)).toLocaleDateString()}} + + + ) +} + +function ChangeDino({dino, setDino, handleCancel}: {dino: Dino, setDino: (dino: Dino) => void, handleCancel: () => void}){ + + const [name, setName] = React.useState(dino.name) + const [snames, setSnames] = React.useState(dino.snames) + const [surname, setSurname] = React.useState(dino.surname) + const [description, setDescription] = React.useState(dino.description) + const [birthday, setBirthday] = React.useState(dino.birthday ? new Date(dino.birthday) : null); + const [last, setLast] = React.useState(dino.last ? new Date(dino.last) : null); + + const saveTodo=() => { + const newdino = { + name: name, + snames: snames, + surname: surname, + id: dino.id === "" ? Math.random().toString() : dino.id, + description: description, + birthday: birthday?.toISOString(), + last: last?.toISOString() + }; + setDino(newdino); + } + + return ( + <> + + :not(style)': { m: 2, width: '50ch' }, + }}> + setName(e.target.value)} + /> + setSnames(e.target.value)} + /> + setSurname(e.target.value)} + /> + setDescription(e.target.value)} + /> + setBirthday(e)} + renderInput={(params: any) => } + /> + setLast(e)} + renderInput={(params: any) => } + /> + + + + + + + + ) +} +export function Dinos(){ + const [dinos, setDinos] = useLocalStorage("dinos",[]); + + const [value, setValue] = useState(dinos[0]?.id); + + const handleChange = (event: React.SyntheticEvent, newValue: string) => { + setValue(newValue); + }; + + const deleteDino=(i: number) => + setDinos([...dinos.slice(0,i), + ...dinos.slice(i+1)]); + + const setDino= (dino: Dino) => { + handleClose(); + setDinos([...dinos, dino]); + } + +const [open, setOpen] = useState(false); +const handleClickOpen = () => { + setOpen(true); +}; +const handleClose = () => { + setOpen(false); +}; + +const [open2, setOpen2] = useState(false); +const [edit, setEdit] = useState({name: "", surname: "", description: "", id: "", snames: ""}); +const [editI, setEditI] = useState(0); +const handleClickOpen2 = (dino: Dino, i: number) => { + setOpen2(true); + setEdit(dino); + setEditI(i); +}; +const handleClose2 = () => { + setOpen2(false); +}; + +const editDino= (dino: Dino) => { + handleClose2(); + setDinos([...dinos.slice(0,editI), + dino, + ...dinos.slice(editI+1)]); +} +return( +
+ Dinos + + + {dinos.sort((a,b) => `${a.name}${a.surname}`.localeCompare(`${b.name}${b.surname}`)).map((dino) => + + )} + + + {dinos.map((dino, i) => + + + + + + + + + + + + )} + + New Dino + + + + Edit Dino + + + +
+) +} diff --git a/src/components/Todos.tsx b/src/components/Todos.tsx index c68e8ff..3d52623 100644 --- a/src/components/Todos.tsx +++ b/src/components/Todos.tsx @@ -1,5 +1,5 @@ import React, {useState } from 'react'; -import { Box, Button, Dialog, DialogActions, DialogContent, DialogTitle, Divider, List, ListItem, TextField, Typography } from '@mui/material'; +import { Box, Button, Checkbox, Dialog, DialogActions, DialogContent, DialogTitle, Divider, List, ListItem, TextField, Typography } from '@mui/material'; import { DatePicker } from '@mui/x-date-pickers'; import DeleteOutlineRoundedIcon from '@mui/icons-material/DeleteOutlineRounded'; import EditRoundedIcon from '@mui/icons-material/EditRounded'; @@ -35,15 +35,11 @@ function ChangeTodo({todo, setTodo, handleCancel}: {todo: Todo, setTodo: (todo: setName(event.target.value); }; - const [id, setId] = React.useState(todo.id) - const [description, setDescription] = React.useState(todo.description) const handleDescChange = (event: React.ChangeEvent) => { setDescription(event.target.value); }; - const [done, setDone] = React.useState(todo.done) - const [from, setFrom] = React.useState(todo.from ? new Date(todo.from) : null); const handleFrom = (newValue: Date | null) => { setFrom(newValue); @@ -58,8 +54,8 @@ function ChangeTodo({todo, setTodo, handleCancel}: {todo: Todo, setTodo: (todo: const saveTodo=() => { const newtodo = { name: name, - id: id === "" ? Math.random().toString() : id, - done: done, + id: todo.id === "" ? Math.random().toString() : todo.id, + done: todo.done, description: description, to: to?.toISOString(), from: from?.toISOString() @@ -75,6 +71,7 @@ function ChangeTodo({todo, setTodo, handleCancel}: {todo: Todo, setTodo: (todo: '& > :not(style)': { m: 2, width: '50ch' }, }}> + const deleteTodo=(i: number) => setTodos([...todos.slice(0,i), ...todos.slice(i+1)]); @@ -159,15 +156,15 @@ const editTodo= (todo: Todo) => { {todos.map((todo, i) => - <> +
- setDone(i, todo,e.target.checked)}> + setDone(i, todo,e.target.checked)}> - + {(i + 1) < todos.length && } - +
)}
diff --git a/src/hooks/useLocalStorage.tsx b/src/hooks/useLocalStorage.tsx index 5b694a9..da99b26 100644 --- a/src/hooks/useLocalStorage.tsx +++ b/src/hooks/useLocalStorage.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from 'react'; +import { useEffect, useState } from 'react'; function useLocalStorage(storageKey: string, fallbackState: T): [T, (val: T) => void] { const [value, setValue] = useState(