From 4489683ce9c37c43d8508e97f830ec30fe6b9fb6 Mon Sep 17 00:00:00 2001 From: Nexmoe <16796652+nexmoe@users.noreply.github.com> Date: Fri, 3 May 2024 11:39:59 +0800 Subject: [PATCH 1/3] feat: Add search functionality to search page and API endpoint Added search functionality to the search page allowing users to search for modules based on title or content. Also, implemented a new API endpoint for searching modules by query. --- pages/search.vue | 78 +++++++++++++++++++++++++++++++++++ server/trpc/routers/module.ts | 18 ++++++++ 2 files changed, 96 insertions(+) create mode 100644 pages/search.vue diff --git a/pages/search.vue b/pages/search.vue new file mode 100644 index 0000000..cee0cac --- /dev/null +++ b/pages/search.vue @@ -0,0 +1,78 @@ + + + + + diff --git a/server/trpc/routers/module.ts b/server/trpc/routers/module.ts index 0280d67..e8377a0 100644 --- a/server/trpc/routers/module.ts +++ b/server/trpc/routers/module.ts @@ -16,4 +16,22 @@ export default router({ where: { id }, }) }), + search: publicProcedure + .input( + z.object({ + query: z.string(), + }), + ) + .query(async ({ ctx, input }) => { + const prisma = ctx.prisma + const { query } = input + return prisma.module.findMany({ + where: { + OR: [ + { title: { contains: query } }, + { content: { contains: query } }, + ], + }, + }) + }), }) From c63a7cf86bed31ee018a593478087f6adb7323c4 Mon Sep 17 00:00:00 2001 From: Nexmoe <16796652+nexmoe@users.noreply.github.com> Date: Fri, 3 May 2024 11:57:55 +0800 Subject: [PATCH 2/3] feat(pages): Improve search functionality and add loading indicator Refactor search functionality in `pages/search.vue` to include asynchronous search operation and loading indicator. Add `loading` state to manage search loading state. Optimize search query handling to only perform search when query value is not empty. Implement error handling for search operations. - Modify search form submission to trigger search operation - Ensure search input field updates query value correctly - Update conditional rendering of search results based on loading state - Add `components/public/Loading.vue` component for displaying loading indicator --- components/public/Loading.vue | 16 +++++++++++++ pages/search.vue | 43 +++++++++++++++++++++++++++-------- 2 files changed, 49 insertions(+), 10 deletions(-) create mode 100644 components/public/Loading.vue diff --git a/components/public/Loading.vue b/components/public/Loading.vue new file mode 100644 index 0000000..4f146cd --- /dev/null +++ b/components/public/Loading.vue @@ -0,0 +1,16 @@ + \ No newline at end of file diff --git a/pages/search.vue b/pages/search.vue index cee0cac..3d36e44 100644 --- a/pages/search.vue +++ b/pages/search.vue @@ -1,17 +1,37 @@