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

Commit809feea

Browse files
committed
feat: saving fcm token to database on load + persisting into localstorage
1 parentf271343 commit809feea

File tree

14 files changed

+142
-15
lines changed

14 files changed

+142
-15
lines changed

‎README.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
##tools + patterns
44

55
- react
6+
- typescript
67
- react-redux
78
- State manager
89
- deox
@@ -18,6 +19,8 @@
1819
- local api
1920
- workbox
2021
- Google tool for service worker handling
22+
- formik
23+
- forms handling
2124

2225
##Features
2326

‎package-lock.json‎

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"reactstrap":"^8.0.0",
3333
"redux":"^4.0.1",
3434
"redux-devtools-extension":"^2.13.8",
35+
"redux-localstorage-simple":"^2.1.6",
3536
"redux-logger":"^3.0.6",
3637
"redux-thunk":"^2.3.0",
3738
"reselect":"^4.0.0",

‎server/db.json‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
{
2+
"notificationIds": [
3+
{
4+
"id":"fn-vVdfJXRo:APA91bFp-map0BqzjghJgKCCfSTSs6tEYQFvwzn5kZ6Z3j-R6spk9LCWD-7UMpQN6GPy928tGboJWsvSjUubYp0tmEwbwEytzh9ujA52547HjwCytV6rU7uKhPLFm5keCb5_M5CXfvQM"
5+
}
6+
],
27
"todos": [
38
{
49
"id":1,
510
"text":"task1",
611
"dueDate":"2019-05-02T13:00:00.000Z",
7-
"completed":true,
12+
"completed":false,
813
"length":1234,
914
"reminder":123,
1015
"createdAt":"2019-05-15T13:36:48.381Z"
@@ -126,4 +131,4 @@
126131
"id":15
127132
}
128133
]
129-
}
134+
}

‎src/actions/index.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Dispatch } from 'redux'
33
import{createAction}from'deox'
44

55
importaxiosfrom'../services/request'
6+
import{requestNotificationPermission}from'../services/push-notification'
67
import{TodoType}from'../models'
78

89
exportconstaddTodo=createAction(
@@ -50,29 +51,40 @@ export const toggleTodo = createAction(
5051
(resolve:Function)=>(id:number)=>resolve({ id})
5152
)
5253

54+
exportconstregisterNotificationId=createAction(
55+
'REGISTRATION_NOTIFICATION_ID',
56+
(resolve:Function)=>(id:string)=>resolve({ id})
57+
)
58+
59+
exportconstglobalError=createAction('GLOBAL_ERROR')
60+
5361
exportconstaddTodoRequest=(todo:Partial<TodoType>)=>{
5462
todo.completed=false
5563
todo.createdAt=newDate()
5664

5765
return(dispatch:Dispatch)=>
5866
axios.post('todos',todo)
5967
.then(({ data}:AxiosResponse<TodoType>)=>dispatch(addTodo(data)))
68+
.catch(()=>dispatch(globalError()))
6069
}
6170

6271
exportconsteditTodoRequest=(todo:TodoType)=>
6372
(dispatch:Dispatch)=>
6473
axios.put(`todos/${todo.id}`,todo)
6574
.then(({ data}:AxiosResponse<TodoType>)=>dispatch(editTodo(data)))
75+
.catch(()=>dispatch(globalError()))
6676

6777
exportconstfetchTodosRequest=()=>
6878
(dispatch:Dispatch)=>
6979
axios.get('todos')
7080
.then(({ data}:AxiosResponse<TodoType[]>)=>dispatch(fetchTodos(data)))
81+
.catch(()=>dispatch(globalError()))
7182

7283
exportconstremoveTodoRequest=(id:number)=>
7384
(dispatch:Dispatch)=>
7485
axios.delete(`todos/${id}`)
7586
.then(()=>dispatch(removeTodo(id)))
87+
.catch(()=>dispatch(globalError()))
7688

7789
exportconsttoggleTodoRequest=(todo:TodoType)=>{
7890
constdata={
@@ -82,4 +94,14 @@ export const toggleTodoRequest = (todo: TodoType) => {
8294
return(dispatch:Dispatch)=>
8395
axios.patch(`todos/${todo.id}`,data)
8496
.then(()=>dispatch(toggleTodo(todo.id)))
97+
.catch(()=>dispatch(globalError()))
8598
}
99+
100+
exportconstregisterNotificationIdRequest=()=>
101+
(dispatch:Dispatch)=>
102+
requestNotificationPermission()
103+
.then(id=>
104+
axios.post(`notificationIds`,{ id})
105+
.then(()=>dispatch(registerNotificationId(id)))
106+
)
107+
.catch(()=>dispatch(globalError()))
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
importReact,{Fragment,useEffect}from'react'
2+
3+
typePropsType={
4+
onLoadRegisterNotificationId:()=>{},
5+
notificationId:string
6+
}
7+
8+
constInitializeNotification=({ onLoadRegisterNotificationId, notificationId}:PropsType)=>{
9+
useEffect(()=>{
10+
if(!Boolean(notificationId)){
11+
onLoadRegisterNotificationId()
12+
}
13+
},[notificationId,onLoadRegisterNotificationId])
14+
15+
return(<Fragment/>)
16+
}
17+
18+
exportdefaultInitializeNotification
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name":"InitializeNotification",
3+
"main":"./InitializeNotification"
4+
}

‎src/components/templates/App/App.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ import { Container } from 'reactstrap'
33

44
importHeaderfrom'../../molecules/Header'
55
importFooterfrom'../../molecules/Footer'
6+
importRegisterNotificationIdfrom'../../../containers/RegisterNotificationId'
67
importSearchTodofrom'../../../containers/SearchTodo'
78
importVisibleTodoListfrom'../../../containers/VisibleTodoList'
89

910
constApp=()=>(
1011
<Container>
12+
<RegisterNotificationId/>
1113
<Header/>
1214
<SearchTodo/>
1315
<VisibleTodoList/>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import{bindActionCreators,Dispatch}from'redux'
2+
import{connect}from'react-redux'
3+
4+
import{registerNotificationIdRequest}from'../actions'
5+
importInitializeNotificationfrom'../components/atoms/InitializeNotification'
6+
7+
constmapStateToProps=(state:any)=>({
8+
notificationId:state.notification.id
9+
})
10+
11+
constmapDispatchToProps=(dispatch:Dispatch)=>
12+
bindActionCreators(
13+
{
14+
onLoadRegisterNotificationId:registerNotificationIdRequest
15+
},
16+
dispatch
17+
)
18+
19+
exportdefaultconnect(mapStateToProps,mapDispatchToProps)(InitializeNotification)

‎src/containers/SearchTodo.tsx‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import { bindActionCreators, Dispatch } from 'redux'
44
import{setKeywordSearchFilter}from'../actions'
55
importSearchTodofrom'../components/atoms/SearchTodo'
66

7-
constmapStateToProps=(state:any,ownProps:any)=>({
8-
active:ownProps.filter===state.visibilityFilter
9-
})
7+
constmapStateToProps=()=>({})
108

119
constmapDispatchToProps=(dispatch:Dispatch)=>
1210
bindActionCreators(

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp