From a52dfcc7fbc7fe14a20b53eaa192e3f86bc143a7 Mon Sep 17 00:00:00 2001 From: MarconLP <13001502+MarconLP@users.noreply.github.com> Date: Fri, 14 Apr 2023 15:49:07 +0200 Subject: [PATCH] add ability to set delete_video_after_link_expires --- prisma/schema.prisma | 22 ++++++------ src/components/ShareModal.tsx | 59 ++++++++++++++++++++++++--------- src/server/api/routers/video.ts | 24 ++++++++++++++ 3 files changed, 79 insertions(+), 26 deletions(-) diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 9b2a930..16632ca 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -16,17 +16,17 @@ datasource db { } model Video { - id String @id @default(cuid()) - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - title String - video_url String - userId String - sharing Boolean @default(false) - deleteAfterExpiry Boolean @default(false) - shareExpiryAt DateTime? - linkShareSeo Boolean @default(false) - user User @relation(fields: [userId], references: [id], onDelete: Cascade) + id String @id @default(cuid()) + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + title String + video_url String + userId String + sharing Boolean @default(false) + delete_after_link_expires Boolean @default(false) + shareExpiryAt DateTime? + linkShareSeo Boolean @default(false) + user User @relation(fields: [userId], references: [id], onDelete: Cascade) @@index([userId]) } diff --git a/src/components/ShareModal.tsx b/src/components/ShareModal.tsx index f8c0005..064a164 100644 --- a/src/components/ShareModal.tsx +++ b/src/components/ShareModal.tsx @@ -20,7 +20,7 @@ export function ShareModal({ video }: Props) { } return { previousValue }; }, - onError: async (err, { videoId }, context) => { + onError: (err, { videoId }, context) => { if (context?.previousValue) { utils.video.get.setData({ videoId }, context.previousValue); } @@ -28,6 +28,27 @@ export function ShareModal({ video }: Props) { }, }); + const setDeleteAfterLinkExpiresMutation = + api.video.setDeleteAfterLinkExpires.useMutation({ + onMutate: async ({ videoId, delete_after_link_expires }) => { + await utils.video.get.cancel(); + const previousValue = utils.video.get.getData({ videoId }); + if (previousValue) { + utils.video.get.setData( + { videoId }, + { ...previousValue, delete_after_link_expires } + ); + } + return { previousValue }; + }, + onError: (err, { videoId }, context) => { + if (context?.previousValue) { + utils.video.get.setData({ videoId }, context.previousValue); + } + console.error(err.message); + }, + }); + const [linkCopied, setLinkCopied] = useState(false); const handleCopy = () => { @@ -104,25 +125,33 @@ export function ShareModal({ video }: Props) { {linkCopied ? "Copied!" : "Copy public link"}
- {/*
*/} - {/* Expire link*/} - - {/* */} - {/*
*/} - {/*
*/} - {/* Delete video when expired*/} - {/* */} - {/*
*/} +
+ Expire link + +
- Share link with search engines + Delete video after link expires console.log("test")} + enabled={video.delete_after_link_expires} + toggle={() => + setDeleteAfterLinkExpiresMutation.mutate({ + videoId: video.id, + delete_after_link_expires: + !video.delete_after_link_expires, + }) + } />
{/*
*/} + {/* Share link with search engines*/} + {/* console.log("test")}*/} + {/* />*/} + {/*
*/} + {/*
*/} {/* Embed code*/} {/*