mirror of
https://github.com/open-webui/open-webui
synced 2025-05-01 19:44:38 +00:00
refac: selector
This commit is contained in:
parent
7aab8b9307
commit
23dcae7054
@ -84,47 +84,49 @@
|
||||
}
|
||||
);
|
||||
|
||||
$: filteredItems = searchValue
|
||||
? fuse
|
||||
.search(searchValue)
|
||||
.map((e) => {
|
||||
return e.item;
|
||||
})
|
||||
.filter((item) => {
|
||||
if (selectedTag === '') {
|
||||
return true;
|
||||
}
|
||||
return (item.model?.tags ?? []).map((tag) => tag.name).includes(selectedTag);
|
||||
})
|
||||
.filter((item) => {
|
||||
if (selectedConnectionType === '') {
|
||||
return true;
|
||||
} else if (selectedConnectionType === 'ollama') {
|
||||
return item.model?.owned_by === 'ollama';
|
||||
} else if (selectedConnectionType === 'openai') {
|
||||
return item.model?.owned_by === 'openai';
|
||||
} else if (selectedConnectionType === 'direct') {
|
||||
return item.model?.direct;
|
||||
}
|
||||
})
|
||||
: items
|
||||
.filter((item) => {
|
||||
if (selectedTag === '') {
|
||||
return true;
|
||||
}
|
||||
return (item.model?.tags ?? []).map((tag) => tag.name).includes(selectedTag);
|
||||
})
|
||||
.filter((item) => {
|
||||
if (selectedConnectionType === '') {
|
||||
return true;
|
||||
} else if (selectedConnectionType === 'ollama') {
|
||||
return item.model?.owned_by === 'ollama';
|
||||
} else if (selectedConnectionType === 'openai') {
|
||||
return item.model?.owned_by === 'openai';
|
||||
} else if (selectedConnectionType === 'direct') {
|
||||
return item.model?.direct;
|
||||
}
|
||||
});
|
||||
$: filteredItems = (
|
||||
searchValue
|
||||
? fuse
|
||||
.search(searchValue)
|
||||
.map((e) => {
|
||||
return e.item;
|
||||
})
|
||||
.filter((item) => {
|
||||
if (selectedTag === '') {
|
||||
return true;
|
||||
}
|
||||
return (item.model?.tags ?? []).map((tag) => tag.name).includes(selectedTag);
|
||||
})
|
||||
.filter((item) => {
|
||||
if (selectedConnectionType === '') {
|
||||
return true;
|
||||
} else if (selectedConnectionType === 'ollama') {
|
||||
return item.model?.owned_by === 'ollama';
|
||||
} else if (selectedConnectionType === 'openai') {
|
||||
return item.model?.owned_by === 'openai';
|
||||
} else if (selectedConnectionType === 'direct') {
|
||||
return item.model?.direct;
|
||||
}
|
||||
})
|
||||
: items
|
||||
.filter((item) => {
|
||||
if (selectedTag === '') {
|
||||
return true;
|
||||
}
|
||||
return (item.model?.tags ?? []).map((tag) => tag.name).includes(selectedTag);
|
||||
})
|
||||
.filter((item) => {
|
||||
if (selectedConnectionType === '') {
|
||||
return true;
|
||||
} else if (selectedConnectionType === 'ollama') {
|
||||
return item.model?.owned_by === 'ollama';
|
||||
} else if (selectedConnectionType === 'openai') {
|
||||
return item.model?.owned_by === 'openai';
|
||||
} else if (selectedConnectionType === 'direct') {
|
||||
return item.model?.direct;
|
||||
}
|
||||
})
|
||||
).filter((item) => !(item.model?.info?.meta?.hidden ?? false));
|
||||
|
||||
$: if (selectedTag || selectedConnectionType) {
|
||||
resetView();
|
||||
@ -282,7 +284,10 @@
|
||||
ollamaVersion = await getOllamaVersion(localStorage.token).catch((error) => false);
|
||||
|
||||
if (items) {
|
||||
tags = items.flatMap((item) => item.model?.tags ?? []).map((tag) => tag.name);
|
||||
tags = items
|
||||
.filter((item) => !(item.model?.info?.meta?.hidden ?? false))
|
||||
.flatMap((item) => item.model?.tags ?? [])
|
||||
.map((tag) => tag.name);
|
||||
|
||||
// Remove duplicates and sort
|
||||
tags = Array.from(new Set(tags)).sort((a, b) => a.localeCompare(b));
|
||||
@ -388,18 +393,20 @@
|
||||
class="flex gap-1 w-fit text-center text-sm font-medium rounded-full bg-transparent px-1.5 pb-0.5"
|
||||
bind:this={tagsContainerElement}
|
||||
>
|
||||
<button
|
||||
class="min-w-fit outline-none p-1.5 {selectedTag === '' &&
|
||||
selectedConnectionType === ''
|
||||
? ''
|
||||
: 'text-gray-300 dark:text-gray-600 hover:text-gray-700 dark:hover:text-white'} transition capitalize"
|
||||
on:click={() => {
|
||||
selectedConnectionType = '';
|
||||
selectedTag = '';
|
||||
}}
|
||||
>
|
||||
{$i18n.t('All')}
|
||||
</button>
|
||||
{#if (items.find((item) => item.model?.owned_by === 'ollama') && items.find((item) => item.model?.owned_by === 'openai')) || items.find((item) => item.model?.direct) || tags.length > 0}
|
||||
<button
|
||||
class="min-w-fit outline-none p-1.5 {selectedTag === '' &&
|
||||
selectedConnectionType === ''
|
||||
? ''
|
||||
: 'text-gray-300 dark:text-gray-600 hover:text-gray-700 dark:hover:text-white'} transition capitalize"
|
||||
on:click={() => {
|
||||
selectedConnectionType = '';
|
||||
selectedTag = '';
|
||||
}}
|
||||
>
|
||||
{$i18n.t('All')}
|
||||
</button>
|
||||
{/if}
|
||||
|
||||
{#if items.find((item) => item.model?.owned_by === 'ollama') && items.find((item) => item.model?.owned_by === 'openai')}
|
||||
<button
|
||||
@ -457,7 +464,7 @@
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#each filteredItems.filter((item) => !(item.model?.info?.meta?.hidden ?? false)) as item, index}
|
||||
{#each filteredItems as item, index}
|
||||
<button
|
||||
aria-label="model-item"
|
||||
class="flex w-full text-left font-medium line-clamp-1 select-none items-center rounded-button py-2 pl-3 pr-1.5 text-sm text-gray-700 dark:text-gray-100 outline-hidden transition-all duration-75 hover:bg-gray-100 dark:hover:bg-gray-800 rounded-lg cursor-pointer data-highlighted:bg-muted {index ===
|
||||
|
Loading…
Reference in New Issue
Block a user