Skip to content

Commit

Permalink
Add menu option to unlike sandbox in liked sandboxes page (#5579)
Browse files Browse the repository at this point in the history
  • Loading branch information
SaraVieira committed Mar 11, 2021
1 parent 2b45591 commit 58ab91b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/app/src/app/overmind/namespaces/dashboard/actions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { compareDesc, parseISO } from 'date-fns';
import { json } from 'overmind';
import { Context } from 'app/overmind';
import { withLoadApp } from 'app/overmind/factories';
import downloadZip from 'app/overmind/effects/zip/create-zip';
Expand Down Expand Up @@ -1834,3 +1835,20 @@ export const getLikedSandboxes = async ({ state, effects }: Context) => {
);
}
};

export const unlikeSandbox = async (
{ state, effects }: Context,
id: string
) => {
const all = state.dashboard.sandboxes[sandboxesTypes.LIKED];
if (!all) return;
try {
state.dashboard.sandboxes[sandboxesTypes.LIKED] = all.filter(
sandbox => sandbox.id !== id
);
await effects.api.unlikeSandbox(id);
} catch (e) {
state.dashboard.sandboxes[sandboxesTypes.LIKED] = json(all);
effects.notificationToast.error('There was a problem removing your like');
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,15 @@ export const SandboxMenu: React.FC<SandboxMenuProps> = ({
)}
</>
)}
{!hasAccess && !isTemplate && location.pathname.includes('liked') && (
<MenuItem
onSelect={() => {
actions.dashboard.unlikeSandbox(sandbox.id);
}}
>
Unlike Sandbox
</MenuItem>
)}
</Menu.ContextMenu>
);
};
Expand Down

0 comments on commit 58ab91b

Please sign in to comment.