CSS cleanup

This commit is contained in:
C-West8
2026-10-23 14:11:44 -05:00
parent 3ca266acc3
commit e801fc3065
12 changed files with 186 additions and 57 deletions

View File

@@ -0,0 +1,24 @@
<script lang="ts" module>
export interface Status {
tone: 'ok' | 'danger';
text: string;
}
</script>
<script lang="ts">
/**
* A form's result, shown after its buttons in the same row. It's always there (empty when
* there's nothing to say), so a message appearing never moves anything.
*/
let { status }: { status: Status | null | undefined } = $props();
</script>
<p class="action-status small tone-{status?.tone ?? 'ok'}" role="status">{status?.text ?? ''}</p>
<style>
.action-status {
flex: 1 1 14rem;
min-width: 0;
color: var(--tone);
}
</style>

View File

@@ -1,11 +1,29 @@
<script lang="ts">
import { enhance } from '$app/forms';
import { SvelteSet } from 'svelte/reactivity';
import ActionStatus, { type Status } from '#lib/components/ActionStatus.svelte';
import StableText from '#lib/components/StableText.svelte';
import TreeName from '#lib/components/TreeName.svelte';
import type { TreeNode } from '#lib/server/status/tree-view.ts';
/** The admin form for choosing which of a project's folders sync. */
let { nodes, excluded }: { nodes: TreeNode[]; excluded: string[] } = $props();
let {
nodes,
excluded,
status
}: {
nodes: TreeNode[];
excluded: string[];
/** The result of the last save, if any. */
status: Status | null;
} = $props();
const LABELS = {
on: 'Syncs',
off: 'Not synced',
covered: 'Not synced (a folder above is unticked)'
};
const LABEL_OPTIONS = Object.values(LABELS);
/** Folders left unticked. Starts from what's saved, and starts over when that changes. */
const unticked = $derived(new SvelteSet(excluded));
@@ -92,11 +110,10 @@
aria-label="Sync {folder.name}"
onchange={() => toggle(unticked, folder.sourceId)}
/>
{#if covered}
Not synced (a folder above is unticked)
{:else}
{ticked ? 'Syncs' : 'Not synced'}
{/if}
<StableText
text={covered ? LABELS.covered : ticked ? LABELS.on : LABELS.off}
options={LABEL_OPTIONS}
/>
</label>
</td>
</tr>
@@ -106,6 +123,7 @@
</div>
<div class="actions">
<button class="button primary">Save folders</button>
<ActionStatus {status} />
</div>
</form>
{/if}

View File

@@ -1,5 +1,6 @@
<script lang="ts">
import { enhance } from '$app/forms';
import StableText from '#lib/components/StableText.svelte';
import type { RunRequestResult } from '#lib/server/sync/coordinator.ts';
let {
@@ -34,7 +35,7 @@
const MESSAGES: Record<RunRequestResult['status'], (r: RunRequestResult) => string> = {
started: () => 'Sync started.',
'already-running': () => 'A sync is already running for this project.',
cooldown: () => 'Run now was used moments ago. It will be available again shortly.',
cooldown: () => 'Run now was used moments ago. Try again shortly.',
unavailable: (r) => (r.status === 'unavailable' ? r.reason : '')
};
</script>
@@ -55,13 +56,10 @@
}}
>
<button class="button primary" disabled={running || remaining > 0 || !!unavailable}>
{#if running}
Syncing…
{:else if remaining > 0}
Run now ({remaining}s)
{:else}
Run now
{/if}
<StableText
text={running ? 'Syncing…' : remaining > 0 ? `Run now (${remaining}s)` : 'Run now'}
options={['Syncing…', `Run now (${cooldownSeconds}s)`, 'Run now']}
/>
</button>
<p class="small muted" role="status">{unavailable ?? message ?? ''}</p>
</form>
@@ -73,9 +71,12 @@
gap: 0.3rem;
}
/* Always two lines tall, so a message appearing doesn't push the page down. */
.run-now p {
max-width: 22rem;
width: 22rem;
max-width: 100%;
text-align: right;
min-height: 1.2em;
height: 3em;
overflow: hidden;
}
</style>

View File

@@ -0,0 +1,30 @@
<script lang="ts">
/**
* Text that changes between known values without changing size: it keeps room for the
* longest of `options`, so the buttons and fields around it never move.
*/
let { text, options }: { text: string; options: readonly string[] } = $props();
</script>
<span class="stable">
<span>{text}</span>
{#each options as option (option)}
<span class="reserve" aria-hidden="true">{option}</span>
{/each}
</span>
<style>
.stable {
display: inline-grid;
font-variant-numeric: tabular-nums;
}
/* Every variant sits in the same cell, so the cell is as wide as the widest one. */
.stable > span {
grid-area: 1 / 1;
}
.reserve {
visibility: hidden;
}
</style>

View File

@@ -20,6 +20,20 @@ export async function attempt<T, E extends object = object>(
}
}
/**
* `attempt` for pages with several forms. Success and failure both carry the action's name,
* so the page can show the message beside the button that was used.
*/
export function attemptAction<E extends object = object>(
action: string,
work: () => Promise<string>,
echo?: E
) {
return attempt(async () => ({ action, message: await work() }), { action, ...echo } as {
action: string;
} & E);
}
/** A form field as a string (empty if missing or a file). */
export function field(data: FormData, name: string): string {
const value = data.get(name);

View File

@@ -59,6 +59,9 @@
html {
-webkit-text-size-adjust: 100%;
/* Keep room for the scrollbar even when the page is short, so filtering or collapsing a
list never shifts everything sideways. */
scrollbar-gutter: stable;
}
body {

View File

@@ -1,5 +1,6 @@
<script lang="ts">
import { enhance } from '$app/forms';
import ActionStatus from '#lib/components/ActionStatus.svelte';
import type { PageProps } from './$types';
let { data, form }: PageProps = $props();
@@ -22,9 +23,6 @@
</div>
{:else}
<form method="POST" class="form" use:enhance>
{#if form?.error}
<div class="notice tone-danger" role="alert">{form.error}</div>
{/if}
<div class="field">
<label for="username">Username</label>
<input
@@ -48,6 +46,7 @@
</div>
<div class="actions">
<button class="button primary">Log in</button>
<ActionStatus status={form?.error ? { tone: 'danger', text: form.error } : null} />
</div>
</form>
{/if}

View File

@@ -1,6 +1,6 @@
import { error, redirect } from '@sveltejs/kit';
import { services } from '#lib/server/app.ts';
import { attempt, field, fields } from '#lib/server/forms.ts';
import { attemptAction, field, fields } from '#lib/server/forms.ts';
import { idParam } from '#lib/server/params.ts';
import type { Actions, PageServerLoad } from './$types';
@@ -19,10 +19,11 @@ export const actions: Actions = {
sourceInput: field(data, 'sourceInput'),
targetInput: field(data, 'targetInput')
};
return attempt(
return attemptAction(
'save',
async () => {
await services().projectService.update(idParam(params.id), values);
return { saved: true };
return 'Changes saved.';
},
{ values }
);
@@ -31,26 +32,26 @@ export const actions: Actions = {
folders: async ({ params, request }) => {
const data = await request.formData();
const choice = { shown: fields(data, 'folder'), synced: fields(data, 'sync') };
return attempt(async () => {
return attemptAction('folders', async () => {
await services().projectService.setFolderSync(idParam(params.id), choice);
return { foldersSaved: true };
return 'Folders saved. ACC catches up on the next sync.';
});
},
resume: ({ params }) =>
attempt(async () => {
attemptAction('resume', async () => {
await services().projectService.resume(idParam(params.id));
return { resumed: true };
return 'Resumed. It syncs again on the next run.';
}),
reset: ({ params }) =>
attempt(async () => {
attemptAction('reset', async () => {
await services().projectService.reset(idParam(params.id));
return { reset: true };
return 'Reset. The next sync reads SharePoint from scratch.';
}),
delete: ({ params }) =>
attempt(async () => {
attemptAction('delete', async () => {
await services().projectService.delete(idParam(params.id));
redirect(303, '/admin');
})

View File

@@ -1,11 +1,20 @@
<script lang="ts">
import { enhance, type SubmitFunction } from '$app/forms';
import { resolve } from '$app/paths';
import ActionStatus, { type Status } from '#lib/components/ActionStatus.svelte';
import FolderSyncForm from '#lib/components/FolderSyncForm.svelte';
import ProjectFields from '#lib/components/ProjectFields.svelte';
import type { PageProps } from './$types';
let { data, form }: PageProps = $props();
/** The result of one of the page's forms, if it was the last one used. */
const statusOf = (action: string): Status | null => {
if (form?.action !== action) return null;
return form.error
? { tone: 'danger', text: form.error }
: { tone: 'ok', text: form.message ?? '' };
};
const project = $derived(data.detail.project);
const values = $derived(form && 'values' in form && form.values ? form.values : project);
const enabled = $derived(
@@ -34,20 +43,6 @@
>
</div>
{#if form?.error}
<div class="notice tone-danger" role="alert">{form.error}</div>
{:else if form && 'saved' in form}
<div class="notice tone-ok" role="status">Changes saved.</div>
{:else if form && 'reset' in form}
<div class="notice tone-ok" role="status">
Project reset. The next sync reads the SharePoint folder from scratch.
</div>
{:else if form && 'resumed' in form}
<div class="notice tone-ok" role="status">Project resumed. It syncs again on the next run.</div>
{:else if form && 'foldersSaved' in form}
<div class="notice tone-ok" role="status">Folders saved. ACC catches up on the next sync.</div>
{/if}
{#if project.pausedReason}
<section class="section">
<h2>Paused</h2>
@@ -58,10 +53,17 @@
moved for good, reset the project and point it at the new folder.
</p>
</div>
<form method="POST" action="?/resume" use:enhance>
<form method="POST" action="?/resume" class="actions" use:enhance>
<button class="button">Resume syncing</button>
<ActionStatus status={statusOf('resume')} />
</form>
</section>
{:else if statusOf('resume')}
<!-- Kept in place after resuming, so the page below doesn't jump up. -->
<section class="section">
<h2>Paused</h2>
<div class="notice tone-ok" role="status">{statusOf('resume')?.text}</div>
</section>
{/if}
<section class="section">
@@ -85,6 +87,7 @@
</label>
<div class="actions">
<button class="button primary">Save changes</button>
<ActionStatus status={statusOf('save')} />
</div>
</form>
</section>
@@ -96,7 +99,11 @@
ACC are deleted on the next sync, and come back if you tick the folder again. New folders sync
unless they're inside an unticked one.
</p>
<FolderSyncForm nodes={data.detail.tree} excluded={project.excludedFolderIds} />
<FolderSyncForm
nodes={data.detail.tree}
excluded={project.excludedFolderIds}
status={statusOf('folders')}
/>
</section>
<section class="section danger-zone">
@@ -112,11 +119,13 @@
<form
method="POST"
action="?/reset"
class="option-form"
use:enhance={confirmFirst(
`Reset ${project.name}? The next sync re-reads the SharePoint folder from scratch.`
)}
>
<button class="button danger">Reset project</button>
<ActionStatus status={statusOf('reset')} />
</form>
</div>
<div class="option">
@@ -130,9 +139,11 @@
<form
method="POST"
action="?/delete"
class="option-form"
use:enhance={confirmFirst(`Remove ${project.name}? This can't be undone.`)}
>
<button class="button danger">Remove project</button>
<ActionStatus status={statusOf('delete')} />
</form>
</div>
</section>
@@ -164,4 +175,14 @@
gap: 0.25rem;
max-width: 60ch;
}
/* The message goes under the button, in a column as wide as the longest one, so the
button stays where it is whether or not there's a message. */
.option-form {
display: grid;
justify-items: end;
gap: 0.3rem;
width: 16rem;
text-align: right;
}
</style>

View File

@@ -1,7 +1,9 @@
<script lang="ts">
import { enhance } from '$app/forms';
import { resolve } from '$app/paths';
import ActionStatus from '#lib/components/ActionStatus.svelte';
import ProjectFields from '#lib/components/ProjectFields.svelte';
import StableText from '#lib/components/StableText.svelte';
import type { PageProps } from './$types';
let { form }: PageProps = $props();
@@ -33,15 +35,16 @@
};
}}
>
{#if form?.error}
<div class="notice tone-danger" role="alert">{form.error}</div>
{/if}
<ProjectFields values={form?.values ?? {}} />
<div class="actions">
<button class="button primary" disabled={saving}>
{saving ? 'Checking folders…' : 'Add project'}
<StableText
text={saving ? 'Checking folders…' : 'Add project'}
options={['Checking folders…', 'Add project']}
/>
</button>
<a class="button" href={resolve('/admin')}>Cancel</a>
<ActionStatus status={form?.error ? { tone: 'danger', text: form.error } : null} />
</div>
</form>
</div>

View File

@@ -18,9 +18,12 @@ export const actions: Actions = {
retry: async ({ params, request }) => {
const sourceId = field(await request.formData(), 'sourceId');
return attempt(async () => {
await services().projectService.retryItem(idParam(params.id), sourceId);
return { retried: sourceId };
});
return attempt(
async () => {
await services().projectService.retryItem(idParam(params.id), sourceId);
return { retried: sourceId };
},
{ sourceId }
);
}
};

View File

@@ -1,6 +1,7 @@
<script lang="ts">
import { enhance } from '$app/forms';
import { resolve } from '$app/paths';
import ActionStatus from '#lib/components/ActionStatus.svelte';
import AutoRefresh from '#lib/components/AutoRefresh.svelte';
import Badge from '#lib/components/Badge.svelte';
import FileTree from '#lib/components/FileTree.svelte';
@@ -77,9 +78,6 @@
{#if detail.issues.length > 0}
<section class="section" aria-labelledby="issues-heading">
<h2 id="issues-heading">Issues</h2>
{#if form?.error}
<div class="notice tone-danger" role="alert">{form.error}</div>
{/if}
<ul class="issues">
{#each detail.issues as issue (issue.sourceId ?? issue.message)}
<li>
@@ -96,9 +94,14 @@
{/if}
</div>
{#if issue.sourceId}
<form method="POST" action="?/retry" use:enhance>
<form method="POST" action="?/retry" class="retry" use:enhance>
<input type="hidden" name="sourceId" value={issue.sourceId} />
<button class="button compact" disabled={detail.running}>Retry on next sync</button>
<ActionStatus
status={form?.error && form.sourceId === issue.sourceId
? { tone: 'danger', text: form.error }
: null}
/>
</form>
{/if}
</li>
@@ -185,6 +188,15 @@
border-top: 1px solid var(--rule);
}
/* The message goes under the button in a fixed-width column, so the button stays put. */
.retry {
display: grid;
justify-items: end;
gap: 0.3rem;
width: 16rem;
text-align: right;
}
.issue-text {
display: grid;
gap: 0.15rem;