-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathed-section-order-reset.tsx
More file actions
49 lines (44 loc) · 1.44 KB
/
Copy pathed-section-order-reset.tsx
File metadata and controls
49 lines (44 loc) · 1.44 KB
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
"use client";
import { ListRestart } from "lucide-react";
import { useTranslations } from "next-intl";
import {
canonicalSectionIndex,
isReorderableSection,
type Section,
} from "@/lib/resume";
import { useResumeStore } from "@/lib/store";
import { Button } from "../../ui/button";
import { Tooltip, TooltipContent, TooltipTrigger } from "../../ui/tooltip";
/** True when the reorderable sections are already in canonical (default) order. */
function isDefaultOrder(sections: Section[]): boolean {
const indices = sections
.filter((section) => isReorderableSection(section.type))
.map((section) => canonicalSectionIndex(section.type));
return indices.every(
(value, index) => index === 0 || indices[index - 1] <= value,
);
}
export function EditorSectionOrderReset() {
const open = useResumeStore((state) => state.open);
const resetSectionOrder = useResumeStore((state) => state.resetSectionOrder);
const t = useTranslations("editor.chrome");
const disabled = !open || isDefaultOrder(open.sections);
return (
<Tooltip>
<TooltipTrigger
render={
<Button
size="icon-sm"
variant="ghost"
disabled={disabled}
onClick={() => resetSectionOrder()}
/>
}
>
<ListRestart />
<span className="sr-only">{t("resetOrder")}</span>
</TooltipTrigger>
<TooltipContent>{t("resetOrder")}</TooltipContent>
</Tooltip>
);
}