fix(ui): keep trash counter in sync with trash changes

Reload the rail trash count after every operation that changes the
trash contents, not just navigation and empty-trash: moving photos to
trash (grid, panel, viewer), restoring, permanent delete and deleting
an album. Previously the counter stayed stale until the next route
change.
This commit is contained in:
iu
2026-10-12 12:58:18 +03:00
parent bf3641f9e0
commit 713c1ca6d3
11 changed files with 165 additions and 0 deletions
@@ -13,6 +13,7 @@
import { density } from '$lib/stores/density.svelte';
import { selection } from '$lib/stores/selection.svelte';
import { photoUpdates } from '$lib/stores/photo-updates.svelte';
import { trash } from '$lib/stores/trash.svelte';
import { viewerReturn } from '$lib/stores/viewer-return';
import { transfer } from '$lib/stores/transfer.svelte';
import { contextMenu, type ContextMenuItem } from '$lib/stores/context-menu.svelte';
@@ -295,6 +296,7 @@
await photosApi.deleteBatch(selection.ids);
selection.clear();
pendingDelete = false;
await trash.load();
} catch (e) {
error = (e as Error).message;
} finally {
@@ -7,6 +7,7 @@
import ConfirmDialog from '$lib/components/ConfirmDialog.svelte';
import { viewerActions } from '$lib/stores/viewer-actions.svelte';
import { photoUpdates } from '$lib/stores/photo-updates.svelte';
import { trash } from '$lib/stores/trash.svelte';
import { viewerReturn } from '$lib/stores/viewer-return';
import type { Album, Photo } from '$lib/types';
@@ -79,6 +80,7 @@
try {
await api(`/photos/${photo.id}`, { method: 'DELETE' });
pendingDelete = null;
await trash.load();
const remaining = photos.filter((p) => p.id !== photo.id);
if (remaining.length > 0) {
const next = remaining[Math.min(Math.max(index, 0), remaining.length - 1)];
@@ -3,6 +3,7 @@
import { goto } from '$app/navigation';
import { api } from '$lib/api';
import Icon from '$lib/components/Icon.svelte';
import { trash } from '$lib/stores/trash.svelte';
import type { Album, ShareLink } from '$lib/types';
const albumId = $derived($page.params.id);
@@ -73,6 +74,7 @@
if (!confirm('Удалить альбом вместе с фото?')) return;
try {
await api(`/albums/${albumId}`, { method: 'DELETE' });
await trash.load();
goto('/');
} catch (e) {
error = (e as Error).message;
@@ -47,6 +47,7 @@
try {
await photosApi.restore(p.id);
photos = photos.filter((x) => x.id !== p.id);
await trash.load();
} catch (e) {
if (e instanceof ApiError && e.code === 'album_required') {
restoring = p;
@@ -76,6 +77,7 @@
await photosApi.restore(photo.id, id);
photos = photos.filter((x) => x.id !== photo.id);
restoring = null;
await trash.load();
} catch (e) {
restoreError = (e as Error).message;
} finally {
@@ -90,6 +92,7 @@
await photosApi.permanentDelete(pending.id);
photos = photos.filter((x) => x.id !== pending?.id);
pending = null;
await trash.load();
} catch (e) {
error = (e as Error).message;
} finally {