-
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.
Move award image mgmt to admin page (#98)
Cleans up the user facing interface to focus on picking and showing awards
- Loading branch information
Showing
6 changed files
with
147 additions
and
93 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
"use client"; | ||
|
||
import { useState } from "react"; | ||
|
||
import { trpc } from "~/app/_trpc/client"; | ||
import { AwardImageChoice } from "~/app/awards/AwardImageChoice"; | ||
import { | ||
Card, | ||
CardContent, | ||
CardDescription, | ||
CardHeader, | ||
CardTitle, | ||
} from "~/components/ui/card"; | ||
import { ButtonLoading } from "~/components/ButtonLoading"; | ||
import { Textarea } from "~/components/ui/textarea"; | ||
|
||
export default function AdminAwards() { | ||
const { data: allAwardImages } = trpc.awardRouter.getAllAwardImages.useQuery({ | ||
shouldLimitToProfile: false, | ||
}); | ||
|
||
const utils = trpc.useContext(); | ||
|
||
const [imageUrls, setImageUrls] = useState<string>(""); | ||
|
||
const addAwardImages = trpc.awardRouter.addImageUrlsToDb.useMutation(); | ||
|
||
const handleAddAwardImages = async () => { | ||
const urls = imageUrls.split("\n").filter((url) => url.length > 0); | ||
|
||
await addAwardImages.mutateAsync({ | ||
imageUrls: urls, | ||
}); | ||
|
||
await utils.awardRouter.getAllAwardImages.invalidate(); | ||
}; | ||
|
||
return ( | ||
<section> | ||
<h1>awards</h1> | ||
|
||
<Card className="max-w-4xl"> | ||
<CardHeader> | ||
<CardTitle>Add images to award choices</CardTitle> | ||
<CardDescription> | ||
Paste a set of image URLs here to add to DB | ||
</CardDescription> | ||
</CardHeader> | ||
<CardContent> | ||
<Textarea | ||
value={imageUrls} | ||
onChange={(e) => setImageUrls(e.target.value)} | ||
/> | ||
<ButtonLoading | ||
onClick={handleAddAwardImages} | ||
isLoading={addAwardImages.isLoading} | ||
> | ||
Add URLs | ||
</ButtonLoading> | ||
</CardContent> | ||
</Card> | ||
|
||
<Card className="max-w-4xl"> | ||
<CardHeader> | ||
<CardTitle>Manage award images</CardTitle> | ||
<CardDescription> | ||
Use this section to add URLs or delete images. Deleting an image | ||
will prompt the user to choose a new image. | ||
</CardDescription> | ||
</CardHeader> | ||
<CardContent> | ||
<div className="grid grid-cols-2 gap-4 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5"> | ||
{(allAwardImages ?? []).map((image) => ( | ||
<AwardImageChoice | ||
key={image.id} | ||
image={image} | ||
shouldClickToClaim={false} | ||
/> | ||
))} | ||
</div> | ||
</CardContent> | ||
</Card> | ||
</section> | ||
); | ||
} |
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
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