mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-20 20:29:06 +00:00
ui search pagination 2+page re-search fix (#714)
Co-authored-by: Igor Loskutov <igor.loskutoff@gmail.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import React, { useState, useEffect } from "react";
|
import React, { useState, useEffect, useMemo } from "react";
|
||||||
import {
|
import {
|
||||||
Flex,
|
Flex,
|
||||||
Spinner,
|
Spinner,
|
||||||
@@ -235,15 +235,26 @@ export default function TranscriptBrowser() {
|
|||||||
|
|
||||||
const pageSize = 20;
|
const pageSize = 20;
|
||||||
|
|
||||||
|
// must be json-able
|
||||||
|
const searchFilters = useMemo(
|
||||||
|
() => ({
|
||||||
|
q: urlSearchQuery,
|
||||||
|
extras: {
|
||||||
|
room_id: urlRoomId || undefined,
|
||||||
|
source_kind: urlSourceKind || undefined,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
[urlSearchQuery, urlRoomId, urlSourceKind],
|
||||||
|
);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: searchData,
|
data: searchData,
|
||||||
isLoading: searchLoading,
|
isLoading: searchLoading,
|
||||||
refetch: reloadSearch,
|
refetch: reloadSearch,
|
||||||
} = useTranscriptsSearch(urlSearchQuery, {
|
} = useTranscriptsSearch(searchFilters.q, {
|
||||||
limit: pageSize,
|
limit: pageSize,
|
||||||
offset: paginationPageTo0Based(page) * pageSize,
|
offset: paginationPageTo0Based(page) * pageSize,
|
||||||
room_id: urlRoomId || undefined,
|
...searchFilters.extras,
|
||||||
source_kind: urlSourceKind || undefined,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const results = searchData?.results || [];
|
const results = searchData?.results || [];
|
||||||
@@ -255,6 +266,12 @@ export default function TranscriptBrowser() {
|
|||||||
|
|
||||||
const totalPages = getTotalPages(totalResults, pageSize);
|
const totalPages = getTotalPages(totalResults, pageSize);
|
||||||
|
|
||||||
|
// reset pagination when search results change (detected by total change; good enough approximation)
|
||||||
|
useEffect(() => {
|
||||||
|
// operation is idempotent
|
||||||
|
setPage(FIRST_PAGE).then(() => {});
|
||||||
|
}, [JSON.stringify(searchFilters)]);
|
||||||
|
|
||||||
const userName = useUserName();
|
const userName = useUserName();
|
||||||
const [deletionLoading, setDeletionLoading] = useState(false);
|
const [deletionLoading, setDeletionLoading] = useState(false);
|
||||||
const cancelRef = React.useRef(null);
|
const cancelRef = React.useRef(null);
|
||||||
|
|||||||
Reference in New Issue
Block a user