From 50d06ad5efa4ab7b2bc774dd5f7fcce39140bce1 Mon Sep 17 00:00:00 2001 From: Tawnee Date: Tue, 26 Mar 2024 19:24:47 -0600 Subject: [PATCH 1/2] filter trashed puzzles in services --- .../ik/rewardablePuzzle/rewardablePuzzleService.ts | 6 +++++- api/src/services/ik/rewardables/rewardables.ts | 12 +++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/api/src/services/ik/rewardablePuzzle/rewardablePuzzleService.ts b/api/src/services/ik/rewardablePuzzle/rewardablePuzzleService.ts index ed5e99cc1..d1861509b 100644 --- a/api/src/services/ik/rewardablePuzzle/rewardablePuzzleService.ts +++ b/api/src/services/ik/rewardablePuzzle/rewardablePuzzleService.ts @@ -47,9 +47,13 @@ export const editRewardablePuzzle: MutationResolvers['editRewardablePuzzle'] = const prevRewardable = await db.rewardable.findUnique({ where: { id: rewardableId }, - select: { name: true, slug: true }, + select: { name: true, slug: true, trashedAt: true }, }) + if (prevRewardable?.trashedAt) { + throw new Error("Cannot edit a puzzle that's in the trash") + } + const steps = formatCreateSteps(input.puzzle.steps) const slug = prevRewardable?.name === input.name diff --git a/api/src/services/ik/rewardables/rewardables.ts b/api/src/services/ik/rewardables/rewardables.ts index 350cba247..a732de915 100644 --- a/api/src/services/ik/rewardables/rewardables.ts +++ b/api/src/services/ik/rewardables/rewardables.ts @@ -20,6 +20,9 @@ export const rewardableBySlug: QueryResolvers['rewardableBySlug'] = ({ slug, type, }, + trashedAt: { + equals: null, + }, }, }) } @@ -57,6 +60,7 @@ export const rewardablesBySortType: QueryResolvers['rewardablesBySortType'] = ({ where: { sortType, listPublicly: true, + trashedAt: { equals: null }, }, }) } @@ -73,7 +77,13 @@ export const rewardablesCollection: QueryResolvers['rewardablesCollection'] = ? count : smallestPaginationCount - const typesFilter = types.map((type) => ({ type, listPublicly: true })) + const typesFilter = types.map((type) => ({ + type, + listPublicly: true, + trashedAt: { + equals: null, + }, + })) const totalCount = await db.rewardable.count({ where: { OR: typesFilter }, }) From 468e57cb082f8f59b83b616699834dd48022ea9a Mon Sep 17 00:00:00 2001 From: Tawnee Date: Tue, 26 Mar 2024 19:25:04 -0600 Subject: [PATCH 2/2] show list of trashed puzzles that link to edit page --- .../components/ProfileCell/ProfileCell.tsx | 75 +++++++++++++------ 1 file changed, 54 insertions(+), 21 deletions(-) diff --git a/web/src/components/ProfileCell/ProfileCell.tsx b/web/src/components/ProfileCell/ProfileCell.tsx index 22773efa6..32e1e380f 100644 --- a/web/src/components/ProfileCell/ProfileCell.tsx +++ b/web/src/components/ProfileCell/ProfileCell.tsx @@ -12,6 +12,7 @@ import type { UserRewardablesQuery, } from 'types/graphql' +import { routes } from '@redwoodjs/router' import { useQuery, CellSuccessProps, @@ -79,6 +80,7 @@ const USER_REWARDABLES_QUERY = gql` query UserRewardablesQuery($userId: String!) { userRewardables(userId: $userId) { id + trashedAt name slug nfts { @@ -120,6 +122,13 @@ export const Success = ({ variables: { userId: user?.id }, }) + const liveRewardables = data?.userRewardables.filter( + (rewardable) => !rewardable.trashedAt + ) + const trashedRewardables = data?.userRewardables.filter( + (rewardable) => rewardable.trashedAt + ) + return (
@@ -312,31 +321,55 @@ export const Success = ({
-
-
-
-

Your Puzzles & Packs

-
+ {(!!liveRewardables?.length || !!trashedRewardables?.length) && ( +
+
+
+

Your Puzzles & Packs

+
-
-
- {data?.userRewardables.map((rewardable) => ( - - ))} +
+ {!!liveRewardables?.length && ( +
+ {liveRewardables?.map((rewardable) => ( + + ))} +
+ )} + + {!!trashedRewardables?.length && ( + <> +

Puzzles and packs in trash

+
+ {trashedRewardables?.map((rewardable) => ( + + ))} +
+ + )}
-
+ )}
) }