refac: lazy load prompts/tools/functions/tags

This commit is contained in:
Timothy Jaeryang Baek
2024-11-12 15:31:11 -08:00
parent fb464800e4
commit f10d0df490
8 changed files with 256 additions and 162 deletions

View File

@@ -1,6 +1,6 @@
<script lang="ts">
import { getAllTags } from '$lib/apis/chats';
import { tags } from '$lib/stores';
import { stringify } from 'postcss';
import { getContext, createEventDispatcher, onMount, onDestroy, tick } from 'svelte';
import { fade } from 'svelte/transition';
@@ -15,13 +15,14 @@
let lastWord = '';
$: lastWord = value ? value.split(' ').at(-1) : value;
let focused = false;
let options = [
{
name: 'tag:',
description: $i18n.t('search for tags')
}
];
let focused = false;
let loading = false;
let filteredOptions = options;
$: filteredOptions = options.filter((option) => {
@@ -52,6 +53,12 @@
})
: [];
const initTags = async () => {
loading = true;
await tags.set(await getAllTags(localStorage.token));
loading = false;
};
const documentClickHandler = (e) => {
const searchContainer = document.getElementById('search-container');
const chatSearch = document.getElementById('chat-search');
@@ -99,6 +106,7 @@
}}
on:focus={() => {
focused = true;
initTags();
}}
on:keydown={(e) => {
if (e.key === 'Enter') {