add ui to change the continuous download attribute of a show

This commit is contained in:
maxDorninger
2025-06-22 14:48:40 +02:00
parent 87cb9088c4
commit ca8a102277
6 changed files with 88 additions and 7 deletions

9
web/package-lock.json generated
View File

@@ -22,7 +22,7 @@
"@eslint/compat": "^1.2.5",
"@eslint/js": "^9.18.0",
"@fontsource/fira-mono": "^5.0.0",
"@lucide/svelte": "^0.503.0",
"@lucide/svelte": "^0.482.0",
"@neoconfetti/svelte": "^2.0.0",
"@sveltejs/adapter-static": "^3.0.8",
"@sveltejs/enhanced-img": "^0.6.0",
@@ -1928,10 +1928,11 @@
}
},
"node_modules/@lucide/svelte": {
"version": "0.503.0",
"resolved": "https://registry.npmjs.org/@lucide/svelte/-/svelte-0.503.0.tgz",
"integrity": "sha512-Y7Q8pHnX2YG8Ef4a/VnYFN9tTAJS33MiS78vQtPiyp5iiWuBlTMoViMiRUxQb7U9Ro46RdJ0kpCADvvha3Z2rA==",
"version": "0.482.0",
"resolved": "https://registry.npmjs.org/@lucide/svelte/-/svelte-0.482.0.tgz",
"integrity": "sha512-n2ycHU9cNcleRDwwpEHBJ6pYzVhHIaL3a+9dQa8kns9hB2g05bY+v2p2KP8v0pZwtNhYTHk/F2o2uZ1bVtQGhw==",
"dev": true,
"license": "ISC",
"peerDependencies": {
"svelte": "^5"
}

View File

@@ -17,7 +17,7 @@
"@eslint/compat": "^1.2.5",
"@eslint/js": "^9.18.0",
"@fontsource/fira-mono": "^5.0.0",
"@lucide/svelte": "^0.503.0",
"@lucide/svelte": "^0.482.0",
"@neoconfetti/svelte": "^2.0.0",
"@sveltejs/adapter-static": "^3.0.8",
"@sveltejs/enhanced-img": "^0.6.0",

View File

@@ -0,0 +1,35 @@
<script lang="ts">
import {Checkbox as CheckboxPrimitive, type WithoutChildrenOrChild} from "bits-ui";
import Check from "@lucide/svelte/icons/check";
import Minus from "@lucide/svelte/icons/minus";
import {cn} from "$lib/utils.js";
let {
ref = $bindable(null),
class: className,
checked = $bindable(false),
indeterminate = $bindable(false),
...restProps
}: WithoutChildrenOrChild<CheckboxPrimitive.RootProps> = $props();
</script>
<CheckboxPrimitive.Root
{...restProps}
bind:checked
bind:indeterminate
bind:ref
class={cn(
"border-primary focus-visible:ring-ring data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground peer box-content size-4 shrink-0 rounded-sm border shadow focus-visible:outline-none focus-visible:ring-1 disabled:cursor-not-allowed disabled:opacity-50 data-[disabled=true]:cursor-not-allowed data-[disabled=true]:opacity-50",
className
)}
>
{#snippet children({checked, indeterminate})}
<span class="flex items-center justify-center text-current">
{#if indeterminate}
<Minus class="size-4"/>
{:else}
<Check class={cn("size-4", !checked && "text-transparent")}/>
{/if}
</span>
{/snippet}
</CheckboxPrimitive.Root>

View File

@@ -0,0 +1,7 @@
import Root from "./checkbox.svelte";
export {
Root,
//
Root as Checkbox,
};

View File

@@ -103,6 +103,7 @@ export interface Show {
metadata_provider: string;
seasons: Season[]; // items: { $ref: #/components/schemas/Season }, type: array
id: string; // type: string, format: uuid
continuous_download: boolean;
}
export interface PublicShow {
@@ -113,6 +114,8 @@ export interface PublicShow {
metadata_provider: string;
seasons: PublicSeason[]; // items: { $ref: #/components/schemas/Season }, type: array
id: string; // type: string, format: uuid
continuous_download: boolean;
}
export interface Torrent {

View File

@@ -16,11 +16,32 @@
import RequestSeasonDialog from '$lib/components/request-season-dialog.svelte';
import {browser} from "$app/environment";
import ShowPicture from "$lib/components/show-picture.svelte";
import {Checkbox} from "$lib/components/ui/checkbox/index.js";
import {toast} from 'svelte-sonner';
import {Label} from "$lib/components/ui/label";
const apiUrl = env.PUBLIC_API_URL
let show: Show = getContext('show');
let user: User = getContext('user');
let show: () => Show = getContext('show');
let user: () => User = getContext('user');
let torrents: RichShowTorrent = page.data.torrentsData;
async function toggle_continuous_download() {
let url = new URL(apiUrl + "/tv/shows/" + show().id + "/continuousDownload");
url.searchParams.append('continuous_download', !show().continuous_download);
console.log("Toggling continuous download for show", show().name, "to", !show().continuous_download);
const response = await fetch(url, {
method: 'POST',
credentials: 'include'
});
if (!response.ok) {
const errorText = await response.text();
toast.error("Failed to toggle continuous download: " + errorText);
} else {
show().continuous_download = !show().continuous_download;
toast.success("Continuous download toggled successfully.");
}
}
</script>
<header class="flex h-16 shrink-0 items-center gap-2">
@@ -73,6 +94,20 @@
class="w-full md:w-1/3 flex-auto rounded-xl bg-muted/50 p-4"
>
{#if user().is_superuser}
<div class="my-2 mx-1 block">
<Checkbox
checked={show().continuous_download}
onCheckedChange={() => {
toggle_continuous_download()
}}
id="continuous-download-checkbox"
/>
<Label for="continuous-download-checkbox">
Enable automatic download of future seasons
</Label>
<hr>
</div>
<DownloadSeasonDialog show={show()}/>
{/if}
<RequestSeasonDialog show={show()}/>