-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(persistInStorage): add redux-persist and retrieve from localStorage
- Loading branch information
Showing
11 changed files
with
87 additions
and
115 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Box, CircularProgress, Typography } from '@mui/material'; | ||
|
||
function FullScreenLoading() { | ||
return ( | ||
<Box | ||
sx={{ | ||
display: 'flex', | ||
alignItems: 'center', | ||
flexDirection: 'column', | ||
height: '100vh', | ||
justifyContent: 'center' | ||
}}> | ||
<Typography variant="h4" align="center"> | ||
Chargement des données... | ||
</Typography> | ||
<CircularProgress size={50} sx={{ mt: 4 }} /> | ||
</Box> | ||
); | ||
} | ||
|
||
export default FullScreenLoading; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,9 @@ | ||
import { configureStore } from '@reduxjs/toolkit'; | ||
import counterReducer from './counter/counterSlice'; | ||
import trackersReducer from './trackers/trackersSlice'; | ||
import { configureStore, EnhancedStore } from '@reduxjs/toolkit'; | ||
import rootReducer from './rootReducer'; | ||
|
||
export function createTestStore() { | ||
export function createTestStore(): EnhancedStore { | ||
const store = configureStore({ | ||
reducer: { | ||
counter: counterReducer, | ||
trackers: trackersReducer | ||
} | ||
reducer: rootReducer | ||
}); | ||
return store; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { combineReducers } from '@reduxjs/toolkit'; | ||
import counterReducer from './counter/counterSlice'; | ||
import trackersReducer from './trackers/trackersSlice'; | ||
|
||
const rootReducer = combineReducers({ | ||
counter: counterReducer, | ||
trackers: trackersReducer | ||
}); | ||
|
||
export default rootReducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,2 @@ | ||
import { subDays } from 'date-fns'; | ||
import Tracker from '../../models/Tracker'; | ||
import TrackerStatus from '../../models/TrackerStatus'; | ||
import { v4 as uuidv4 } from 'uuid'; | ||
|
||
class TrackersActions { | ||
// A mock function to mimic making an async request for data | ||
fetchAll() { | ||
return new Promise<{ data: Tracker[] }>((resolve) => | ||
setTimeout( | ||
() => | ||
resolve({ | ||
data: [ | ||
{ | ||
id: uuidv4(), | ||
beginDate: new Date().toString(), | ||
name: "Boire plus d'eau", | ||
defaultQuantity: 1, | ||
status: TrackerStatus.active, | ||
unit: "litre d'eau", | ||
entries: [] | ||
}, | ||
{ | ||
id: uuidv4(), | ||
beginDate: new Date().toString(), | ||
defaultQuantity: 1, | ||
name: 'Faire du yoga', | ||
status: TrackerStatus.active, | ||
unit: 'séance', | ||
entries: [] | ||
}, | ||
{ | ||
id: uuidv4(), | ||
beginDate: subDays(new Date(), 7).toString(), | ||
defaultQuantity: 15, | ||
duration: 45, | ||
name: 'Faire des pompes', | ||
status: TrackerStatus.active, | ||
unit: 'pompes', | ||
entries: [] | ||
} | ||
] | ||
}), | ||
900 | ||
) | ||
); | ||
} | ||
} | ||
class TrackersActions {} | ||
export default new TrackersActions(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,12 @@ | ||
import SliceStatus from '../../models/SliceStatus'; | ||
import trackersReducer, { TrackersState, fetchAllTrackers } from './trackersSlice'; | ||
import trackersReducer from './trackersSlice'; | ||
|
||
describe('counter reducer', () => { | ||
const initialState: TrackersState = { | ||
error: {}, | ||
status: SliceStatus.idle, | ||
trackers: undefined | ||
}; | ||
it('should handle initial state', () => { | ||
expect(trackersReducer(undefined, { type: 'unknown' })).toEqual({ | ||
error: {}, | ||
status: SliceStatus.idle, | ||
trackers: undefined | ||
}); | ||
}); | ||
|
||
it('should handle fetch all trackers pending', () => { | ||
const actual = trackersReducer(initialState, fetchAllTrackers.pending); | ||
expect(actual.status).toEqual(SliceStatus.loading); | ||
expect(actual.error).toEqual({}); | ||
}); | ||
|
||
it('should handle fetch all trackers error', () => { | ||
const actual = trackersReducer(initialState, fetchAllTrackers.rejected); | ||
expect(actual.status).toEqual(SliceStatus.failed); | ||
expect(actual.error).not.toEqual({}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters