File tree Expand file tree Collapse file tree 8 files changed +67
-17
lines changed Expand file tree Collapse file tree 8 files changed +67
-17
lines changed Original file line number Diff line number Diff line change 1+ .card {
2+ border : 1px solid;
3+ max-width : 400px ;
4+ min-height : 100px ;
5+ border-radius : 16px ;
6+ padding : 16px ;
7+ }
Original file line number Diff line number Diff line change 1+ import styles from './Card.module.css'
2+
3+ function Card ( { children } ) {
4+ return (
5+ < div className = { styles . card } >
6+ { children }
7+ </ div >
8+ )
9+ }
10+
11+ export default Card
File renamed without changes.
Original file line number Diff line number Diff line change 11import Link from 'next/link'
22import Page from '@/common/layout/page'
3+
34import { Inter } from 'next/font/google'
4- import styles from '@/styles /Home.module.css'
5+ import styles from '. /Home.module.css'
56import navlinks from './items.json'
67
78const inter = Inter ( { subsets : [ 'latin' ] } )
Original file line number Diff line number Diff line change 11import PropTypes from 'prop-types'
22import Page from '@/common/layout/page'
3+ import Card from '@/common/ui/card'
4+ import TodoListComponent from '@/domain/redux/todolist'
35
46function ReduxComponent ( {
5- todos,
67 addTodo,
78 deleteTodo
89} ) {
@@ -17,20 +18,19 @@ function ReduxComponent ({
1718 Add Todo
1819 </ button >
1920
20- < ul style = { { marginTop : '24px' } } >
21- { ( todos ) . map ( ( ( item , id ) => (
22- < li key = { id } >
23- < span > id: { item . id } , { item . text } </ span >
24- < span >
25- < button onClick = { ( ) => deleteTodo ( item . id ) } >
26- [ x ]
27- </ button >
28- </ span >
29- </ li >
30- ) ) ) }
31- </ ul >
21+ < TodoListComponent deleteTodo = { deleteTodo } />
22+ < br />
23+
24+ < Card >
25+ hello
26+ </ Card >
3227 </ Page >
3328 )
3429}
3530
31+ ReduxComponent . propTypes = {
32+ addTodo : PropTypes . func ,
33+ deleteTodo : PropTypes . func
34+ }
35+
3636export default ReduxComponent
Original file line number Diff line number Diff line change 1+ import PropTypes from 'prop-types'
2+ import { useSelector } from 'react-redux'
3+
4+ function TodoListComponent ( { deleteTodo } ) {
5+ const { ids, entities : todos } = useSelector ( state => state . todos )
6+
7+ return (
8+ < ul style = { { marginTop : '24px' } } >
9+ { ( ids ) . map ( ( ( id , index ) => (
10+ < li key = { index } >
11+ < span > id: { todos [ id ] . id } , { todos [ id ] . text } </ span >
12+ < span >
13+ < button onClick = { ( ) => deleteTodo ( id ) } >
14+ [ x ]
15+ </ button >
16+ </ span >
17+ </ li >
18+ ) ) ) }
19+ </ ul >
20+ )
21+ }
22+
23+ TodoListComponent . propTypes = {
24+ deleteTodo : PropTypes . func
25+ }
26+
27+ export default TodoListComponent
Original file line number Diff line number Diff line change 1+ // Notes:
2+ // https://redux.js.org/tutorials/essentials/part-6-performance-normalization#normalized-state-structure
3+ // https://redux.js.org/tutorials/essentials/part-6-performance-normalization#optimizing-the-posts-list
4+
15import {
26 createSlice ,
37 createEntityAdapter
@@ -8,10 +12,12 @@ const STATES = {
812 PENDING : 'pending'
913}
1014
15+ // Entiti adapter
1116const todosAdapter = createEntityAdapter ( {
1217 selectId : ( todo ) => todo . id
1318} )
1419
20+ // Slice
1521const todoSlice = createSlice ( {
1622 name : 'todos' ,
1723 initialState : todosAdapter . getInitialState ( {
Original file line number Diff line number Diff line change 1- import { useSelector , useDispatch } from 'react-redux'
1+ import { useDispatch } from 'react-redux'
22import { todoReceived , todoDelete } from '@/lib/store/todos/todoSlice'
33
44import ReduxComponent from '@/components/redux'
55
66function ReduxContainer ( ) {
77 const dispatch = useDispatch ( )
8- const todos = useSelector ( state => state . todos )
98
109 const addTodo = ( ) => {
1110 dispatch ( todoReceived ( {
@@ -19,7 +18,6 @@ function ReduxContainer () {
1918
2019 return (
2120 < ReduxComponent
22- todos = { todos . ids . map ( id => todos . entities [ id ] ) }
2321 addTodo = { addTodo }
2422 deleteTodo = { deleteTodo }
2523 />
You can’t perform that action at this time.
0 commit comments