Skip to content

Commit 459ce8e

Browse files
committed
preview: simplify
1 parent 414f966 commit 459ce8e

File tree

3 files changed

+26
-96
lines changed

3 files changed

+26
-96
lines changed

sites/preview/src/lib/components/ConfirmRemoveDialog.svelte renamed to sites/preview/src/lib/components/ConfirmDialog.svelte

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
let open = $state.raw(false);
66
let title = $state.raw("");
77
let description = $state.raw("");
8+
let confirmLabel = $state.raw("");
89
let resolveShow: ((value: boolean) => void) | undefined;
910
10-
export function show(args: { title: string; description: string }) {
11+
export function show(args: { title: string; description: string; confirmLabel: string }) {
1112
return new Promise<boolean>((resolve) => {
1213
open = true;
1314
title = args.title;
1415
description = args.description;
16+
confirmLabel = args.confirmLabel;
1517
resolveShow = resolve;
1618
});
1719
}
@@ -55,18 +57,18 @@
5557
</AlertDialog.Description>
5658

5759
<div class="mt-4 flex justify-end gap-2">
58-
<AlertDialog.Cancel
59-
class="inline-flex h-10 items-center justify-center rounded bg-neutral-200 px-6 text-sm font-medium hover:bg-neutral-300 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-current active:scale-95"
60-
>
61-
Cancel
62-
</AlertDialog.Cancel>
63-
6460
<AlertDialog.Action
65-
class="inline-flex h-10 items-center justify-center rounded bg-red-700 px-6 text-sm font-medium text-white hover:bg-red-800 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-red-800 active:scale-95"
61+
class="inline-flex h-10 items-center justify-center rounded bg-neutral-200 px-6 text-sm font-medium hover:bg-neutral-300 focus-visible:outline-2 focus-visible:outline-current active:scale-95"
6662
onclick={() => close(true)}
6763
>
68-
Confirm
64+
{confirmLabel}
6965
</AlertDialog.Action>
66+
67+
<AlertDialog.Cancel
68+
class="inline-flex h-10 items-center justify-center rounded bg-neutral-200 px-6 text-sm font-medium hover:bg-neutral-300 focus-visible:outline-2 focus-visible:outline-current active:scale-95"
69+
>
70+
Cancel
71+
</AlertDialog.Cancel>
7072
</div>
7173
</div>
7274
{/if}

sites/preview/src/lib/components/ResolveConflictDialog.svelte

Lines changed: 0 additions & 77 deletions
This file was deleted.

sites/preview/src/lib/components/Tree.svelte

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
type TreeItemState,
1616
} from "svelte-file-tree";
1717
import { toast } from "svelte-sonner";
18-
import ConfirmRemoveDialog from "./ConfirmRemoveDialog.svelte";
19-
import ResolveConflictDialog from "./ResolveConflictDialog.svelte";
18+
import ConfirmDialog from "./ConfirmDialog.svelte";
2019
import TreeItem from "./TreeItem.svelte";
2120
import type { TreeProps } from "./types.js";
2221
@@ -28,8 +27,7 @@
2827
let borderAnimationTargetId: string | undefined = $state.raw();
2928
let borderAnimationTimeout: number | undefined;
3029
31-
let confirmRemoveDialog: ConfirmRemoveDialog | null = $state.raw(null);
32-
let resolveConflictDialog: ResolveConflictDialog | null = $state.raw(null);
30+
let confirmDialog: ConfirmDialog | null = $state.raw(null);
3331
3432
function startBorderAnimation(targetId: string) {
3533
if (borderAnimationTimeout !== undefined) {
@@ -46,7 +44,7 @@
4644
nodes.sort((a, b) => a.name.localeCompare(b.name));
4745
}
4846
49-
function onResolveNameConflict({ operation, name }: OnResolveNameConflictArgs) {
47+
async function onResolveNameConflict({ operation, name }: OnResolveNameConflictArgs) {
5048
let title: string;
5149
switch (operation) {
5250
case "copy": {
@@ -59,20 +57,23 @@
5957
}
6058
}
6159
62-
return resolveConflictDialog!.show({
60+
const didConfirm = await confirmDialog!.show({
6361
title,
6462
description: `An item named "${name}" already exists in this location. Do you want to skip it or cancel the operation entirely?`,
63+
confirmLabel: "Skip",
6564
});
65+
return didConfirm ? "skip" : "cancel";
6666
}
6767
6868
function onCircularReference({ source }: OnCircularReferenceArgs) {
6969
toast.error(`Cannot move "${source.node.name}" inside itself`);
7070
}
7171
7272
function canRemove({ removed }: OnRemoveArgs) {
73-
return confirmRemoveDialog!.show({
73+
return confirmDialog!.show({
7474
title: `Are you sure you want to delete ${removed.length} item(s)?`,
7575
description: "They will be permanently deleted. This action cannot be undone.",
76+
confirmLabel: "Confirm",
7677
});
7778
}
7879
@@ -155,6 +156,11 @@
155156
return false;
156157
}
157158
159+
if (name.includes("/")) {
160+
toast.error("The name cannot contain a slash");
161+
return false;
162+
}
163+
158164
const node = item.node;
159165
const siblings = item.parent?.node.children ?? root.children;
160166
for (const sibling of siblings) {
@@ -169,7 +175,7 @@
169175
}
170176
</script>
171177

172-
<div class="flex min-h-svh p-2">
178+
<div class="flex min-h-svh p-4">
173179
<Tree
174180
{root}
175181
{expandedIds}
@@ -202,5 +208,4 @@
202208
</Tree>
203209
</div>
204210

205-
<ConfirmRemoveDialog bind:this={confirmRemoveDialog} />
206-
<ResolveConflictDialog bind:this={resolveConflictDialog} />
211+
<ConfirmDialog bind:this={confirmDialog} />

0 commit comments

Comments
 (0)