Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitafe4dd0

Browse files
formatted the code
1 parenta39bde8 commitafe4dd0

File tree

4 files changed

+47
-42
lines changed

4 files changed

+47
-42
lines changed

‎src/App.tsx‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,22 @@ import { FaSun, FaMoon } from 'react-icons/fa';
66
import{useEffect,useReducer,useState}from'react';
77
import{StateContext,StateType}from'./context/state/state';
88
import{Notes}from'./components/note/data';
9-
import{ADD_NOTE,DELETE_NOTE,INIT_NOTES,SET_EDIT_MODE,SET_NOTE_FOR_EDIT,UPDATE_NOTE}from'./actions';
9+
import{
10+
ADD_NOTE,
11+
DELETE_NOTE,
12+
INIT_NOTES,
13+
SET_EDIT_MODE,
14+
SET_NOTE_FOR_EDIT,
15+
UPDATE_NOTE,
16+
}from'./actions';
1017
import{getNotes}from'./services/notes-service';
1118

1219
functionApp(){
1320
const[theme,setTheme]=useState('light');
1421
const[checked,setChecked]=useState(false);
1522

1623
const[state,dispatch]=useReducer(
17-
(state:StateType,action:{type:string;payload:any})=>{
24+
(state:StateType,action:{type:string;payload:any})=>{
1825
switch(action.type){
1926
caseINIT_NOTES:
2027
return{ ...state,notes:action.payload};
@@ -54,13 +61,13 @@ function App() {
5461
}
5562
};
5663

57-
useEffect(()=>{
58-
asyncfunctioninitializeNotes(){
64+
useEffect(()=>{
65+
asyncfunctioninitializeNotes(){
5966
constnotes=awaitgetNotes();
60-
dispatch({type:INIT_NOTES,payload:notes})
67+
dispatch({type:INIT_NOTES,payload:notes});
6168
}
62-
initializeNotes()
63-
},[])
69+
initializeNotes();
70+
},[]);
6471

6572
return(
6673
<StateContext.Providervalue={{ state, dispatch}}>

‎src/components/note/note.tsx‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@ type NoteProps = {
1313
id:string;
1414
text:string;
1515
priority?:Priority;
16-
note:NoteType
16+
note:NoteType;
1717
};
1818

1919
functionNote(props:NoteProps){
2020
consttheme=useContext(ThemeContext);
21-
const{dispatch}=useContext(StateContext);
21+
const{dispatch}=useContext(StateContext);
2222

23-
consteditNote=(note:NoteType)=>{
24-
dispatch({type:SET_EDIT_MODE,payload:true});
25-
dispatch({type:SET_NOTE_FOR_EDIT,payload:note});
23+
consteditNote=(note:NoteType)=>{
24+
dispatch({type:SET_EDIT_MODE,payload:true});
25+
dispatch({type:SET_NOTE_FOR_EDIT,payload:note});
2626
};
2727

28-
consthandleDelete=async()=>{
28+
consthandleDelete=async()=>{
2929
console.log(awaitdeleteNote(props.id));
3030
dispatch({type:DELETE_NOTE,payload:props.id});
31-
}
31+
};
3232

3333
return(
3434
<Card
@@ -44,9 +44,7 @@ function Note(props: NoteProps) {
4444
<div>{props.text}</div>
4545
<divclassName="right-corner">
4646
<FaEditonClick={()=>editNote(props.note)}></FaEdit>
47-
<FaTrash
48-
onClick={handleDelete}
49-
></FaTrash>
47+
<FaTrashonClick={handleDelete}></FaTrash>
5048
</div>
5149
</>
5250
</Card>

‎src/pages/home/home.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { StateContext } from '../../context/state/state';
77

88
functionHome(){
99
consttheme=useContext(ThemeContext);
10-
const{state}=useContext(StateContext);
10+
const{state}=useContext(StateContext);
1111

1212
return(
1313
<divclassName={`home${theme}`}>

‎src/services/notes-service.tsx‎

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
import{NoteType}from"../components/note/note-type";
1+
import{NoteType}from'../components/note/note-type';
22

3-
exportasyncfunctiongetNotes(){
4-
constresponse=awaitfetch('/notes');
5-
returnawaitresponse.json();
3+
exportasyncfunctiongetNotes(){
4+
constresponse=awaitfetch('/notes');
5+
returnawaitresponse.json();
66
}
7-
exportasyncfunctionaddNote(note:NoteType){
8-
constresponse=awaitfetch('/notes',{
9-
method:'post',
10-
headers:{"Content-Type":"application/json"},
11-
body:JSON.stringify(note)
12-
});
13-
returnawaitresponse.json();
7+
exportasyncfunctionaddNote(note:NoteType){
8+
constresponse=awaitfetch('/notes',{
9+
method:'post',
10+
headers:{'Content-Type':'application/json'},
11+
body:JSON.stringify(note),
12+
});
13+
returnawaitresponse.json();
1414
}
15-
exportasyncfunctiondeleteNote(id:string){
16-
constresponse=awaitfetch(`/notes/${id}`,{
17-
method:'delete',
18-
});
19-
returnawaitresponse.json();
15+
exportasyncfunctiondeleteNote(id:string){
16+
constresponse=awaitfetch(`/notes/${id}`,{
17+
method:'delete',
18+
});
19+
returnawaitresponse.json();
20+
}
21+
exportasyncfunctionupdateNote(id:string,note:NoteType){
22+
constresponse=awaitfetch(`/notes/${id}`,{
23+
method:'put',
24+
headers:{'Content-Type':'application/json'},
25+
body:JSON.stringify(note),
26+
});
27+
returnawaitresponse.json();
2028
}
21-
exportasyncfunctionupdateNote(id:string,note:NoteType){
22-
constresponse=awaitfetch(`/notes/${id}`,{
23-
method:'put',
24-
headers:{"Content-Type":"application/json"},
25-
body:JSON.stringify(note)
26-
});
27-
returnawaitresponse.json();
28-
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp