Skip to content

Commit

Permalink
fix: fixed contributor insight contributor grid not loading paged data (
Browse files Browse the repository at this point in the history
  • Loading branch information
nickytonline authored Aug 14, 2024
1 parent f9b495b commit 1f645ed
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
8 changes: 2 additions & 6 deletions lib/hooks/api/useContributorList.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import useSWR, { Fetcher } from "swr";
import { useState } from "react";
import { publicApiFetcher } from "lib/utils/public-api-fetcher";

export function convertToContributors({
Expand Down Expand Up @@ -29,7 +28,7 @@ export const useContributorsList = ({
workspaceId,
listId,
initialData,
initialPage = 1,
page,
defaultLimit = 10,
defaultRange = "30",
showOscr = false,
Expand All @@ -43,16 +42,14 @@ export const useContributorsList = ({
data: DbPRContributor[];
meta: Meta;
};
initialPage?: number;
page: number;
defaultLimit?: number;
defaultRange?: string;
showOscr?: boolean;
username: string;
orderBy?: string;
orderDirection?: string;
}) => {
const [page, setPage] = useState(initialPage);

const query = new URLSearchParams();
query.append("page", page.toString());
query.append("limit", `${defaultLimit}`);
Expand All @@ -77,7 +74,6 @@ export const useContributorsList = ({
const contributors = convertToContributors({ rawContributors: data?.data, username, oscrEnabled: showOscr });

return {
setPage,
data: data ? { data: contributors, meta: data.meta } : { data: [], meta: {} },
isLoading: !error && !data,
isError: !!error,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,18 @@ export default function ContributorInsightEditPage({
isOwner,
username,
}: ContributorInsightEditPageProps) {
const router = useRouter();
const page = Number((router.query.page as string) ?? 1);
const [name, setName] = useState(list.name);
const [loading, setLoading] = useState(false);

const {
data: { data: contributors },
} = useContributorsList({ workspaceId, listId: list?.id, showOscr: true, username });
} = useContributorsList({ workspaceId, listId: list?.id, showOscr: true, username, page });
const initialTrackedContributors = new Map([
...contributors.map((contributor) => [contributor.login ?? contributor.username, true] as const),
]);

const router = useRouter();
const [name, setName] = useState(list.name);
const [loading, setLoading] = useState(false);
const [trackedContributors, setTrackedContributors] = useState<Map<string, boolean>>(initialTrackedContributors);
const [isTrackedContributorsModalOpen, setIsTrackedContributorsModalOpen] = useState(false);
const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ const ListsOverview = ({
const { listId, range, limit } = router.query;
const orderDirection = router.query.orderDirection as OrderDirection;
const orderBy = router.query.orderBy as string;
const page = Number((router.query.page as string) ?? 1);

const setOscrSortDirection = (direction: OrderDirection) => {
setQueryParams({ orderDirection: direction, orderBy: "oscr" });
};

const {
isLoading,
setPage,
data: { data: contributors, meta },
} = useContributorsList({
workspaceId,
Expand All @@ -127,6 +127,7 @@ const ListsOverview = ({
username,
orderBy,
orderDirection,
page,
});

const {
Expand Down

0 comments on commit 1f645ed

Please sign in to comment.