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

ENG-1140: new-trashed-rewardables-flow #1177

Merged
merged 4 commits into from
Apr 12, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,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
Expand Down
12 changes: 11 additions & 1 deletion api/src/services/ik/rewardables/rewardables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export const rewardableBySlug: QueryResolvers['rewardableBySlug'] = ({
slug,
type,
},
trashedAt: {
equals: null,
},
},
})
}
Expand Down Expand Up @@ -57,6 +60,7 @@ export const rewardablesBySortType: QueryResolvers['rewardablesBySortType'] = ({
where: {
sortType,
listPublicly: true,
trashedAt: { equals: null },
},
})
}
Expand All @@ -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 },
})
Expand Down
75 changes: 54 additions & 21 deletions web/src/components/ProfileCell/ProfileCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
UserRewardablesQuery,
} from 'types/graphql'

import { routes } from '@redwoodjs/router'
import {
useQuery,
CellSuccessProps,
Expand Down Expand Up @@ -79,6 +80,7 @@ const USER_REWARDABLES_QUERY = gql`
query UserRewardablesQuery($userId: String!) {
userRewardables(userId: $userId) {
id
trashedAt
name
slug
nfts {
Expand Down Expand Up @@ -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 (
<div>
<div className="mt-12 flex flex-col gap-6 lg:mt-0 lg:flex-row">
Expand Down Expand Up @@ -312,31 +321,55 @@ export const Success = ({
</div>
</div>

<div className="mt-6 flex flex-col gap-6">
<div className="overflow-hidden rounded-lg bg-black/30 lg:basis-2/5">
<div className="bg-black/30 py-8 px-4 sm:px-8">
<p className="">Your Puzzles & Packs</p>
</div>
{(!!liveRewardables?.length || !!trashedRewardables?.length) && (
<div className="flex flex-col gap-6">
<div className="overflow-hidden rounded-lg bg-black/30 lg:basis-2/5">
<div className="bg-black/30 py-8 px-4 sm:px-8">
<p className="">Your Puzzles & Packs</p>
</div>

<div className="flex flex-col gap-4 py-8 px-4 text-sm sm:px-8">
<div className="grid gap-4 py-8 px-4 text-sm sm:px-8 md:grid-cols-2">
{data?.userRewardables.map((rewardable) => (
<Thumbnail
id={rewardable.id} // keep typescript happy
key={rewardable.id}
name={rewardable.name}
href={rewardableLandingRoute({
type: rewardable.type,
slug: rewardable.slug,
})}
isGrid={false} // always false for this display
cloudinaryId={rewardable.nfts?.[0]?.cloudinaryId}
/>
))}
<div className="flex flex-col gap-4 py-8 px-4 text-sm sm:px-8">
{!!liveRewardables?.length && (
<div className="grid gap-4 py-8 px-4 text-sm sm:px-8 md:grid-cols-2">
{liveRewardables?.map((rewardable) => (
<Thumbnail
id={rewardable.id} // keep typescript happy
key={rewardable.id}
name={rewardable.name}
href={rewardableLandingRoute({
type: rewardable.type,
slug: rewardable.slug,
})}
isGrid={false} // always false for this display
cloudinaryId={rewardable.nfts?.[0]?.cloudinaryId}
/>
))}
</div>
)}

{!!trashedRewardables?.length && (
<>
<p className="text-stone-300">Puzzles and packs in trash</p>
<div className="grid gap-4 py-8 px-4 text-sm sm:px-8 md:grid-cols-2">
{trashedRewardables?.map((rewardable) => (
<Thumbnail
id={rewardable.id} // keep typescript happy
key={rewardable.id}
name={rewardable.name}
href={routes.editFormArchetype({
slug: rewardable.slug,
})}
isGrid={false} // always false for this display
cloudinaryId={rewardable.nfts?.[0]?.cloudinaryId}
/>
))}
</div>
</>
)}
</div>
</div>
</div>
</div>
)}
</div>
)
}