enh: model move to top

This commit is contained in:
Timothy J. Baek 2024-09-18 00:49:27 +02:00
parent 984e0c533e
commit 8e3ad45ce4
3 changed files with 64 additions and 0 deletions

View File

@ -0,0 +1,19 @@
<script lang="ts">
export let className = 'size-4';
export let strokeWidth = '1.5';
</script>
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width={strokeWidth}
stroke="currentColor"
class={className}
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="m15 11.25-3-3m0 0-3 3m3-3v7.5M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z"
/>
</svg>

View File

@ -94,6 +94,35 @@
window.addEventListener('message', messageHandler, false);
};
const moveToTopHandler = async (model) => {
let info = model.info;
if (!info) {
info = {
id: model.id,
name: model.name,
meta: {
position: 0
},
params: {}
};
}
info.meta = {
...info.meta,
position: 0
};
const res = await updateModelById(localStorage.token, info.id, info);
if (res) {
toast.success($i18n.t(`Model {{name}} is now at the top`, { name: info.id }));
}
await models.set(await getModels(localStorage.token));
_models = $models;
};
const hideModelHandler = async (model) => {
let info = model.info;
@ -440,6 +469,9 @@
exportHandler={() => {
exportModelHandler(model);
}}
moveToTopHandler={() => {
moveToTopHandler(model);
}}
hideHandler={() => {
hideModelHandler(model);
}}

View File

@ -12,6 +12,7 @@
import ArchiveBox from '$lib/components/icons/ArchiveBox.svelte';
import DocumentDuplicate from '$lib/components/icons/DocumentDuplicate.svelte';
import ArrowDownTray from '$lib/components/icons/ArrowDownTray.svelte';
import ArrowUpCircle from '$lib/components/icons/ArrowUpCircle.svelte';
const i18n = getContext('i18n');
@ -21,6 +22,7 @@
export let cloneHandler: Function;
export let exportHandler: Function;
export let moveToTopHandler: Function;
export let hideHandler: Function;
export let deleteHandler: Function;
export let onClose: Function;
@ -80,6 +82,17 @@
<div class="flex items-center">{$i18n.t('Export')}</div>
</DropdownMenu.Item>
<DropdownMenu.Item
class="flex gap-2 items-center px-3 py-2 text-sm font-medium cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 rounded-md"
on:click={() => {
moveToTopHandler();
}}
>
<ArrowUpCircle />
<div class="flex items-center">{$i18n.t('Move to Top')}</div>
</DropdownMenu.Item>
<DropdownMenu.Item
class="flex gap-2 items-center px-3 py-2 text-sm font-medium cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 rounded-md"
on:click={() => {