Skip to content
This repository has been archived by the owner on Oct 19, 2023. It is now read-only.

Commit

Permalink
able to change the thumbnail and gif times
Browse files Browse the repository at this point in the history
  • Loading branch information
C-Sinclair committed Aug 2, 2022
1 parent 5b6bfea commit 92dda23
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
36 changes: 33 additions & 3 deletions app/src/pages/admin/short/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export const editShortSchema = z.object({
description: z.string().min(1).max(256).optional(),
path: z.string().min(3),
playbackId: z.string(),
thumbnailTime: z.string().optional(),
previewGifStartTime: z.string().optional(),
});

function EditShortForm() {
Expand Down Expand Up @@ -70,8 +72,8 @@ function EditShortForm() {
);

return (
<>
<h1>Edit short</h1>
<div className="flex flex-col items-center w-full mt-10">
<h1 className="text-white text-3xl">Edit short</h1>
<form className="flex flex-col p-20 bg-black max-w-md" ref={zo.ref}>
<div className="mb-4 w-full">
<label htmlFor="title" className="text-white">
Expand Down Expand Up @@ -117,6 +119,34 @@ function EditShortForm() {
aria-invalid={Boolean(zo.errors.playbackId())}
/>
</div>
<div className="mb-4 w-full">
<label htmlFor="thumbnailTime" className="text-white">
Thumbnail Time (s)
</label>
<input
name={zo.fields.thumbnailTime()}
id="thumbnailTime"
className="w-full"
type="number"
aria-invalid={Boolean(zo.errors.thumbnailTime())}
/>
<p className="text-red-50">{zo.errors.thumbnailTime()?.message}</p>
</div>
<div className="mb-4 w-full">
<label htmlFor="previewGifStartTime" className="text-white">
Preview Gif Start Time (s)
</label>
<input
name={zo.fields.previewGifStartTime()}
id="previewGifStartTime"
className="w-full"
type="number"
aria-invalid={Boolean(zo.errors.previewGifStartTime())}
/>
<p className="text-red-50">
{zo.errors.previewGifStartTime()?.message}
</p>
</div>
<button
type="submit"
className="self-end mt-4 text-white"
Expand All @@ -125,6 +155,6 @@ function EditShortForm() {
Submit
</button>
</form>
</>
</div>
);
}
13 changes: 11 additions & 2 deletions app/src/server/routers/short.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,19 @@ export const shortRouter = createRouter()
data: editShortSchema,
}),
async resolve({ input, ctx }) {
const { id, data } = input;
const {
id,
data: { previewGifStartTime, thumbnailTime, ...data },
} = input;
const short = await ctx.prisma.short.update({
where: { id },
data,
data: {
...data,
previewGifStartTime: previewGifStartTime
? parseInt(previewGifStartTime)
: null,
thumbnailTime: thumbnailTime ? parseInt(thumbnailTime) : null,
},
select: defaultShortSelect,
});
return short;
Expand Down

0 comments on commit 92dda23

Please sign in to comment.