Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions app/(admin)/(activity-management)/events/_components/data-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ import { EVENTS_TABLE_QUERY } from "./query";

export function EventsDataTable() {
const PAGE_SIZE = 10;
const [after, setAfter] = useState<string | null>(null);
const [before, setBefore] = useState<string | null>(null);
const [direction, setDirection] = useState<Direction>("backward");
const [cursors, setCursors] = useState<(string | null)[]>([null]);
const [currentIndex, setCurrentIndex] = useState(0);

const variables = direction === "backward"
? { first: PAGE_SIZE, after, last: undefined, before: undefined }
: { last: PAGE_SIZE, before, first: undefined, after: undefined };
const after = cursors[currentIndex];
const variables = { first: PAGE_SIZE, after };

const { data } = useSuspenseQuery(EVENTS_TABLE_QUERY, {
variables,
Expand All @@ -42,13 +40,15 @@ export function EventsDataTable() {
const handlePageChange = (direction: Direction) => {
if (!pageInfo) return;
if (direction === "forward" && pageInfo.hasNextPage) {
setAfter(pageInfo.endCursor ?? null);
setBefore(null);
setDirection("forward");
} else if (direction === "backward" && pageInfo.hasPreviousPage) {
setBefore(pageInfo.startCursor ?? null);
setAfter(null);
setDirection("backward");
const nextCursor = pageInfo.endCursor ?? null;
setCursors(prev => {
const newCursors = prev.slice(0, currentIndex + 1);
newCursors.push(nextCursor);
return newCursors;
});
setCurrentIndex(currentIndex + 1);
} else if (direction === "backward" && currentIndex > 0) {
setCurrentIndex(currentIndex - 1);
}
};

Expand All @@ -58,7 +58,7 @@ export function EventsDataTable() {
data={eventList}
totalCount={data?.events.totalCount ?? 0}
hasNextPage={!!pageInfo?.hasNextPage}
hasPreviousPage={!!pageInfo?.hasPreviousPage}
hasPreviousPage={currentIndex > 0}
onPageChange={handlePageChange}
/>
);
Expand Down
28 changes: 14 additions & 14 deletions app/(admin)/(activity-management)/points/_components/data-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ import { POINTS_TABLE_QUERY } from "./query";

export function PointsDataTable() {
const PAGE_SIZE = 10;
const [after, setAfter] = useState<string | null>(null);
const [before, setBefore] = useState<string | null>(null);
const [direction, setDirection] = useState<Direction>("backward");
const [cursors, setCursors] = useState<(string | null)[]>([null]);
const [currentIndex, setCurrentIndex] = useState(0);

const variables = direction === "backward"
? { first: PAGE_SIZE, after, last: undefined, before: undefined }
: { last: PAGE_SIZE, before, first: undefined, after: undefined };
const after = cursors[currentIndex];
const variables = { first: PAGE_SIZE, after };

const { data } = useSuspenseQuery(POINTS_TABLE_QUERY, {
variables,
Expand Down Expand Up @@ -43,13 +41,15 @@ export function PointsDataTable() {
const handlePageChange = (direction: Direction) => {
if (!pageInfo) return;
if (direction === "forward" && pageInfo.hasNextPage) {
setAfter(pageInfo.endCursor ?? null);
setBefore(null);
setDirection("forward");
} else if (direction === "backward" && pageInfo.hasPreviousPage) {
setBefore(pageInfo.startCursor ?? null);
setAfter(null);
setDirection("backward");
const nextCursor = pageInfo.endCursor ?? null;
setCursors(prev => {
const newCursors = prev.slice(0, currentIndex + 1);
newCursors.push(nextCursor);
return newCursors;
});
setCurrentIndex(currentIndex + 1);
} else if (direction === "backward" && currentIndex > 0) {
setCurrentIndex(currentIndex - 1);
}
};

Expand All @@ -59,7 +59,7 @@ export function PointsDataTable() {
data={pointsList}
totalCount={data?.points.totalCount ?? 0}
hasNextPage={!!pageInfo?.hasNextPage}
hasPreviousPage={!!pageInfo?.hasPreviousPage}
hasPreviousPage={currentIndex > 0}
onPageChange={handlePageChange}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ import { SUBMISSIONS_TABLE_QUERY } from "./query";

export function SubmissionsDataTable() {
const PAGE_SIZE = 10;
const [after, setAfter] = useState<string | null>(null);
const [before, setBefore] = useState<string | null>(null);
const [direction, setDirection] = useState<Direction>("backward");
const [cursors, setCursors] = useState<(string | null)[]>([null]);
const [currentIndex, setCurrentIndex] = useState(0);

const variables = direction === "backward"
? { first: PAGE_SIZE, after, last: undefined, before: undefined }
: { last: PAGE_SIZE, before, first: undefined, after: undefined };
const after = cursors[currentIndex];
const variables = { first: PAGE_SIZE, after };

const { data } = useSuspenseQuery(SUBMISSIONS_TABLE_QUERY, {
variables,
Expand Down Expand Up @@ -46,13 +44,15 @@ export function SubmissionsDataTable() {
const handlePageChange = (direction: Direction) => {
if (!pageInfo) return;
if (direction === "forward" && pageInfo.hasNextPage) {
setAfter(pageInfo.endCursor ?? null);
setBefore(null);
setDirection("forward");
} else if (direction === "backward" && pageInfo.hasPreviousPage) {
setBefore(pageInfo.startCursor ?? null);
setAfter(null);
setDirection("backward");
const nextCursor = pageInfo.endCursor ?? null;
setCursors(prev => {
const newCursors = prev.slice(0, currentIndex + 1);
newCursors.push(nextCursor);
return newCursors;
});
setCurrentIndex(currentIndex + 1);
} else if (direction === "backward" && currentIndex > 0) {
setCurrentIndex(currentIndex - 1);
}
};

Expand All @@ -62,7 +62,7 @@ export function SubmissionsDataTable() {
data={submissionList}
totalCount={data?.submissions.totalCount ?? 0}
hasNextPage={!!pageInfo?.hasNextPage}
hasPreviousPage={!!pageInfo?.hasPreviousPage}
hasPreviousPage={currentIndex > 0}
onPageChange={handlePageChange}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ import { QUESTIONS_TABLE_QUERY } from "./query";

export function QuestionsDataTable() {
const PAGE_SIZE = 5;
const [after, setAfter] = useState<string | null>(null);
const [before, setBefore] = useState<string | null>(null);
const [direction, setDirection] = useState<Direction>("backward");
const [cursors, setCursors] = useState<(string | null)[]>([null]);
const [currentIndex, setCurrentIndex] = useState(0);

const variables = direction === "backward"
? { first: PAGE_SIZE, after, last: undefined, before: undefined }
: { last: PAGE_SIZE, before, first: undefined, after: undefined };
const after = cursors[currentIndex];
const variables = { first: PAGE_SIZE, after };

const { data } = useSuspenseQuery(QUESTIONS_TABLE_QUERY, {
variables,
Expand All @@ -42,13 +40,15 @@ export function QuestionsDataTable() {
const handlePageChange = (direction: Direction) => {
if (!pageInfo) return;
if (direction === "forward" && pageInfo.hasNextPage) {
setAfter(pageInfo.endCursor ?? null);
setBefore(null);
setDirection("forward");
} else if (direction === "backward" && pageInfo.hasPreviousPage) {
setBefore(pageInfo.startCursor ?? null);
setAfter(null);
setDirection("backward");
const nextCursor = pageInfo.endCursor ?? null;
setCursors(prev => {
const newCursors = prev.slice(0, currentIndex + 1);
newCursors.push(nextCursor);
return newCursors;
});
setCurrentIndex(currentIndex + 1);
} else if (direction === "backward" && currentIndex > 0) {
setCurrentIndex(currentIndex - 1);
}
};

Expand All @@ -58,7 +58,7 @@ export function QuestionsDataTable() {
data={questionList}
totalCount={data?.questions.totalCount ?? 0}
hasNextPage={!!pageInfo?.hasNextPage}
hasPreviousPage={!!pageInfo?.hasPreviousPage}
hasPreviousPage={currentIndex > 0}
onPageChange={handlePageChange}
/>
);
Expand Down
28 changes: 14 additions & 14 deletions app/(admin)/(user-management)/users/_components/data-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ import { USERS_TABLE_QUERY } from "./query";

export function UsersDataTable() {
const PAGE_SIZE = 5;
const [after, setAfter] = useState<string | null>(null);
const [before, setBefore] = useState<string | null>(null);
const [direction, setDirection] = useState<Direction>("backward");
const [cursors, setCursors] = useState<(string | null)[]>([null]);
const [currentIndex, setCurrentIndex] = useState(0);

const variables = direction === "backward"
? { first: PAGE_SIZE, after, last: undefined, before: undefined }
: { last: PAGE_SIZE, before, first: undefined, after: undefined };
const after = cursors[currentIndex];
const variables = { first: PAGE_SIZE, after };

const { data } = useSuspenseQuery(USERS_TABLE_QUERY, {
variables,
Expand Down Expand Up @@ -45,13 +43,15 @@ export function UsersDataTable() {
const handlePageChange = (direction: Direction) => {
if (!pageInfo) return;
if (direction === "forward" && pageInfo.hasNextPage) {
setAfter(pageInfo.endCursor ?? null);
setBefore(null);
setDirection("forward");
} else if (direction === "backward" && pageInfo.hasPreviousPage) {
setBefore(pageInfo.startCursor ?? null);
setAfter(null);
setDirection("backward");
const nextCursor = pageInfo.endCursor ?? null;
setCursors(prev => {
const newCursors = prev.slice(0, currentIndex + 1);
newCursors.push(nextCursor);
return newCursors;
});
setCurrentIndex(currentIndex + 1);
} else if (direction === "backward" && currentIndex > 0) {
setCurrentIndex(currentIndex - 1);
}
};

Expand All @@ -61,7 +61,7 @@ export function UsersDataTable() {
data={userList}
totalCount={data?.users.totalCount ?? 0}
hasNextPage={!!pageInfo?.hasNextPage}
hasPreviousPage={!!pageInfo?.hasPreviousPage}
hasPreviousPage={currentIndex > 0}
onPageChange={handlePageChange}
/>
);
Expand Down
2 changes: 2 additions & 0 deletions components/data-table/cursor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export function CursorDataTable<TData, TValue>({
hasPreviousPage,
onPageChange,
}: CursorDataTableProps<TData, TValue>) {
"use no memo";

const table = useReactTable({
data,
columns,
Expand Down
2 changes: 2 additions & 0 deletions components/data-table/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export interface DataTableProps<TData, TValue> {
}

export function DataTableMain<TData, TValue>({ table, columns }: DataTableProps<TData, TValue>) {
"use no memo";

return (
<div className="rounded-md border">
<Table>
Expand Down