);
}
function VersionActions({ version }: { version: SavedVersion }) {
return (
Back
{version.canModify && (
<>
>
)}
);
}
function VersionOptions({ version }: { version: SavedVersion }) {
let [confirming, setConfirming] = useState<"restore" | "fork" | null>(null);
let [busy, setBusy] = useState(false);
let toaster = useToaster();
let { identity } = useIdentityData();
let router = useRouter();
let isMobile = useIsMobile();
let restore = async () => {
if (busy) return;
setBusy(true);
try {
let res = await restoreVersion(version.tokenId, version.versionId);
if (!res.ok) return toaster({ content: res.error, type: "error" });
setConfirming(null);
toaster({ content: "Version restored", type: "success" });
router.push(`/${version.tokenId}`);
} finally {
setBusy(false);
}
};
let fork = async () => {
if (busy) return;
setBusy(true);
try {
let res = await forkVersionAsNewLeaflet(
version.tokenId,
version.versionId,
);
if (!res.ok) return toaster({ content: res.error, type: "error" });
if (!identity) {
addDocToHome(res.value.token);
globalMutate("leaflets");
}
setConfirming(null);
if (isMobile) window.location.href = `/${res.value.token.id}`;
else window.open(`/${res.value.token.id}`, "_blank");
} finally {
setBusy(false);
}
};
return (
<>
setConfirming(null)}
title="Restore?"
confirmLabel="Restore"
busy={busy}
onConfirm={restore}
>
This will replace the current doc
with this version.
The current doc will also be saved as a version, so you can get it back!
setConfirming(null)}
title="Create a new document?"
confirmLabel="Create new"
busy={busy}
onConfirm={fork}
>
This will copy this version into a new doc and open it in a new tab.
The current doc will be left as is.
>
);
}
function ConfirmModal(props: {
open: boolean;
onClose: () => void;
title: string;
confirmLabel: string;
busy: boolean;
onConfirm: () => void;
children: React.ReactNode;
}) {
return (
{
if (!o && !props.busy) props.onClose();
}}
title={props.title}
className="max-w-full w-sm text-center"
>