diff --git a/src/client/Paginate.tsx b/src/client/Paginate.tsx index 993a471..c282f0b 100644 --- a/src/client/Paginate.tsx +++ b/src/client/Paginate.tsx @@ -16,8 +16,6 @@ export const ShowMore = ({ return items.value.slice(0, $shownItems.value) }) - console.log($paginatedItems.value) - return ( <> {$paginatedItems.value.map(children)} diff --git a/src/client/UtentiPage.tsx b/src/client/UtentiPage.tsx index 0e3d619..a8a7b76 100644 --- a/src/client/UtentiPage.tsx +++ b/src/client/UtentiPage.tsx @@ -1,7 +1,6 @@ -import { useComputed, useSignal } from '@preact/signals' +import { effect, useComputed, useSignal } from '@preact/signals' import Fuse from 'fuse.js' import { useEffect } from 'preact/hooks' -import { trottleDebounce } from './lib/util' import { ShowMore } from './Paginate' type User = { @@ -22,15 +21,48 @@ function applyPatches(users: User[]) { users.reverse() } +const MACCHINISTI = [ + // Lista dei macchinisti attuali + 'delucreziis', + 'minnocci', + 'baldino', + 'mossa', + 'manicastri', + 'llombardo', +] + +const RAPPSTUD = [ + // Lista dei rappresentanti degli studenti attuali + 'smannella', + 'falcionella', + 'piazza', +] + export const UtentiPage = () => { const $utentiData = useSignal([]) - const $fuse = useSignal | null>(null) + + const $filter = useSignal('utenti') + + const $filteredData = useComputed(() => + $filter.value === 'macchinisti' + ? $utentiData.value.filter(user => MACCHINISTI.includes(user.uid)) + : $filter.value === 'rappstud' + ? $utentiData.value.filter(user => RAPPSTUD.includes(user.uid)) + : $utentiData.value, + ) + + const $fuse = useComputed( + () => + new Fuse($filteredData.value, { + keys: ['gecos', 'uid'], + }), + ) const $searchText = useSignal('') const $searchResults = useComputed(() => $searchText.value.trim().length > 0 ? ($fuse.value?.search($searchText.value).map(result => result.item) ?? []) - : $utentiData.value, + : $filteredData.value, ) useEffect(() => { @@ -40,23 +72,25 @@ export const UtentiPage = () => { applyPatches(data) $utentiData.value = data - $fuse.value = new Fuse(data, { - keys: ['gecos'], - }) + + $fuse.value.setCollection(data) }) }, []) return ( <>