-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[19] Feature: I can create a collection that will represent a physica…
…l collection (#31) * can create collection * displays cards on collection page * scripts + index updates * can create collections * fix lint errors add ButtonProps type void router replacement when creating collection add alt text to images when viewing collection * fixing routes using singular noun for singular operations using plural noun for plural operations
- Loading branch information
1 parent
94c9b12
commit e2acec0
Showing
12 changed files
with
201 additions
and
46 deletions.
There are no files selected for viewing
This file contains 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
2 changes: 2 additions & 0 deletions
2
prisma/migrations/20241122063426_add_cards_to_collection/migration.sql
This file contains 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,2 @@ | ||
-- AlterTable | ||
ALTER TABLE "Collection" ADD COLUMN "cards" TEXT[]; |
This file contains 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 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 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,26 @@ | ||
type ButtonProps = Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, 'className'> | ||
|
||
export default function Button({ children, ...props }: ButtonProps) { | ||
return ( | ||
<button | ||
className=" | ||
rounded-full | ||
dark:bg-purple-950 | ||
px-4 | ||
py-2 | ||
font-semibold | ||
no-underline | ||
transition | ||
dark:hover:bg-pink-800 | ||
dark:focus:bg-pink-800 | ||
dark:hover:drop-shadow-glow | ||
dark:focus:drop-shadow-glow | ||
" | ||
{...props} | ||
> | ||
{children} | ||
</button> | ||
|
||
) | ||
} | ||
|
This file contains 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 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 |
---|---|---|
@@ -1,12 +1,25 @@ | ||
import Image from 'next/image'; | ||
import { useRouter } from 'next/router'; | ||
import { api } from '~/utils/api'; | ||
|
||
export default function Page() { | ||
const router = useRouter() | ||
const collection = api.collection.byId.useQuery({ id: router.query.id as string }) | ||
const cards = api.card.findMany.useQuery({ cardIds: collection.data?.cards ?? [] }) | ||
|
||
return ( | ||
<div> | ||
<h1>My Page</h1> | ||
<h2>Slug: {router.query.id}</h2> | ||
</div> | ||
<div> | ||
<h1>{collection.data?.name}</h1> | ||
{cards.data?.map(card => { | ||
const images = card.image_uris as { small: string } | null; | ||
|
||
return ( | ||
<div key={card.id}> | ||
<p>{card.name}</p> | ||
<Image src={images?.small ?? ""} width={100} height={200} alt={card.name} /> | ||
</div> | ||
) | ||
})} | ||
</div> | ||
); | ||
} |
This file contains 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,38 @@ | ||
import { useRouter } from "next/router" | ||
import { useState } from "react" | ||
import Button from "~/components/Button" | ||
import SearchBar from "~/components/SearchBar" | ||
import { api } from "~/utils/api" | ||
|
||
export default function CreateCollectionPage() { | ||
const router = useRouter(); | ||
const [collectionName, setCollectionName] = useState('') | ||
const [selectedCards, setSelectedCards] = useState<string[]>([]) | ||
|
||
const { mutate: collectionMutation } = api.collection.create.useMutation({ | ||
onSuccess: newCollection => { | ||
void router.replace(`/collection/${newCollection.id}`) | ||
} | ||
}); | ||
|
||
function createCollection(data: { name: string, cards: string[] }) { | ||
collectionMutation(data); | ||
} | ||
|
||
return ( | ||
<div> | ||
<h1>Creating Collection</h1> | ||
<form> | ||
<div className="p-4"> | ||
<label htmlFor="collectionName">Collection Name</label> | ||
<input className="text-black" type="text" id="collectionName" onChange={e => setCollectionName(e.target.value)} value={collectionName} /> | ||
</div> | ||
<Button type="button" onClick={() => createCollection({ name: collectionName, cards: selectedCards })}>Create Collection</Button> | ||
<div className="p-4"> | ||
<SearchBar onSelectedChange={setSelectedCards} /> | ||
</div> | ||
</form> | ||
</div> | ||
) | ||
} | ||
|
This file contains 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,33 @@ | ||
import Link from "next/link" | ||
import { type Collection } from "@prisma/client" | ||
import { api } from "~/utils/api" | ||
|
||
const CollectionList = ({ collections }: { collections: Collection[] }) => { | ||
if (collections.length < 1) { | ||
return ( | ||
<> | ||
<p>No collections...</p> | ||
</> | ||
) | ||
} | ||
|
||
return (collections.map(collection => ( | ||
<div key={collection.id}> | ||
<span>{collection.name}</span> | ||
<Link href={`/collection/${collection.id}`}>View Collection</Link> | ||
</div> | ||
))) | ||
} | ||
|
||
export default function CollectionsIndex() { | ||
const { data: collections } = api.collection.getAll.useQuery(); | ||
|
||
return ( | ||
<div> | ||
<Link href="collection/create">Create Collection</Link> | ||
<p>Your collections</p> | ||
<CollectionList collections={collections ?? []} /> | ||
</div> | ||
) | ||
} | ||
|
This file contains 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 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 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