FEAT: Wipe Contacts table on ingest to prevent duplicates, and commit infinite scroll contacts list

This commit is contained in:
2026-06-13 08:06:56 +02:00
parent 5b32c09076
commit d189da954f
2 changed files with 39 additions and 45 deletions

View File

@@ -63,6 +63,7 @@ namespace GerbilManagerWebAPI.Import
_db.HealthRecords.RemoveRange(_db.HealthRecords); _db.HealthRecords.RemoveRange(_db.HealthRecords);
_db.Gerbils.RemoveRange(_db.Gerbils); _db.Gerbils.RemoveRange(_db.Gerbils);
_db.Litters.RemoveRange(_db.Litters); _db.Litters.RemoveRange(_db.Litters);
_db.Contacts.RemoveRange(_db.Contacts);
await _db.SaveChangesAsync(); await _db.SaveChangesAsync();
} }
else else
@@ -80,6 +81,7 @@ namespace GerbilManagerWebAPI.Import
await _db.HealthRecords.ExecuteDeleteAsync(); await _db.HealthRecords.ExecuteDeleteAsync();
await _db.Gerbils.ExecuteDeleteAsync(); await _db.Gerbils.ExecuteDeleteAsync();
await _db.Litters.ExecuteDeleteAsync(); await _db.Litters.ExecuteDeleteAsync();
await _db.Contacts.ExecuteDeleteAsync();
} }
// 2. Import Contacts (Add new ones, and update roles/details of existing ones) // 2. Import Contacts (Add new ones, and update roles/details of existing ones)

View File

@@ -1,35 +1,48 @@
/** FEAT-2: Kontakte-Liste — Gridify-Namenssuche + Paging, Link auf Detailseite. */ /** FEAT-2: Kontakte-Liste — Gridify-Namenssuche + Infinite Scroll, Link auf Detailseite. */
import { useState } from 'react' import { useEffect, useRef, useState } from 'react'
import { Link } from 'react-router-dom' import { Link } from 'react-router-dom'
import { de } from '../strings/de' import { de } from '../strings/de'
import { listContactsPaged } from '../api/contacts' import { listContactsPaged } from '../api/contacts'
import { condition, type GridifyQuery } from '../api/gridify' import { condition } from '../api/gridify'
import { useApi } from '../hooks/useApi' import { useInfiniteList } from '../hooks/useInfiniteList'
const PAGE_SIZE = 20 const PAGE_SIZE = 20
export default function KontaktePage() { export default function KontaktePage() {
const t = de.pages.kontakte const t = de.pages.kontakte
const [search, setSearch] = useState('') const [search, setSearch] = useState('')
const [page, setPage] = useState(1)
const filter = search.trim() const filter = search.trim()
? condition({ field: 'name', op: 'contains', value: search.trim() }) ? condition({ field: 'name', op: 'contains', value: search.trim() })
: undefined : undefined
const query: GridifyQuery = { filter, orderBy: 'name', page, pageSize: PAGE_SIZE } // Infinite scroll: one page at a time, accumulated. The trailing `id` makes the
// ordering a total order so OFFSET pagination never repeats/omits a row.
const list = useInfiniteList(
(page) => listContactsPaged({ filter, orderBy: 'name,id', page, pageSize: PAGE_SIZE }),
`${filter ?? ''}`,
)
const { items, total, hasMore, loading, loadingMore, loadMore } = list
const contacts = useApi(() => listContactsPaged(query), [filter, page]) const sentinelRef = useRef<HTMLDivElement | null>(null)
useEffect(() => {
const total = contacts.data?.totalCount ?? 0 const el = sentinelRef.current
const totalPages = Math.max(1, Math.ceil(total / PAGE_SIZE)) if (!el) return
const items = contacts.data?.items ?? [] const io = new IntersectionObserver(
(entries) => {
if (entries[0].isIntersecting && hasMore && !loading && !loadingMore) loadMore()
},
{ rootMargin: '300px 0px' },
)
io.observe(el)
return () => io.disconnect()
}, [hasMore, loading, loadingMore, loadMore])
return ( return (
<section className="page"> <section className="page">
<header className="page-head"> <header className="page-head">
<div> <div>
<h2>{t.title}</h2> <h2>{t.title}</h2>
{contacts.data && ( {!loading && (
<p className="muted"> <p className="muted">
{total} {t.countLabel} {total} {t.countLabel}
</p> </p>
@@ -46,27 +59,22 @@ export default function KontaktePage() {
className="input" className="input"
placeholder={t.searchPlaceholder} placeholder={t.searchPlaceholder}
value={search} value={search}
onChange={(e) => { onChange={(e) => setSearch(e.target.value)}
setSearch(e.target.value)
setPage(1)
}}
aria-label={t.fields.name} aria-label={t.fields.name}
/> />
</div> </div>
{contacts.loading && <p className="muted">{de.common.loading}</p>} {loading && <p className="muted">{de.common.loading}</p>}
{contacts.error && ( {list.error && (
<div className="alert alert--error"> <div className="alert alert--error">
<span>{contacts.error}</span> <span>{list.error}</span>
<button type="button" className="btn" onClick={contacts.reload}> <button type="button" className="btn" onClick={list.reload}>
{de.common.retry} {de.common.retry}
</button> </button>
</div> </div>
)} )}
{!contacts.loading && !contacts.error && items.length === 0 && ( {!loading && !list.error && items.length === 0 && <p className="muted">{t.empty}</p>}
<p className="muted">{t.empty}</p>
)}
{items.length > 0 && ( {items.length > 0 && (
<ul className="card-list"> <ul className="card-list">
@@ -115,28 +123,12 @@ export default function KontaktePage() {
</ul> </ul>
)} )}
{totalPages > 1 && ( {/* Infinite-scroll sentinel + "loading more" indicator. */}
<nav className="pager" aria-label="Seitennavigation"> {hasMore && <div ref={sentinelRef} aria-hidden="true" style={{ height: 1 }} />}
<button {loadingMore && (
type="button" <p className="muted" style={{ textAlign: 'center', padding: '0.75rem 0' }}>
className="btn" {de.common.loading}
disabled={page <= 1} </p>
onClick={() => setPage((p) => Math.max(1, p - 1))}
>
{de.common.previous}
</button>
<span className="muted">
{de.common.page} {page} {de.common.of} {totalPages}
</span>
<button
type="button"
className="btn"
disabled={page >= totalPages}
onClick={() => setPage((p) => Math.min(totalPages, p + 1))}
>
{de.common.next}
</button>
</nav>
)} )}
</section> </section>
) )