utenti: filter by user category

dev
Antonio De Lucreziis 2 months ago
parent 7398f27035
commit de28d3ad6e

@ -16,8 +16,6 @@ export const ShowMore = <T extends any>({
return items.value.slice(0, $shownItems.value)
})
console.log($paginatedItems.value)
return (
<>
{$paginatedItems.value.map(children)}

@ -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<User[]>([])
const $fuse = useSignal<Fuse<User> | 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 (
<>
<div class="search-bar">
<div class="filter-select">
<div
class="filter-select"
onClick={e => {
e.currentTarget.querySelector('select')?.showPicker()
}}
>
<span class="material-symbols-outlined">filter_list</span>
<select>
<option value="new-first">Nuovi utenti</option>
<option value="old-first">Vecchi utenti</option>
<option value="first-name">Nome</option>
<option value="last-name">Cognome</option>
<option value="uid">Username</option>
<select onChange={e => ($filter.value = e.currentTarget.value)} value={$filter.value}>
<option value="utenti">Utenti</option>
<option value="macchinisti">Macchinisti</option>
<option value="rappstud">RappStud</option>
</select>
<span class="material-symbols-outlined">expand_more</span>
</div>
@ -74,23 +108,20 @@ export const UtentiPage = () => {
{$searchResults.value ? (
<ShowMore items={$searchResults} pageSize={10}>
{poissonUser => (
console.log(poissonUser),
(
<div class="search-result">
<div class="icon">
<span class="material-symbols-outlined">person</span>
</div>
<div class="text">{poissonUser.gecos}</div>
<div class="right">
<a
href={`https://poisson.phc.dm.unipi.it/~${poissonUser.uid}`}
target="_blank"
>
<span class="material-symbols-outlined">open_in_new</span>
</a>
</div>
<div class="search-result">
<div class="icon">
<span class="material-symbols-outlined">person</span>
</div>
<div class="text">{poissonUser.gecos}</div>
<div class="right">
<a
href={`https://poisson.phc.dm.unipi.it/~${poissonUser.uid}`}
target="_blank"
>
<span class="material-symbols-outlined">open_in_new</span>
</a>
</div>
)
</div>
)}
</ShowMore>
) : (

Loading…
Cancel
Save