From 615050c0975a4d9a8a4d209d98ae047be3962b35 Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Tue, 5 Nov 2024 13:15:29 -0600 Subject: [PATCH] add plugin search --- src/lib/helpers/types/pluginTypes.js | 1 + src/lib/scss/custom/pages/_chat.scss | 2 ++ src/lib/services/plugin-service.js | 3 ++- src/routes/VerticalLayout/Sidebar.svelte | 9 ++++----- src/routes/page/plugin/+page.svelte | 22 +++++++++++++++++++++- 5 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/lib/helpers/types/pluginTypes.js b/src/lib/helpers/types/pluginTypes.js index 50e7104..cb9ac9a 100644 --- a/src/lib/helpers/types/pluginTypes.js +++ b/src/lib/helpers/types/pluginTypes.js @@ -22,6 +22,7 @@ /** * @typedef {Object} PluginFilter * @property {import('$commonTypes').Pagination} pager - Pagination + * @property {string[]} [names] - The plugin names */ export default {}; \ No newline at end of file diff --git a/src/lib/scss/custom/pages/_chat.scss b/src/lib/scss/custom/pages/_chat.scss index 21e4755..cae5130 100644 --- a/src/lib/scss/custom/pages/_chat.scss +++ b/src/lib/scss/custom/pages/_chat.scss @@ -89,6 +89,7 @@ flex: 0 0 fit-content; flex-direction: column; height: 100%; + gap: 5px; .chat-head-agent { flex: 0.5; @@ -108,6 +109,7 @@ display: flex; gap: 5px; width: fit-content; + font-size: 12px; } } } diff --git a/src/lib/services/plugin-service.js b/src/lib/services/plugin-service.js index ae9f85c..d03e814 100644 --- a/src/lib/services/plugin-service.js +++ b/src/lib/services/plugin-service.js @@ -11,7 +11,8 @@ export async function getPlugins(filter) { let url = endpoints.pluginListUrl; const response = await axios.get(url, { params: filter, paramsSerializer: { - dots: true + dots: true, + indexes: null } }); return response.data; diff --git a/src/routes/VerticalLayout/Sidebar.svelte b/src/routes/VerticalLayout/Sidebar.svelte index 5084b90..03dbdd4 100644 --- a/src/routes/VerticalLayout/Sidebar.svelte +++ b/src/routes/VerticalLayout/Sidebar.svelte @@ -201,8 +201,7 @@ return path?.startsWith('/') ? path.substring(1) : path; }; - /** @param {string} link */ - const goToPage = (link) => { + const goToPage = () => { globalEventStore.reset(); } @@ -231,19 +230,19 @@ {:else} -
  • goToPage(subMenu.link)}>{$_(subMenu.label)}
  • +
  • goToPage()}>{$_(subMenu.label)}
  • {/if} {/each} {:else}
  • - goToPage(item.link)} > + goToPage()} > {$_(item.label)}
  • diff --git a/src/routes/page/plugin/+page.svelte b/src/routes/page/plugin/+page.svelte index d8ac056..67487f5 100644 --- a/src/routes/page/plugin/+page.svelte +++ b/src/routes/page/plugin/+page.svelte @@ -2,11 +2,13 @@ import Breadcrumb from '$lib/common/Breadcrumb.svelte'; import HeadTitle from '$lib/common/HeadTitle.svelte'; import Plugins from './plugin-list.svelte'; - import { onMount } from 'svelte'; + import { onDestroy, onMount } from 'svelte'; import { getPlugins } from '$lib/services/plugin-service'; import { PUBLIC_PLUGIN_DEFAULT_ICON } from '$env/static/public'; import PlainPagination from '$lib/common/PlainPagination.svelte'; import { _ } from 'svelte-i18n'; + import { globalEventStore } from '$lib/helpers/store'; + import { GlobalEvent } from '$lib/helpers/enums'; const firstPage = 1; const pageSize = 12; @@ -25,10 +27,28 @@ /** @type {import('$commonTypes').Pagination} */ let pager = filter.pager; + /** @type {any} */ + let unsubscriber; + onMount(async () => { await getPagedPlugins(); + + unsubscriber = globalEventStore.subscribe((/** @type {import('$commonTypes').GlobalEvent} */ event) => { + if (event.name !== GlobalEvent.Search) return; + + const names = event.payload ? [event.payload] : undefined; + filter = { + pager: { page: firstPage, size: pageSize, count: 0 }, + names: names + }; + getPagedPlugins(); + }); }); + onDestroy(() => { + unsubscriber?.(); + }); + async function getPagedPlugins() { plugins = await getPlugins(filter); refresh();