refactor: enhance data invalidation

This commit is contained in:
maxid
2025-12-21 16:54:32 +01:00
parent 7a44463982
commit bf84cc0a06
9 changed files with 29 additions and 33 deletions

View File

@@ -2,7 +2,7 @@
import { Button } from '$lib/components/ui/button/index.js';
import * as Card from '$lib/components/ui/card/index.js';
import { ImageOff, LoaderCircle } from 'lucide-svelte';
import { goto, invalidateAll } from '$app/navigation';
import { goto } from '$app/navigation';
import { resolve } from '$app/paths';
import type { components } from '$lib/api/api';
import client from '$lib/api';
@@ -40,11 +40,14 @@
}
if (isShow) {
await goto(resolve('/dashboard/tv/[showId]', { showId: data?.id ?? '' }));
await goto(resolve('/dashboard/tv/[showId]', { showId: data?.id ?? '' }), {
invalidateAll: true
});
} else {
await goto(resolve('/dashboard/movies/[movieId]', { movieId: data?.id ?? '' }));
await goto(resolve('/dashboard/movies/[movieId]', { movieId: data?.id ?? '' }), {
invalidateAll: true
});
}
await invalidateAll();
loading = false;
}
</script>

View File

@@ -26,15 +26,14 @@
toast.error('Movie ID is missing');
return;
}
const { response } = await client.DELETE('/api/v1/movies/{movie_id}', {
const { error } = await client.DELETE('/api/v1/movies/{movie_id}', {
params: {
path: { movie_id: media.id },
query: { delete_files_on_disk: deleteFilesOnDisk, delete_torrents: deleteTorrents }
}
});
if (!response.ok) {
const errorText = await response.text();
toast.error('Failed to delete movie: ' + errorText);
if (error) {
toast.error('Failed to delete movie: ' + error.detail);
} else {
toast.success('Movie deleted successfully.');
deleteDialogOpen = false;
@@ -43,15 +42,14 @@
}
async function delete_show() {
const { response } = await client.DELETE('/api/v1/tv/shows/{show_id}', {
const { error } = await client.DELETE('/api/v1/tv/shows/{show_id}', {
params: {
path: { show_id: media.id! },
query: { delete_files_on_disk: deleteFilesOnDisk, delete_torrents: deleteTorrents }
}
});
if (!response.ok) {
const errorText = await response.text();
toast.error('Failed to delete show: ' + errorText);
if (error) {
toast.error('Failed to delete show: ' + error.detail);
} else {
toast.success('Show deleted successfully.');
deleteDialogOpen = false;

View File

@@ -14,11 +14,10 @@
torrent: components['schemas']['MovieTorrent'] | components['schemas']['RichSeasonTorrent'];
} = $props();
let dialogOpen = $state(false);
let importedState = $state(torrent.imported || false);
let importedState = $derived(torrent.imported);
async function closeDialog() {
dialogOpen = false;
importedState = torrent.imported || false;
}
async function saveTorrent() {
const { error } = await client.PATCH('/api/v1/torrent/{torrent_id}/status', {
@@ -32,8 +31,7 @@
}
});
if (error) {
console.error(`Failed to update torrent ${torrent.torrent_id} imported state: ${error}`);
toast.error(`Failed to update torrent: ${error}`);
toast.error('Failed to update torrent.');
return;
}
await invalidateAll();
@@ -53,10 +51,8 @@
</Dialog.Description>
</Dialog.Header>
<div class="flex gap-2">
<Label for="imported-state">Torrent {importedState ? 'is' : 'is not'} imported.</Label>
<Switch bind:checked={importedState} id="imported-state" />
<Label for="imported-state"
>Change Torrent import state to: {importedState ? 'is' : 'is not'} imported.</Label
>
</div>
<Dialog.Footer class="mt-8 flex justify-between gap-2">
<Button onclick={() => closeDialog()} variant="secondary">Cancel</Button>

View File

@@ -9,6 +9,7 @@
import { toast } from 'svelte-sonner';
import client from '$lib/api';
import type { components } from '$lib/api/api';
import { invalidateAll } from '$app/navigation';
let {
media,
@@ -70,6 +71,7 @@
toast.success(`Library updated to ${selectedLabel}`);
media.library = selectedLabel;
}
await invalidateAll();
}
function closeAndFocusTrigger() {

View File

@@ -8,6 +8,7 @@
import { toast } from 'svelte-sonner';
import client from '$lib/api';
import type { components } from '$lib/api/api';
import { invalidateAll } from '$app/navigation';
let { movie }: { movie: components['schemas']['PublicMovie'] } = $props();
let dialogOpen = $state(false);
@@ -44,6 +45,7 @@
} else {
toast.error('Failed to submit request');
}
await invalidateAll();
}
</script>

View File

@@ -7,7 +7,7 @@
import { getContext } from 'svelte';
import { Button } from '$lib/components/ui/button/index.js';
import { toast } from 'svelte-sonner';
import { goto } from '$app/navigation';
import { goto, invalidateAll } from '$app/navigation';
import { resolve } from '$app/paths';
import client from '$lib/api';
@@ -56,12 +56,6 @@
response = data.response;
}
if (response.ok) {
const requestIndex = requests.findIndex((r) => r.id === requestId);
if (requestIndex !== -1) {
let newAuthorizedStatus = !currentAuthorizedStatus;
requests[requestIndex]!.authorized = newAuthorizedStatus;
requests[requestIndex]!.authorized_by = newAuthorizedStatus ? user() : undefined;
}
toast.success(
`Request ${!currentAuthorizedStatus ? 'approved' : 'unapproved'} successfully.`
);
@@ -70,6 +64,7 @@
console.error(`Failed to update request status ${response.statusText}`, errorText);
toast.error(`Failed to update request status: ${response.statusText}`);
}
await invalidateAll();
}
async function deleteRequest(requestId: string) {
@@ -101,16 +96,12 @@
response = data.response;
}
if (response.ok) {
// remove the request from the list
const index = requests.findIndex((r) => r.id === requestId);
if (index > -1) {
requests.splice(index, 1);
}
toast.success('Request deleted successfully');
} else {
console.error(`Failed to delete request ${response.statusText}`, await response.text());
toast.error('Failed to delete request');
}
await invalidateAll();
}
</script>

View File

@@ -13,6 +13,7 @@
import { toast } from 'svelte-sonner';
import DeleteTorrentDialog from '$lib/components/delete-torrent-dialog.svelte';
import EditTorrentDialog from '$lib/components/edit-torrent-dialog.svelte';
import { invalidateAll } from '$app/navigation';
let {
torrents,
isShow = true
@@ -42,6 +43,7 @@
console.log(`Successfully retried download for torrent ${torrent.torrent_title}`);
toast.success('Trying to download torrent...');
}
await invalidateAll();
}
</script>

View File

@@ -47,8 +47,8 @@
selectedUser = null;
newPassword = '';
newEmail = '';
await invalidateAll();
}
await invalidateAll();
}
async function deleteUser() {
@@ -68,8 +68,8 @@
toast.success(`User ${userToDelete.email} deleted successfully.`);
deleteDialogOpen = false;
userToDelete = null;
await invalidateAll();
}
await invalidateAll();
}
</script>

View File

@@ -5,6 +5,7 @@
import { Label } from '$lib/components/ui/label/index.js';
import { Input } from '$lib/components/ui/input/index.js';
import client from '$lib/api';
import { invalidateAll } from '$app/navigation';
let newPassword: string = $state('');
let newEmail: string = $state('');
@@ -25,6 +26,7 @@
}
newPassword = '';
newEmail = '';
await invalidateAll();
}
</script>