import { Dialog, Transition } from "@headlessui/react"; import { Fragment, useState } from "react"; import { ModernSwitch } from "~/components/ModernSwitch"; import { api, type RouterOutputs } from "~/utils/api"; import ExpireDateSelectMenu from "~/components/ExpireDateSelectMenu"; interface Props { video: RouterOutputs["video"]["get"]; } export function ShareModal({ video }: Props) { const utils = api.useContext(); const [open, setOpen] = useState(false); const setSharingMutation = api.video.setSharing.useMutation({ onMutate: async ({ videoId, sharing }) => { await utils.video.get.cancel(); const previousValue = utils.video.get.getData({ videoId }); if (previousValue) { utils.video.get.setData({ videoId }, { ...previousValue, sharing }); } return { previousValue }; }, onError: (err, { videoId }, context) => { if (context?.previousValue) { utils.video.get.setData({ videoId }, context.previousValue); } console.error(err.message); }, }); 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 = () => { void navigator.clipboard.writeText(window.location.href); setLinkCopied(true); setTimeout(() => { setLinkCopied(false); }, 5000); }; return ( <> setOpen(true)} className="ml-4 cursor-pointer rounded border border-[#0000001a] px-2 py-2 text-sm text-[#292d34] hover:bg-[#fafbfc]" > Share setOpen(false)} >
Share this recording
Share link with anyone setSharingMutation.mutate({ videoId: video.id, sharing: !video.sharing, }) } />
{video.sharing ? ( <>
Expire link
Delete video after link expires setDeleteAfterLinkExpiresMutation.mutate({ videoId: video.id, delete_after_link_expires: !video.delete_after_link_expires, }) } />
{/*
*/} {/* Share link with search engines*/} {/* console.log("test")}*/} {/* />*/} {/*
*/} {/*
*/} {/* Embed code*/} {/* */} {/*
*/}
) : null}
); }