-
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.
92 improve the styles and layout on the main awards page (#93)
* Update styles on the award pages * Add a placeholder image
- Loading branch information
Showing
6 changed files
with
296 additions
and
216 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 @@ | ||
"use client"; | ||
|
||
import Image from "next/image"; | ||
|
||
import { cn } from "~/utils"; | ||
|
||
import { type Award } from "./page"; | ||
|
||
export function AwardCard({ award }: { award: Award }) { | ||
const label = award.awardType === "WORD_COUNT" ? "words" : "sentences"; | ||
|
||
const numberAward = ( | ||
<p className="text-2xl"> | ||
{award.awardValue ?? 0} {label} | ||
</p> | ||
); | ||
|
||
const masteryAward = ( | ||
<p className="text-2xl">{award.word && <p>{award.word?.word}</p>}</p> | ||
); | ||
|
||
return ( | ||
<div className="flex flex-col items-center bg-gray-200"> | ||
{award.word ? masteryAward : numberAward} | ||
|
||
<Image | ||
key={award.id} | ||
src={award.image?.imageUrl ?? "/placeholder.jpeg"} | ||
alt={"Award image"} | ||
width={256} | ||
height={256} | ||
className={cn("rounded-md", { | ||
"border-4 border-yellow-400": !award.imageId, | ||
})} | ||
/> | ||
</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,65 @@ | ||
"use client"; | ||
|
||
import Image from "next/image"; | ||
|
||
import { trpc } from "~/app/_trpc/client"; | ||
import { ButtonLoading } from "~/components/ButtonLoading"; | ||
|
||
import { type AwardImage } from "./page"; | ||
|
||
export function AwardImageChoice({ | ||
image, | ||
shouldClickToClaim, | ||
}: { | ||
image: AwardImage; | ||
shouldClickToClaim: boolean; | ||
}) { | ||
const utils = trpc.useContext(); | ||
|
||
const addImageIdToAward = trpc.awardRouter.addImageIdToAward.useMutation(); | ||
|
||
const handleAddImageIdToAward = async (imageId: string) => { | ||
// confirm add | ||
const shouldAdd = confirm( | ||
"Are you sure you want to add this image to the award?" | ||
); | ||
if (!shouldAdd) { | ||
return; | ||
} | ||
|
||
await addImageIdToAward.mutateAsync({ | ||
imageId, | ||
}); | ||
|
||
await utils.awardRouter.getAllAwardsForProfile.invalidate(); | ||
}; | ||
|
||
const deleteImage = trpc.awardRouter.deleteImage.useMutation(); | ||
|
||
const handleDeleteImage = async (imageId: string) => { | ||
await deleteImage.mutateAsync({ | ||
imageId, | ||
}); | ||
|
||
await utils.awardRouter.getAllAwardImages.invalidate(); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<Image | ||
key={image.id} | ||
src={image.imageUrl} | ||
alt={"Award image"} | ||
width={256} | ||
height={256} | ||
onClick={() => shouldClickToClaim && handleAddImageIdToAward(image.id)} | ||
/> | ||
<ButtonLoading | ||
onClick={() => handleDeleteImage(image.id)} | ||
isLoading={deleteImage.isLoading} | ||
> | ||
Delete | ||
</ButtonLoading> | ||
</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,14 @@ | ||
"use client"; | ||
|
||
import { AwardCard } from "./AwardCard"; | ||
import { type Award } from "./page"; | ||
|
||
export function AwardList({ awards = [] }: { awards?: Award[] }) { | ||
return ( | ||
<div className="grid grid-cols-2 gap-4 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5"> | ||
{awards.map((award) => ( | ||
<AwardCard key={award.id} award={award} /> | ||
))} | ||
</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
Oops, something went wrong.