Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
To-Do List
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SOFT Core
SOFT 260
To-Do List
Commits
0c2ecf9e
Commit
0c2ecf9e
authored
1 year ago
by
Brady James Garvin
Browse files
Options
Downloads
Patches
Plain Diff
Implemented a basic to-do list app.
parent
058d6c74
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
to-do-list/src/features/toDo/toDo.js
+47
-7
47 additions, 7 deletions
to-do-list/src/features/toDo/toDo.js
to-do-list/src/features/toDo/toDoSlice.js
+35
-2
35 additions, 2 deletions
to-do-list/src/features/toDo/toDoSlice.js
with
82 additions
and
9 deletions
to-do-list/src/features/toDo/toDo.js
+
47
−
7
View file @
0c2ecf9e
//
import { useSelector, useDispatch } from 'react-redux';
import
{
useSelector
,
useDispatch
}
from
'
react-redux
'
;
// import PropTypes from 'prop-types';
// import PropTypes from 'prop-types';
//
import classNames from 'classnames';
import
classNames
from
'
classnames
'
;
//
import styles from './toDo.module.css';
import
styles
from
'
./toDo.module.css
'
;
import
{
import
{
selectDraft
,
selectItems
,
setDraft
,
addItem
,
setDone
,
}
from
'
./toDoSlice.js
'
;
}
from
'
./toDoSlice.js
'
;
function
Item
(
props
)
{
function
Item
(
props
)
{
return
null
;
const
dispatch
=
useDispatch
();
const
classes
=
classNames
({
[
styles
.
done
]:
props
.
done
,
});
const
onClick
=
()
=>
dispatch
(
setDone
({
index
:
props
.
index
,
done
:
!
props
.
done
,
}));
return
(
<
div
className
=
{
styles
.
item
}
>
<
span
className
=
{
classes
}
>
#
{
props
.
index
}
{
props
.
text
}
<
/span
>
<
button
onClick
=
{
onClick
}
>
Done
<
/button
>
<
/div
>
);
}
}
Item
.
propTypes
=
{
//
Item.propTypes = {
};
//
};
export
function
List
()
{
export
function
List
()
{
return
null
;
const
draft
=
useSelector
(
selectDraft
);
const
items
=
useSelector
(
selectItems
);
const
dispatch
=
useDispatch
();
const
onChange
=
(
event
)
=>
dispatch
(
setDraft
({
draft
:
event
.
target
.
value
,
}));
const
onClick
=
()
=>
dispatch
(
addItem
());
return
(
<>
{
items
.
map
((
item
,
index
)
=>
<
Item
key
=
{
index
}
index
=
{
index
}
text
=
{
item
.
text
}
done
=
{
item
.
done
}
/>
,
)}
<
div
className
=
{
styles
.
draft
}
>
<
input
type
=
{
'
text
'
}
className
=
{
styles
.
wide
}
value
=
{
draft
}
onChange
=
{
onChange
}
/
>
<
button
onClick
=
{
onClick
}
>+<
/button
>
<
/div
>
<
/
>
);
}
}
This diff is collapsed.
Click to expand it.
to-do-list/src/features/toDo/toDoSlice.js
+
35
−
2
View file @
0c2ecf9e
...
@@ -3,11 +3,44 @@ import { createSlice } from '@reduxjs/toolkit';
...
@@ -3,11 +3,44 @@ import { createSlice } from '@reduxjs/toolkit';
const
toDoSlice
=
createSlice
({
const
toDoSlice
=
createSlice
({
name
:
'
toDo
'
,
name
:
'
toDo
'
,
initialState
:
{
initialState
:
{
draft
:
''
,
items
:
[],
},
},
reducers
:
{
reducers
:
{
setDraft
:
(
toDo
,
action
)
=>
{
const
{
draft
,
}
=
action
.
payload
;
toDo
.
draft
=
draft
;
},
addItem
:
(
toDo
)
=>
{
toDo
.
items
.
push
({
text
:
toDo
.
draft
,
done
:
false
,
});
toDo
.
draft
=
''
;
},
setDone
:
(
toDo
,
action
)
=>
{
const
{
index
,
done
,
}
=
action
.
payload
;
toDo
.
items
[
index
].
done
=
done
;
},
},
},
});
});
export
default
toDoSlice
;
export
default
toDoSlice
;
// export const {
export
const
{
// } = toDoSlice.actions;
setDraft
,
addItem
,
setDone
,
}
=
toDoSlice
.
actions
;
export
function
selectDraft
(
state
)
{
return
state
.
toDo
.
draft
;
}
export
function
selectItems
(
state
)
{
return
state
.
toDo
.
items
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment