Skip to content

Commit

Permalink
Task: use redux toolkit (#3186)
Browse files Browse the repository at this point in the history
  • Loading branch information
thewahome authored Aug 7, 2024
1 parent 676e113 commit b366636
Show file tree
Hide file tree
Showing 177 changed files with 2,867 additions and 4,867 deletions.
3 changes: 1 addition & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,7 @@ extends:
- job: Three
displayName: "Publish artifacts"
dependsOn: One
# Test deployment
# condition: and(succeeded(), or(eq(variables['isMaster'], 'true'), eq(variables['isDev'], 'true')))
condition: and(succeeded(), or(eq(variables['isMaster'], 'true'), eq(variables['isDev'], 'true')))
steps:
- task: NodeTool@0
inputs:
Expand Down
151 changes: 141 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"@microsoft/microsoft-graph-client": "3.0.7",
"@monaco-editor/react": "4.6.0",
"@ms-ofb/officebrowserfeedbacknpm": "file:packages/officebrowserfeedbacknpm-1.6.6.tgz",
"@reduxjs/toolkit": "2.2.5",
"adaptive-expressions": "4.22.2",
"adaptivecards": "3.0.2",
"adaptivecards-templating": "2.3.1",
Expand Down Expand Up @@ -52,8 +53,6 @@
"react-app-polyfill": "3.0.0",
"react-dom": "18.2.0",
"react-redux": "8.1.3",
"redux": "4.2.1",
"redux-thunk": "2.4.2",
"resolve": "1.22.8",
"sass": "1.72.0",
"sass-loader": "14.2.1",
Expand Down Expand Up @@ -96,6 +95,7 @@
"@types/isomorphic-fetch": "0.0.39",
"@types/jest": "29.5.12",
"@types/lodash.debounce": "4.0.9",
"@types/markdown-it": "^14.1.1",
"@types/react": "18.2.55",
"@types/react-dom": "18.2.19",
"@types/react-redux": "7.1.30",
Expand All @@ -115,6 +115,7 @@
"jest-fetch-mock": "3.0.3",
"jest-sonar-reporter": "2.0.0",
"jest-watch-typeahead": "2.2.2",
"markdown-it": "^14.1.0",
"node-notifier": "10.0.1",
"react-dev-utils": "12.0.1",
"redux-logger": "3.0.6",
Expand Down
33 changes: 12 additions & 21 deletions src/app/middleware/localStorageMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
import { Dispatch, Middleware, UnknownAction } from '@reduxjs/toolkit';
import { collectionsCache } from '../../modules/cache/collections.cache';
import { resourcesCache } from '../../modules/cache/resources.cache';
import { samplesCache } from '../../modules/cache/samples.cache';
import { AppAction } from '../../types/action';
import { ResourcePath } from '../../types/resources';
import { addResourcePaths } from '../services/actions/collections-action-creators';
import { Collection, ResourcePath } from '../../types/resources';
import { CURRENT_THEME } from '../services/graph-constants';
import { getUniquePaths } from '../services/reducers/collections-reducer.util';
import {
CHANGE_THEME_SUCCESS, COLLECTION_CREATE_SUCCESS, FETCH_RESOURCES_ERROR, FETCH_RESOURCES_SUCCESS,
CHANGE_THEME_SUCCESS, COLLECTION_CREATE_SUCCESS,
RESOURCEPATHS_ADD_SUCCESS, RESOURCEPATHS_DELETE_SUCCESS, SAMPLES_FETCH_SUCCESS
} from '../services/redux-constants';
import { saveToLocalStorage } from '../utils/local-storage';

const localStorageMiddleware = (store: any) => (next: any) => async (action: AppAction) => {
const localStorageMiddleware: Middleware<{}, any, Dispatch<UnknownAction>> = () => (next) => async (value) => {
const action = value as AppAction;
switch (action.type) {
case CHANGE_THEME_SUCCESS:
saveToLocalStorage(CURRENT_THEME,action.response);
saveToLocalStorage(CURRENT_THEME, action.payload);
break;

case SAMPLES_FETCH_SUCCESS:
samplesCache.saveSamples(action.response);
samplesCache.saveSamples(action.payload);
break;

case RESOURCEPATHS_ADD_SUCCESS: {
const collections = await collectionsCache.read();
const item = collections.find(k => k.isDefault)!;
item.paths = getUniquePaths(item.paths, action.response);
item.paths = getUniquePaths(item.paths, action.payload as ResourcePath[]);
await collectionsCache.update(item.id, item);
break;
}

case RESOURCEPATHS_DELETE_SUCCESS: {
const paths = action.response;
const paths = action.payload as ResourcePath[];
const collections = await collectionsCache.read();
const collection = collections.find(k => k.isDefault)!;
paths.forEach((path: ResourcePath) => {
Expand All @@ -45,24 +45,15 @@ const localStorageMiddleware = (store: any) => (next: any) => async (action: App
}

case COLLECTION_CREATE_SUCCESS: {
await collectionsCache.create(action.response);
break;
}

case FETCH_RESOURCES_SUCCESS:
case FETCH_RESOURCES_ERROR: {
resourcesCache.readCollection().then((data: ResourcePath[]) => {
if (data && data.length > 0) {
store.dispatch(addResourcePaths(data));
}
});
await collectionsCache.create(action.payload as Collection);
break;
}

default:
break;
}
return next(action);
};
}


export default localStorageMiddleware;
Loading

0 comments on commit b366636

Please sign in to comment.