Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: append unique paths to collection #2560

Merged
merged 1 commit into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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