-
Notifications
You must be signed in to change notification settings - Fork 0
feat(deck): add deck collaboration (issue #27) #82
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
Open
jcserv
wants to merge
5
commits into
main
Choose a base branch
from
feat-deck-collaboration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a865365
feat(deck): add deck collaboration (issue #27)
jcserv 776d3b0
test(deck): close coverage gaps left by collaboration feature
jcserv 0c054d8
fix(deck): close TOCTOU race in proposal approve/reject
jcserv 36f1f8c
fix(deck): address remaining collaboration review findings
jcserv 8bd8e12
fix(deck): fold compare and collaborate into more menu
jcserv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| import { Suspense } from "react"; | ||
| import { notFound } from "next/navigation"; | ||
| import { ChevronLeft, PencilLine } from "lucide-react"; | ||
| import Link from "@/app/_components/link"; | ||
| import { Button } from "@/components/ui/button"; | ||
| import { prisma } from "@/lib/db"; | ||
| import { getSession } from "@/lib/auth/session"; | ||
| import { canCollaborateOnDeck } from "@/lib/auth/deck-access"; | ||
| import { listDeckProposals } from "@/app/_actions/deck/collaboration"; | ||
| import { DeckProposalReviewList } from "@/app/_components/deck/deck-proposal-review-list"; | ||
|
|
||
| interface DeckCollaboratePageProps { | ||
| params: Promise<{ id: string }>; | ||
| } | ||
|
|
||
| async function DeckCollaborateContent({ id }: { id: string }) { | ||
| const [deck, session] = await Promise.all([ | ||
| prisma.deck.findUnique({ | ||
| where: { id }, | ||
| select: { | ||
| id: true, | ||
| name: true, | ||
| userId: true, | ||
| collaborationEnabled: true, | ||
| }, | ||
| }), | ||
| getSession(), | ||
| ]); | ||
| if (!deck) notFound(); | ||
|
|
||
| const isOwner = session?.userId === deck.userId; | ||
| const isCollaborator = | ||
| !isOwner && (await canCollaborateOnDeck(deck, session?.userId)); | ||
| if (!isOwner && !isCollaborator) notFound(); | ||
|
|
||
| return ( | ||
| <div className="flex flex-col gap-6"> | ||
| <div className="flex flex-col gap-2"> | ||
| <Link | ||
| href={`/deck/${deck.id}`} | ||
| className="inline-flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground w-fit" | ||
| > | ||
| <ChevronLeft className="size-4" aria-hidden /> | ||
| Back to deck | ||
| </Link> | ||
| <h1 className="font-heading text-2xl md:text-3xl font-semibold leading-tight tracking-tight"> | ||
| {deck.name} · Collaborate | ||
| </h1> | ||
| <p className="text-sm text-muted-foreground"> | ||
| {isOwner | ||
| ? "Review proposed changes from people you follow. Approving applies the whole proposal at once." | ||
| : "Propose card changes for the owner to review. They can approve or reject the whole proposal."} | ||
| </p> | ||
| </div> | ||
|
|
||
| {isOwner ? ( | ||
| <DeckOwnerReview deckId={deck.id} /> | ||
| ) : ( | ||
| <div className="flex flex-col items-start gap-4 rounded-md border border-dashed p-6"> | ||
| <p className="text-sm text-muted-foreground max-w-prose"> | ||
| Build a set of add/remove/quantity changes, then submit it for the | ||
| owner to approve or reject. | ||
| </p> | ||
| <Button render={<Link href={`/deck/${deck.id}/propose`} />}> | ||
| <PencilLine className="size-3.5" aria-hidden /> | ||
| Propose changes | ||
| </Button> | ||
| </div> | ||
| )} | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| async function DeckOwnerReview({ deckId }: { deckId: string }) { | ||
| const proposals = await listDeckProposals(deckId); | ||
| return <DeckProposalReviewList deckId={deckId} proposals={proposals} />; | ||
| } | ||
|
|
||
| export default function DeckCollaboratePage({ | ||
| params, | ||
| }: DeckCollaboratePageProps) { | ||
| return ( | ||
| <div className="px-4 md:px-8 py-6 max-w-[1000px] mx-auto"> | ||
| <Suspense | ||
| fallback={ | ||
| <div className="flex flex-col gap-4"> | ||
| <div className="h-6 w-40 rounded-md bg-muted animate-pulse" /> | ||
| <div className="h-[120px] rounded-md bg-muted/30 animate-pulse" /> | ||
| </div> | ||
| } | ||
| > | ||
| <CollaborateLoader params={params} /> | ||
| </Suspense> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| async function CollaborateLoader({ | ||
| params, | ||
| }: { | ||
| params: Promise<{ id: string }>; | ||
| }) { | ||
| const { id } = await params; | ||
| return <DeckCollaborateContent id={id} />; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| import { Suspense } from "react"; | ||
| import { notFound } from "next/navigation"; | ||
| import { ChevronLeft } from "lucide-react"; | ||
| import Link from "@/app/_components/link"; | ||
| import { requireDeckCollaborator } from "@/lib/auth/deck-access"; | ||
| import { getDeckById } from "@/lib/deck/queries"; | ||
| import { DeckProposeDraft } from "@/app/_components/deck/deck-propose-draft"; | ||
|
|
||
| interface DeckProposePageProps { | ||
| params: Promise<{ id: string }>; | ||
| } | ||
|
|
||
| async function DeckProposeContent({ id }: { id: string }) { | ||
| await requireDeckCollaborator(id); | ||
| const deck = await getDeckById(id); | ||
| if (!deck) notFound(); | ||
|
|
||
| const mainboard = deck.cards | ||
| .filter((c) => c.zone === "MAINBOARD") | ||
| .map((c) => ({ | ||
| cardId: c.cardId, | ||
| cardName: c.card.name, | ||
| category: c.category, | ||
| quantity: c.quantity, | ||
| })); | ||
|
|
||
| return ( | ||
| <div className="flex flex-col gap-6"> | ||
| <div className="flex flex-col gap-2"> | ||
| <Link | ||
| href={`/deck/${id}/collaborate`} | ||
| className="inline-flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground w-fit" | ||
| > | ||
| <ChevronLeft className="size-4" aria-hidden /> | ||
| Back to collaborate | ||
| </Link> | ||
| <h1 className="font-heading text-2xl md:text-3xl font-semibold leading-tight tracking-tight"> | ||
| Propose changes to {deck.name} | ||
| </h1> | ||
| <p className="text-sm text-muted-foreground"> | ||
| Adjust mainboard quantities or add new cards, then submit for the | ||
| owner to review. | ||
| </p> | ||
| </div> | ||
|
|
||
| <DeckProposeDraft deckId={id} existingCards={mainboard} /> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| export default function DeckProposePage({ params }: DeckProposePageProps) { | ||
| return ( | ||
| <div className="px-4 md:px-8 py-6 max-w-[900px] mx-auto"> | ||
| <Suspense | ||
| fallback={ | ||
| <div className="flex flex-col gap-4"> | ||
| <div className="h-6 w-40 rounded-md bg-muted animate-pulse" /> | ||
| <div className="h-[240px] rounded-md bg-muted/30 animate-pulse" /> | ||
| </div> | ||
| } | ||
| > | ||
| <ProposeLoader params={params} /> | ||
| </Suspense> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| async function ProposeLoader({ | ||
| params, | ||
| }: { | ||
| params: Promise<{ id: string }>; | ||
| }) { | ||
| const { id } = await params; | ||
| return <DeckProposeContent id={id} />; | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.