@@ -2,12 +2,13 @@ import React, { useState } from "react";
2
2
import { makeStyles } from "@material-ui/core/styles" ;
3
3
import Container from "@material-ui/core/Container" ;
4
4
import Typography from "@material-ui/core/Typography" ;
5
- import TextField from "@material-ui/core/TextField" ;
6
5
import Button from "@material-ui/core/Button" ;
7
6
import List from "@material-ui/core/List" ;
8
7
import ListItem from "@material-ui/core/ListItem" ;
9
8
import ListItemText from "@material-ui/core/ListItemText" ;
10
9
import Chip from "@material-ui/core/Chip" ;
10
+ import NoteInput from "./NoteInput" ;
11
+ import TagsInput from "./TagsInput" ;
11
12
import moment from "moment" ;
12
13
import { v4 as uuidv4 } from "uuid" ;
13
14
@@ -21,33 +22,29 @@ const useStyles = makeStyles((theme) => ({
21
22
form : {
22
23
margin : theme . spacing ( 5 , 0 , 3 , 0 ) ,
23
24
} ,
24
- input : {
25
- marginBottom : theme . spacing ( 2 ) ,
26
- } ,
27
25
tag : {
28
26
margin : theme . spacing ( 0 , 0 , 0 , 0.5 ) ,
29
27
} ,
30
28
} ) ) ;
31
29
32
30
export default function App ( ) {
33
31
const classes = useStyles ( ) ;
34
-
35
- const dummyData = [
32
+ const dummyNotes = [
36
33
{
37
34
id : uuidv4 ( ) ,
38
- timestamp : moment ( ) . add ( 25 , "minutes" ) ,
35
+ timestamp : moment ( ) . subtract ( 25 , "minutes" ) ,
39
36
text : "Get groceries" ,
40
37
tags : [ "todo" ] ,
41
38
} ,
42
39
{
43
40
id : uuidv4 ( ) ,
44
- timestamp : moment ( ) . add ( 10 , "minutes" ) ,
41
+ timestamp : moment ( ) . subtract ( 10 , "minutes" ) ,
45
42
text : "Go to the gym later" ,
46
43
tags : [ "todo" , "fitness" , "2020 goals" ] ,
47
44
} ,
48
45
{
49
46
id : uuidv4 ( ) ,
50
- timestamp : moment ( ) . add ( 4 , "minutes" ) ,
47
+ timestamp : moment ( ) . subtract ( 4 , "minutes" ) ,
51
48
text : "Mitch is the trainer from Colorado" ,
52
49
tags : [ "people" ] ,
53
50
} ,
@@ -58,9 +55,20 @@ export default function App() {
58
55
tags : [ "work" , "reminder" ] ,
59
56
} ,
60
57
] ;
61
- const [ notes , setNotes ] = useState ( dummyData ) ;
58
+ const dummyTags = [
59
+ "todo" ,
60
+ "fitness" ,
61
+ "2020 goals" ,
62
+ "people" ,
63
+ "work" ,
64
+ "reminder" ,
65
+ ] ;
66
+ const [ notes , setNotes ] = useState ( dummyNotes ) ;
67
+ const [ tags , setTags ] = useState ( dummyTags ) ;
62
68
// const [notes, setNotes] = useState([]);
63
- const [ input , setInput ] = useState ( "" ) ;
69
+ // const [tags, setTags] = useState([]);
70
+ const [ noteInputValue , setNoteInputValue ] = useState ( "" ) ;
71
+ const [ tagsInputValue , setTagsInputValue ] = useState ( [ ] ) ;
64
72
65
73
const addNote = ( text , tags ) => {
66
74
setNotes ( [ { id : uuidv4 ( ) , timestamp : moment ( ) , text, tags } , ...notes ] ) ;
@@ -75,13 +83,17 @@ export default function App() {
75
83
76
84
const handleSaveNote = ( e ) => {
77
85
e . preventDefault ( ) ;
78
- setInput ( "" ) ;
79
- // TODO: account for tags
80
- addNote ( input , [ ] ) ;
86
+ setNoteInputValue ( "" ) ;
87
+ setTagsInputValue ( [ ] ) ;
88
+ addNote ( noteInputValue , tagsInputValue ) ;
81
89
} ;
82
90
83
91
const handleChangeNote = ( e ) => {
84
- setInput ( e . target . value ) ;
92
+ setNoteInputValue ( e . target . value ) ;
93
+ } ;
94
+
95
+ const handleChangeTags = ( e , newValue ) => {
96
+ setTagsInputValue ( newValue ) ;
85
97
} ;
86
98
87
99
return (
@@ -95,18 +107,17 @@ export default function App() {
95
107
SimpleNote
96
108
</ Typography >
97
109
< form className = { classes . form } onSubmit = { handleSaveNote } >
98
- < TextField
99
- className = { classes . input }
100
- value = { input }
101
- onChange = { handleChangeNote }
102
- fullWidth
103
- placeholder = "Write something here..."
110
+ < NoteInput value = { noteInputValue } onChange = { handleChangeNote } />
111
+ < TagsInput
112
+ value = { tagsInputValue }
113
+ onChange = { handleChangeTags }
114
+ options = { tags }
104
115
/>
105
116
< Button
106
117
type = "submit"
107
118
variant = "contained"
108
119
color = "primary"
109
- disabled = { ! input }
120
+ disabled = { ! noteInputValue }
110
121
>
111
122
Save
112
123
</ Button >
0 commit comments