File size: 6,034 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
import { t } from "@lingui/macro";
import {
ArrowClockwise,
ArrowCounterClockwise,
ArrowsOutCardinal,
CircleNotch,
ClockClockwise,
CubeFocus,
FilePdf,
Hash,
LineSegment,
LinkSimple,
MagnifyingGlass,
MagnifyingGlassMinus,
MagnifyingGlassPlus,
} from "@phosphor-icons/react";
import { Button, Separator, Toggle, Tooltip } from "@reactive-resume/ui";
import { motion } from "framer-motion";
import { useState } from "react";
import { useToast } from "@/client/hooks/use-toast";
import { usePrintResume } from "@/client/services/resume";
import { useBuilderStore } from "@/client/stores/builder";
import { useResumeStore, useTemporalResumeStore } from "@/client/stores/resume";
const openInNewTab = (url: string) => {
const win = window.open(url, "_blank");
if (win) win.focus();
};
export const BuilderToolbar = () => {
const { toast } = useToast();
const [panMode, setPanMode] = useState<boolean>(true);
const setValue = useResumeStore((state) => state.setValue);
const undo = useTemporalResumeStore((state) => state.undo);
const redo = useTemporalResumeStore((state) => state.redo);
const frameRef = useBuilderStore((state) => state.frame.ref);
const id = useResumeStore((state) => state.resume.id);
const isPublic = useResumeStore((state) => state.resume.visibility === "public");
const pageOptions = useResumeStore((state) => state.resume.data.metadata.page.options);
const { printResume, loading } = usePrintResume();
const onPrint = async () => {
const { url } = await printResume({ id });
openInNewTab(url);
};
const onCopy = async () => {
const { url } = await printResume({ id });
await navigator.clipboard.writeText(url);
toast({
variant: "success",
title: t`A link has been copied to your clipboard.`,
description: t`Anyone with this link can view and download the resume. Share it on your profile or with recruiters.`,
});
};
const onZoomIn = () => frameRef?.contentWindow?.postMessage({ type: "ZOOM_IN" }, "*");
const onZoomOut = () => frameRef?.contentWindow?.postMessage({ type: "ZOOM_OUT" }, "*");
const onResetView = () => frameRef?.contentWindow?.postMessage({ type: "RESET_VIEW" }, "*");
const onCenterView = () => frameRef?.contentWindow?.postMessage({ type: "CENTER_VIEW" }, "*");
const onTogglePanMode = () => {
setPanMode(!panMode);
frameRef?.contentWindow?.postMessage({ type: "TOGGLE_PAN_MODE", panMode: !panMode }, "*");
};
return (
<motion.div className="fixed inset-x-0 bottom-0 mx-auto hidden py-6 text-center md:block">
<div className="inline-flex items-center justify-center rounded-full bg-background px-4 shadow-xl">
<Tooltip content={t`Undo`}>
<Button
size="icon"
variant="ghost"
className="rounded-none"
onClick={() => {
undo();
}}
>
<ArrowCounterClockwise />
</Button>
</Tooltip>
<Tooltip content={t`Redo`}>
<Button
size="icon"
variant="ghost"
className="rounded-none"
onClick={() => {
redo();
}}
>
<ArrowClockwise />
</Button>
</Tooltip>
<Separator orientation="vertical" className="h-9" />
<Tooltip content={panMode ? t`Scroll to Pan` : t`Scroll to Zoom`}>
<Toggle className="rounded-none" pressed={panMode} onPressedChange={onTogglePanMode}>
{panMode ? <ArrowsOutCardinal /> : <MagnifyingGlass />}
</Toggle>
</Tooltip>
<Separator orientation="vertical" className="h-9" />
<Tooltip content={t`Zoom In`}>
<Button size="icon" variant="ghost" className="rounded-none" onClick={onZoomIn}>
<MagnifyingGlassPlus />
</Button>
</Tooltip>
<Tooltip content={t`Zoom Out`}>
<Button size="icon" variant="ghost" className="rounded-none" onClick={onZoomOut}>
<MagnifyingGlassMinus />
</Button>
</Tooltip>
<Tooltip content={t`Reset Zoom`}>
<Button size="icon" variant="ghost" className="rounded-none" onClick={onResetView}>
<ClockClockwise />
</Button>
</Tooltip>
<Tooltip content={t`Center Artboard`}>
<Button size="icon" variant="ghost" className="rounded-none" onClick={onCenterView}>
<CubeFocus />
</Button>
</Tooltip>
<Separator orientation="vertical" className="h-9" />
<Tooltip content={t`Toggle Page Break Line`}>
<Toggle
className="rounded-none"
pressed={pageOptions.breakLine}
onPressedChange={(pressed) => {
setValue("metadata.page.options.breakLine", pressed);
}}
>
<LineSegment />
</Toggle>
</Tooltip>
<Tooltip content={t`Toggle Page Numbers`}>
<Toggle
className="rounded-none"
pressed={pageOptions.pageNumbers}
onPressedChange={(pressed) => {
setValue("metadata.page.options.pageNumbers", pressed);
}}
>
<Hash />
</Toggle>
</Tooltip>
<Separator orientation="vertical" className="h-9" />
<Tooltip content={t`Copy Link to Resume`}>
<Button
size="icon"
variant="ghost"
className="rounded-none"
disabled={!isPublic}
onClick={onCopy}
>
<LinkSimple />
</Button>
</Tooltip>
<Tooltip content={t`Download PDF`}>
<Button
size="icon"
variant="ghost"
disabled={loading}
className="rounded-none"
onClick={onPrint}
>
{loading ? <CircleNotch className="animate-spin" /> : <FilePdf />}
</Button>
</Tooltip>
</div>
</motion.div>
);
};
|