Skip to content

Commit

Permalink
Chore: append unique paths to collection (#2560)
Browse files Browse the repository at this point in the history
  • Loading branch information
thewahome authored May 4, 2023
1 parent b0dda64 commit db86b90
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/app/middleware/localStorageMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const localStorageMiddleware = (store: any) => (next: any) => async (action: App
case RESOURCEPATHS_ADD_SUCCESS: {
const collections = await collectionsCache.read();
const item = collections.find(k => k.isDefault)!;
item.paths = action.response;
item.paths = Array.from(new Set([...item.paths, ...action.response]));
await collectionsCache.update(item.id, item);
break;
}
Expand Down
10 changes: 3 additions & 7 deletions src/app/services/reducers/collections-reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@ export function collections(state: Collection[] = initialState, action: AppActio
case RESOURCEPATHS_ADD_SUCCESS:
const index = state.findIndex(k => k.isDefault);
if (index > -1) {
const paths: IResourceLink[] = [...state[index].paths];
action.response.forEach((element: any) => {
const exists = !!paths.find(k => k.key === element.key);
if (!exists) {
paths.push(element);
}
});
const paths: IResourceLink[] = Array.from(
new Set([...state[index].paths, ...action.response])
);
const context = [...state];
context[index].paths = paths;
return context;
Expand Down

0 comments on commit db86b90

Please sign in to comment.