fix(tenders): correct cursor pagination and language query handling
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
Stop double-counting cursor stack depth so tender list pages advance sequentially, and only pass a language to tender details when lang is present in the URL. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -29,9 +29,7 @@ interface IProps {
|
|||||||
// Backend has shipped the documents payload as a bare array, an `ApiResponse`
|
// Backend has shipped the documents payload as a bare array, an `ApiResponse`
|
||||||
// wrapper, and a `{ data: { documents: [...] } }` wrapper at different times.
|
// wrapper, and a `{ data: { documents: [...] } }` wrapper at different times.
|
||||||
// Normalize so a real list is never dropped because of a wrapper mismatch.
|
// Normalize so a real list is never dropped because of a wrapper mismatch.
|
||||||
function extractTenderDocuments(
|
function extractTenderDocuments(payload: unknown): TTenderDocumentsResponse[] {
|
||||||
payload: unknown,
|
|
||||||
): TTenderDocumentsResponse[] {
|
|
||||||
if (!payload) return [];
|
if (!payload) return [];
|
||||||
if (Array.isArray(payload)) return payload as TTenderDocumentsResponse[];
|
if (Array.isArray(payload)) return payload as TTenderDocumentsResponse[];
|
||||||
|
|
||||||
@@ -58,12 +56,12 @@ const TenderDetails = ({ params }: IProps) => {
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
const searchParams = useSearchParams();
|
const searchParams = useSearchParams();
|
||||||
const selectedLanguage = searchParams.get("lang") || "en";
|
const selectedLanguage = searchParams.get("lang") ?? "";
|
||||||
const { mutate: translateTender, isPending: isTranslating } =
|
const { mutate: translateTender, isPending: isTranslating } =
|
||||||
useTranslateTenderMutation();
|
useTranslateTenderMutation();
|
||||||
const { data, isLoading, isError, isFetching } = useTenderDetailQuery(
|
const { data, isLoading, isError, isFetching } = useTenderDetailQuery(
|
||||||
details,
|
details,
|
||||||
{ language: selectedLanguage },
|
selectedLanguage ? { language: selectedLanguage } : undefined,
|
||||||
);
|
);
|
||||||
|
|
||||||
const breadcrumbItems = [
|
const breadcrumbItems = [
|
||||||
@@ -107,7 +105,7 @@ const TenderDetails = ({ params }: IProps) => {
|
|||||||
const nextLanguage = event.target.value;
|
const nextLanguage = event.target.value;
|
||||||
if (!nextLanguage) return;
|
if (!nextLanguage) return;
|
||||||
|
|
||||||
const prevLanguage = searchParams.get("lang") || "en";
|
const prevLanguage = searchParams.get("lang") ?? "";
|
||||||
if (nextLanguage === prevLanguage) return;
|
if (nextLanguage === prevLanguage) return;
|
||||||
|
|
||||||
userPendingLangRef.current = nextLanguage;
|
userPendingLangRef.current = nextLanguage;
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ export const useHybridPagination = ({
|
|||||||
|
|
||||||
if (cursorStack.length > 0) {
|
if (cursorStack.length > 0) {
|
||||||
const last = cursorStack[cursorStack.length - 1];
|
const last = cursorStack[cursorStack.length - 1];
|
||||||
return Math.max(0, last.fromPage - 1 + cursorStack.length);
|
return Math.max(0, last.fromPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
const paramsCursor =
|
const paramsCursor =
|
||||||
|
|||||||
Reference in New Issue
Block a user