diff --git a/src/components/list/Goal.js b/src/components/list/Goal.js index bd5b4fb..19d114b 100644 --- a/src/components/list/Goal.js +++ b/src/components/list/Goal.js @@ -1,6 +1,7 @@ import styles from './Goal.module.css'; import {Link} from "react-router-dom"; + function Goal({ id, details, period, icon, frequency, finish, completed }) { return ( diff --git a/src/components/list/List.js b/src/components/list/List.js index 489a1d6..b80401e 100644 --- a/src/components/list/List.js +++ b/src/components/list/List.js @@ -14,5 +14,4 @@ function List() { ); } - export default List; \ No newline at end of file diff --git a/src/components/new/Details.js b/src/components/new/Details.js index b50c34b..cb35a3c 100644 --- a/src/components/new/Details.js +++ b/src/components/new/Details.js @@ -3,6 +3,7 @@ import {useContext, useEffect, useState} from 'react'; import {Context} from "../../services/Memory"; import {useNavigate, useParams} from "react-router-dom"; + function Details() { const {id} = useParams(); @@ -30,8 +31,8 @@ function Details() { const [state, dispatch] = useContext(Context); const onChange = (e, prop) => { - setForm(estate => ({ - ...estate, + setForm(prevEstate => ({ + ...prevEstate, [prop]: e.target.value })) } @@ -43,7 +44,7 @@ function Details() { if (!id) return; if (!goalMemory) { - return navigate('/notFound'); + return navigate('/list'); } setForm(goalMemory); }, [id, state.objects, navigate]); @@ -139,7 +140,7 @@ function Details() { onChange={(e) => {onChange(e, 'icon')}} > {icons.map((icon) => { - return + return })} diff --git a/src/services/Memory.js b/src/services/Memory.js index f74ccfc..644b818 100644 --- a/src/services/Memory.js +++ b/src/services/Memory.js @@ -76,7 +76,10 @@ const reducer = (state, action) => { orderList: [...state.orderList, id], objects: { ...state.objects, - [id]: action.goal + [id]: { + ...action.goal, + id + } } } } @@ -90,9 +93,10 @@ const reducer = (state, action) => { } case 'DELETE_GOAL': { const id = action.goal.id; + const newOrder = state.orderList.filter((goalId) => goalId !== id); delete state.objects[id]; return { - orderList: state.orderList.filter((goalId) => goalId !== id), + orderList: newOrder, objects: { ...state.objects } } }