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`
|
||||
// wrapper, and a `{ data: { documents: [...] } }` wrapper at different times.
|
||||
// Normalize so a real list is never dropped because of a wrapper mismatch.
|
||||
function extractTenderDocuments(
|
||||
payload: unknown,
|
||||
): TTenderDocumentsResponse[] {
|
||||
function extractTenderDocuments(payload: unknown): TTenderDocumentsResponse[] {
|
||||
if (!payload) return [];
|
||||
if (Array.isArray(payload)) return payload as TTenderDocumentsResponse[];
|
||||
|
||||
@@ -58,12 +56,12 @@ const TenderDetails = ({ params }: IProps) => {
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
const searchParams = useSearchParams();
|
||||
const selectedLanguage = searchParams.get("lang") || "en";
|
||||
const selectedLanguage = searchParams.get("lang") ?? "";
|
||||
const { mutate: translateTender, isPending: isTranslating } =
|
||||
useTranslateTenderMutation();
|
||||
const { data, isLoading, isError, isFetching } = useTenderDetailQuery(
|
||||
details,
|
||||
{ language: selectedLanguage },
|
||||
selectedLanguage ? { language: selectedLanguage } : undefined,
|
||||
);
|
||||
|
||||
const breadcrumbItems = [
|
||||
@@ -107,7 +105,7 @@ const TenderDetails = ({ params }: IProps) => {
|
||||
const nextLanguage = event.target.value;
|
||||
if (!nextLanguage) return;
|
||||
|
||||
const prevLanguage = searchParams.get("lang") || "en";
|
||||
const prevLanguage = searchParams.get("lang") ?? "";
|
||||
if (nextLanguage === prevLanguage) return;
|
||||
|
||||
userPendingLangRef.current = nextLanguage;
|
||||
|
||||
@@ -80,7 +80,7 @@ export const useHybridPagination = ({
|
||||
|
||||
if (cursorStack.length > 0) {
|
||||
const last = cursorStack[cursorStack.length - 1];
|
||||
return Math.max(0, last.fromPage - 1 + cursorStack.length);
|
||||
return Math.max(0, last.fromPage);
|
||||
}
|
||||
|
||||
const paramsCursor =
|
||||
|
||||
Reference in New Issue
Block a user