1- import { Action , ActionType } from '../actions' ;
1+ import { PayloadAction , createSlice } from '@reduxjs/toolkit' ;
2+
23import { Notification } from '../types' ;
34
45interface State {
@@ -11,7 +12,7 @@ interface State {
1112 seenRustSurvey2022 : boolean ;
1213}
1314
14- const DEFAULT : State = {
15+ const initialState : State = {
1516 seenRustSurvey2018 : true ,
1617 seenRust2018IsDefault : true ,
1718 seenRustSurvey2020 : true ,
@@ -21,16 +22,22 @@ const DEFAULT: State = {
2122 seenRustSurvey2022 : false ,
2223} ;
2324
24- export default function notifications ( state = DEFAULT , action : Action ) : State {
25- switch ( action . type ) {
26- case ActionType . NotificationSeen : {
27- switch ( action . notification ) {
25+ const slice = createSlice ( {
26+ name : 'notifications' ,
27+ initialState,
28+ reducers : {
29+ notificationSeen : ( state , action : PayloadAction < Notification > ) => {
30+ switch ( action . payload ) {
2831 case Notification . RustSurvey2022 : {
29- return { ... state , seenRustSurvey2022 : true } ;
32+ state . seenRustSurvey2022 = true ;
3033 }
3134 }
32- }
33- default :
34- return state ;
35- }
36- }
35+ } ,
36+ } ,
37+ } ) ;
38+
39+ const { notificationSeen } = slice . actions ;
40+
41+ export const seenRustSurvey2022 = ( ) => notificationSeen ( Notification . RustSurvey2022 ) ;
42+
43+ export default slice . reducer ;
0 commit comments