180 lines
4.1 KiB
Svelte
180 lines
4.1 KiB
Svelte
<script lang="ts">
|
|
import { SvelteSet } from 'svelte/reactivity';
|
|
import Badge from '#lib/components/Badge.svelte';
|
|
import TimeAgo from '#lib/components/TimeAgo.svelte';
|
|
import { ITEM_STATUS } from '#lib/format.ts';
|
|
import type { TreeNode } from '#lib/server/status/tree-view.ts';
|
|
|
|
let { nodes }: { nodes: TreeNode[] } = $props();
|
|
|
|
const collapsed = new SvelteSet<string>();
|
|
let attentionOnly = $state(false);
|
|
|
|
interface Row {
|
|
node: TreeNode;
|
|
depth: number;
|
|
}
|
|
|
|
const needsAttention = (node: TreeNode): boolean =>
|
|
node.status !== 'synced' || node.children.some(needsAttention);
|
|
|
|
const rows = $derived.by(() => {
|
|
const result: Row[] = [];
|
|
const walk = (list: TreeNode[], depth: number) => {
|
|
for (const node of list) {
|
|
if (attentionOnly && !needsAttention(node)) continue;
|
|
result.push({ node, depth });
|
|
if (node.isFolder && !collapsed.has(node.sourceId)) walk(node.children, depth + 1);
|
|
}
|
|
};
|
|
walk(nodes, 0);
|
|
return result;
|
|
});
|
|
|
|
function toggle(id: string) {
|
|
if (collapsed.has(id)) collapsed.delete(id);
|
|
else collapsed.add(id);
|
|
}
|
|
|
|
function statusOf(node: TreeNode) {
|
|
if (node.waiting) return { label: 'Waiting on folder', tone: 'info' as const };
|
|
return ITEM_STATUS[node.status];
|
|
}
|
|
</script>
|
|
|
|
<div class="toolbar">
|
|
<label class="check small">
|
|
<input type="checkbox" bind:checked={attentionOnly} />
|
|
Only show files that need attention
|
|
</label>
|
|
</div>
|
|
|
|
{#if rows.length === 0}
|
|
<p class="empty muted">
|
|
{attentionOnly
|
|
? 'Everything is synced.'
|
|
: 'No files yet. They appear here after the first sync.'}
|
|
</p>
|
|
{:else}
|
|
<div class="table-wrap">
|
|
<table class="register">
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Status</th>
|
|
<th>Changed in SharePoint</th>
|
|
<th>Last synced</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{#each rows as { node, depth } (node.sourceId)}
|
|
{@const status = statusOf(node)}
|
|
<tr class:folder={node.isFolder}>
|
|
<td class="name" style:--depth={depth}>
|
|
{#if node.isFolder}
|
|
<button
|
|
type="button"
|
|
class="twisty"
|
|
aria-expanded={!collapsed.has(node.sourceId)}
|
|
aria-label="{collapsed.has(node.sourceId) ? 'Expand' : 'Collapse'} {node.name}"
|
|
onclick={() => toggle(node.sourceId)}
|
|
>
|
|
<svg viewBox="0 0 16 16" aria-hidden="true"><path d="M6 4l4 4-4 4" /></svg>
|
|
</button>
|
|
<svg class="icon" viewBox="0 0 16 16" aria-hidden="true">
|
|
<path d="M1.5 3.5h5l1.5 1.5h6.5v8h-13z" />
|
|
</svg>
|
|
{:else}
|
|
<span class="twisty-spacer"></span>
|
|
<svg class="icon" viewBox="0 0 16 16" aria-hidden="true">
|
|
<path d="M3.5 1.5h6l3 3v10h-9z M9.5 1.5v3h3" />
|
|
</svg>
|
|
{/if}
|
|
<span title={node.error ?? undefined}>{node.name}</span>
|
|
{#if node.problems > 0}
|
|
<span class="problems">{node.problems} failed inside</span>
|
|
{/if}
|
|
</td>
|
|
<td><Badge {...status} /></td>
|
|
<td class="small"><TimeAgo date={node.isFolder ? null : node.modifiedAt} empty="" /></td
|
|
>
|
|
<td class="small"><TimeAgo date={node.syncedAt} empty="Not yet" /></td>
|
|
</tr>
|
|
{/each}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
{/if}
|
|
|
|
<style>
|
|
.toolbar {
|
|
display: flex;
|
|
justify-content: flex-end;
|
|
}
|
|
|
|
.empty {
|
|
padding: 1.5rem;
|
|
border: 1px dashed var(--rule);
|
|
text-align: center;
|
|
}
|
|
|
|
.name {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.35rem;
|
|
padding-left: calc(0.5rem + var(--depth) * 1.25rem);
|
|
min-width: 18rem;
|
|
}
|
|
|
|
.folder .name {
|
|
font-weight: 600;
|
|
}
|
|
|
|
.twisty,
|
|
.twisty-spacer {
|
|
flex: none;
|
|
width: 1.25rem;
|
|
height: 1.25rem;
|
|
}
|
|
|
|
.twisty {
|
|
display: grid;
|
|
place-items: center;
|
|
padding: 0;
|
|
border: 0;
|
|
border-radius: var(--radius);
|
|
background: none;
|
|
color: var(--pencil);
|
|
cursor: pointer;
|
|
}
|
|
|
|
.twisty svg {
|
|
width: 0.85rem;
|
|
height: 0.85rem;
|
|
fill: none;
|
|
stroke: currentColor;
|
|
stroke-width: 1.75;
|
|
transition: transform 120ms ease;
|
|
}
|
|
|
|
.twisty[aria-expanded='true'] svg {
|
|
transform: rotate(90deg);
|
|
}
|
|
|
|
.icon {
|
|
flex: none;
|
|
width: 1rem;
|
|
height: 1rem;
|
|
fill: none;
|
|
stroke: var(--pencil);
|
|
stroke-width: 1.1;
|
|
}
|
|
|
|
.problems {
|
|
margin-left: 0.25rem;
|
|
font-size: var(--step--1);
|
|
font-weight: 500;
|
|
color: var(--danger);
|
|
}
|
|
</style>
|