#24-directory-structure #26

Merged
djmil merged 15 commits from #24-directory-structure into main 2023-11-10 09:37:23 +01:00
3 changed files with 16 additions and 19 deletions
Showing only changes of commit 9ec2059c4a - Show all commits

View File

@ -13,7 +13,7 @@ import useLeaderboardApi from './api/leaderboard';
import useUserApi from './api/user';
function App() {
const pollingFlux = useReducer(Polling.reducer, Polling.restoreState);
const pollingFlux = useReducer(Polling.reducer, Polling.initialState);
const userFlux = useReducer(User.reducer, User.initialState);
const leaderboardApi = useLeaderboardApi(pollingFlux);

View File

@ -12,7 +12,7 @@ export default function useLeaderboardApi([polling, dispatchPolling]) {
const [leaderboard, isFetching] = usePolling(uri, mode);
if (polling.leaderboard !== isFetching) {
dispatchPolling({ type: 'setLeaderboard', value: isFetching });
dispatchPolling({ type: 'next', leaderboard: isFetching });
}
return leaderboard;

View File

@ -1,4 +1,5 @@
import { useLocalStorage } from '../util/PersistentStorage'
import { nextState } from '../util/StateHelper';
const Persistent = (() => {
const [getEnabled, setEnabled] = useLocalStorage('polling.enabled', true);
@ -9,36 +10,32 @@ const Persistent = (() => {
}
})(); // <<--- Execute
const restoreState = {
enabled: Persistent.getEnabled() === 'true',
export const pollingInitialState = {
enabled: Persistent.getEnabled() === 'true',
games: false,
leaderboard: false
games: false,
leaderboard: false
};
function reducer(state, action) {
export function pollingReducer(curntState, action) {
switch (action.type) {
case 'toggleOnOff': return {
...state,
enabled: Persistent.setEnabled(!state.enabled)
...curntState,
enabled: Persistent.setEnabled(!curntState.enabled)
};
case 'setGames': return {
...state,
games: action.value
};
case 'setLeaderboard': return {
...state,
leaderboard: action.value
};
case 'next':
return nextState(curntState, action);
default:
throw Error('Unknown action.type:' + action.type);
}
}
const Polling = { reducer, restoreState }
const Polling = {
reducer: pollingReducer,
initialState: pollingInitialState
};
export default Polling