This commit is contained in:
silentoplayz 2025-06-21 14:55:23 -04:00 committed by GitHub
commit be5826b350
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 32 additions and 5 deletions

View File

@ -12,7 +12,8 @@
deleteAllModels, deleteAllModels,
getBaseModels, getBaseModels,
toggleModelById, toggleModelById,
updateModelById updateModelById,
getModelById
} from '$lib/apis/models'; } from '$lib/apis/models';
import { getModels } from '$lib/apis'; import { getModels } from '$lib/apis';
@ -36,6 +37,9 @@
import Eye from '$lib/components/icons/Eye.svelte'; import Eye from '$lib/components/icons/Eye.svelte';
import { copyToClipboard } from '$lib/utils'; import { copyToClipboard } from '$lib/utils';
import { page } from '$app/stores';
import { goto } from '$app/navigation';
let shiftKey = false; let shiftKey = false;
let importFiles; let importFiles;
@ -67,6 +71,24 @@
let searchValue = ''; let searchValue = '';
$: {
if ($page.url.pathname === '/admin/settings/models/edit') {
const modelIdFromUrl = $page.url.searchParams.get('id');
if (modelIdFromUrl && models) {
const modelExists = models.some((m) => m.id === modelIdFromUrl);
if (modelExists) {
selectedModelId = modelIdFromUrl;
} else {
goto('/admin/settings/models', { replaceState: true });
}
} else if (!modelIdFromUrl) {
goto('/admin/settings/models', { replaceState: true });
}
} else if ($page.url.pathname === '/admin/settings/models' && selectedModelId !== null) {
selectedModelId = null;
}
}
const downloadModels = async (models) => { const downloadModels = async (models) => {
let blob = new Blob([JSON.stringify(models)], { let blob = new Blob([JSON.stringify(models)], {
type: 'application/json' type: 'application/json'
@ -316,7 +338,7 @@
class=" flex flex-1 text-left space-x-3.5 cursor-pointer w-full" class=" flex flex-1 text-left space-x-3.5 cursor-pointer w-full"
type="button" type="button"
on:click={() => { on:click={() => {
selectedModelId = model.id; goto(`/admin/settings/models/edit?id=${model.id}`);
}} }}
> >
<div class=" self-center w-8"> <div class=" self-center w-8">
@ -380,7 +402,7 @@
class="self-center w-fit text-sm px-2 py-2 dark:text-gray-300 dark:hover:text-white hover:bg-black/5 dark:hover:bg-white/5 rounded-xl" class="self-center w-fit text-sm px-2 py-2 dark:text-gray-300 dark:hover:text-white hover:bg-black/5 dark:hover:bg-white/5 rounded-xl"
type="button" type="button"
on:click={() => { on:click={() => {
selectedModelId = model.id; goto(`/admin/settings/models/edit?id=${model.id}`);
}} }}
> >
<svg <svg
@ -554,10 +576,10 @@
onSubmit={(model) => { onSubmit={(model) => {
console.log(model); console.log(model);
upsertModelHandler(model); upsertModelHandler(model);
selectedModelId = null; goto('/admin/settings/models');
}} }}
onBack={() => { onBack={() => {
selectedModelId = null; goto('/admin/settings/models');
}} }}
/> />
{/if} {/if}

View File

@ -0,0 +1,5 @@
<script>
import Models from '$lib/components/admin/Settings/Models.svelte';
</script>
<Models />