From 6a5ef64d35a1e62866257d6c8011f19e6cf79edc Mon Sep 17 00:00:00 2001 From: Patrick Alvin Alcala Date: Thu, 30 Oct 2025 16:33:54 +0800 Subject: [PATCH] Added filter search --- src/pages/AssessorPage/Assessor.tsx | 66 ++++++++++++++++------------- 1 file changed, 36 insertions(+), 30 deletions(-) diff --git a/src/pages/AssessorPage/Assessor.tsx b/src/pages/AssessorPage/Assessor.tsx index b292998..fc4671a 100644 --- a/src/pages/AssessorPage/Assessor.tsx +++ b/src/pages/AssessorPage/Assessor.tsx @@ -3,7 +3,7 @@ import { Logo, Page, Row, Padding, ModalButton, Button, Clickable, Link, Modal, import { FiLogOut } from 'solid-icons/fi' import { Tabs } from '@kobalte/core/tabs' import { ofetch } from 'ofetch' -import { onMount, createSignal, Show } from 'solid-js' +import { onMount, createSignal, Show, createEffect } from 'solid-js' import dayjs from 'dayjs' import { checkConnection, createPdf } from '../../utils/functions' import { FaSolidThumbsUp } from 'solid-icons/fa' @@ -55,18 +55,18 @@ export default () => { } } - const handleFilterChange = (value: string) => { - // setFilter(value) - if (value.trim() === '') { - setApplicationList(fullIDList()) - setNameList(fullNameList()) - } else { - const filteredApplications = fullIDList().filter((app) => app.toLowerCase().includes(value.toLowerCase())) - const filteredNames = fullNameList().slice(0, filteredApplications.length) - setApplicationList(filteredApplications) - setNameList(filteredNames) - } - } + // const handleFilterChange = (value: string) => { + // // setFilter(value) + // if (value.trim() === '') { + // setApplicationList(fullIDList()) + // setNameList(fullNameList()) + // } else { + // const filteredApplications = fullIDList().filter((app) => app.toLowerCase().includes(value.toLowerCase())) + // const filteredNames = fullNameList().slice(0, filteredApplications.length) + // setApplicationList(filteredApplications) + // setNameList(filteredNames) + // } + // } const getPrintDetails = async (id: number) => { const response = await ofetch(API + 'get-printdetails-electrical/' + id) @@ -161,8 +161,8 @@ export default () => { const approversignId = await geteSignId(276) getApprovedDate(approversignId, applicationNo) - const assessorId = await getEmployeeId(op.result7[0]) - const assessorsignId = await geteSignId(assessorId) + // const assessorId = await getEmployeeId(op.result7[0]) + // const assessorsignId = await geteSignId(assessorId) getAssessedDate(op.result11[0]) } @@ -171,22 +171,20 @@ export default () => { return total } - const getListForPrinting = async (query?: string) => { + const getListForPrinting = async () => { try { const response = await ofetch(API + 'get-listopprinting-electrical', { parseResponse: JSON.parse }) - const filteredApplications = response.result.filter((item: any) => - item - .toString() - .toLowerCase() - .includes((query ?? '').toLowerCase()) - ) - const filteredNames = response.result2.filter((item: any) => - item.toString().toLowerCase().includes((query ?? '').toLowerCase()) - ) - // setApplicationList(response.result) - // setNameList(response.result2) - setApplicationList(filteredApplications) - setNameList(filteredNames) + + if (filter() !== '' && filter().trim().length !== 0) { + const filteredApplications = response.result.filter((item: string) => item.includes(filter())) + const filteredIndices = response.result.map((item: string, index: number) => (item.includes(filter()) ? index : -1)).filter((index: number) => index !== -1) + const filteredNames = filteredIndices.map((index: number) => response.result2[index]) + setApplicationList(filteredApplications) + setNameList(filteredNames) + return + } + setApplicationList(response.result) + setNameList(response.result2) } catch (error) { console.error(error) } @@ -352,6 +350,14 @@ export default () => { } }) + createEffect(async () => { + if (filter() !== '') { + await getListForPrinting() + } else if (filter() === '') { + await getListForPrinting() + } + }) + return ( <> @@ -451,7 +457,7 @@ export default () => { - +