feat(frontend): add configurable app settings (file load limit, tag rule apply_to_existing)
- Add appSettings store (localStorage-backed) with two settings: fileLoadLimit (default 100) and tagRuleApplyToExisting (default false) - Settings page: new Behaviour section with numeric input for files per page (10–500) and an on/off toggle for retroactive tag rule application - files/+page.svelte: derive LIMIT from appSettings.fileLoadLimit so changes take effect immediately without reload - TagRuleEditor: pass apply_to_existing from appSettings when activating a rule via PATCH (only sent on activation, not deactivation) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
import { api, ApiError } from '$lib/api/client';
|
||||
import type { Tag, TagOffsetPage, TagRule } from '$lib/api/types';
|
||||
import TagBadge from './TagBadge.svelte';
|
||||
import { appSettings } from '$lib/stores/appSettings';
|
||||
|
||||
interface Props {
|
||||
tagId: string;
|
||||
@@ -62,10 +63,11 @@
|
||||
busy = true;
|
||||
error = '';
|
||||
const thenTagId = rule.then_tag_id!;
|
||||
const activating = !rule.is_active;
|
||||
try {
|
||||
const updated = await api.patch<TagRule>(`/tags/${tagId}/rules/${thenTagId}`, {
|
||||
is_active: !rule.is_active,
|
||||
});
|
||||
const body: Record<string, unknown> = { is_active: activating };
|
||||
if (activating) body.apply_to_existing = $appSettings.tagRuleApplyToExisting;
|
||||
const updated = await api.patch<TagRule>(`/tags/${tagId}/rules/${thenTagId}`, body);
|
||||
onRulesChange(rules.map((r) => r.then_tag_id === thenTagId ? updated : r));
|
||||
} catch (e) {
|
||||
error = e instanceof ApiError ? e.message : 'Failed to update rule';
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import { writable } from 'svelte/store';
|
||||
import { browser } from '$app/environment';
|
||||
|
||||
export interface AppSettings {
|
||||
fileLoadLimit: number;
|
||||
tagRuleApplyToExisting: boolean;
|
||||
}
|
||||
|
||||
const DEFAULTS: AppSettings = {
|
||||
fileLoadLimit: 100,
|
||||
tagRuleApplyToExisting: false,
|
||||
};
|
||||
|
||||
function load(): AppSettings {
|
||||
if (!browser) return { ...DEFAULTS };
|
||||
try {
|
||||
const stored = JSON.parse(localStorage.getItem('app-settings') ?? 'null');
|
||||
return stored ? { ...DEFAULTS, ...stored } : { ...DEFAULTS };
|
||||
} catch {
|
||||
return { ...DEFAULTS };
|
||||
}
|
||||
}
|
||||
|
||||
export const appSettings = writable<AppSettings>(load());
|
||||
|
||||
appSettings.subscribe((v) => {
|
||||
if (browser) localStorage.setItem('app-settings', JSON.stringify(v));
|
||||
});
|
||||
Reference in New Issue
Block a user