Skip to content

Commit 1dfda75

Browse files
authored
refactor: simplify feed fetchFn params (#2068)
1 parent 58e8781 commit 1dfda75

20 files changed

+46
-52
lines changed

src/features/feed/Feed.tsx

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,8 @@ import { useRangeChange } from "./useRangeChange";
3232

3333
const ABORT_REASON_UNMOUNT = "unmount";
3434

35-
interface PageData {
36-
page_cursor?: PageCursor;
37-
}
38-
3935
export type FetchFn<I> = (
40-
pageData: PageData,
36+
page_cursor: PageCursor | undefined,
4137
options?: Pick<RequestInit, "signal">,
4238
) => Promise<FetchFnResult<I>>;
4339

@@ -176,12 +172,9 @@ export default function Feed<I>({
176172
abortControllerRef.current = abortController;
177173

178174
try {
179-
result = await fetchFn(
180-
{ page_cursor: currentCursor },
181-
{
182-
signal: abortController.signal,
183-
},
184-
);
175+
result = await fetchFn(currentCursor, {
176+
signal: abortController.signal,
177+
});
185178
} catch (error) {
186179
// Aborted requests are expected. Silently return to avoid spamming console with DOM errors
187180
// Also don't set loading to false, component will unmount (or shortly rerender)

src/features/feed/sort/durations.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,7 @@ export function convertDurationToSeconds(duration: VgerDuration) {
4949
return 2147483647;
5050
case "All":
5151
return undefined;
52+
default:
53+
duration satisfies never; // type exhaustiveness check
5254
}
5355
}

src/features/settings/tags/browse/BrowseTags.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@ export default function BrowseTags({ filter }: BrowseTagsProps) {
1818
{},
1919
);
2020

21-
const fetchFn: FetchFn<UserTagType> = async (pageData) => {
22-
if (typeof pageData.page_cursor === "string")
23-
throw new Error("Invalid page data");
21+
const fetchFn: FetchFn<UserTagType> = async (cursor) => {
22+
if (typeof cursor === "string") throw new Error("Invalid page data");
2423

25-
const page = pageData.page_cursor ?? 0;
24+
const page = cursor ?? 1;
2625

2726
const data = await db.getUserTagsPaginated(
2827
page,
@@ -31,7 +30,7 @@ export default function BrowseTags({ filter }: BrowseTagsProps) {
3130
);
3231

3332
// Reset removed state on refresh
34-
if (!pageData.page_cursor) setRemovedByHandle({});
33+
if (!cursor) setRemovedByHandle({});
3534

3635
return { data, next_page: page + 1 };
3736
};

src/features/user/Profile.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ export default function Profile({ person, onPull }: ProfileProps) {
4949

5050
const isSelf = getRemoteHandle(person.person) === myHandle;
5151

52-
const fetchFn: FetchFn<PostCommentItem> = async (pageData, ...rest) => {
52+
const fetchFn: FetchFn<PostCommentItem> = async (page_cursor, ...rest) => {
5353
const response = await client.listPersonContent(
5454
{
55-
...pageData,
55+
page_cursor,
5656
limit: LIMIT,
5757
person_id: person.person.id,
5858
},

src/routes/pages/inbox/InboxPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ export default function InboxPage({ showRead }: InboxPageProps) {
2828
);
2929
const totalUnread = useAppSelector(totalUnreadSelector);
3030

31-
const fetchFn: FetchFn<InboxItemView> = async (pageData, ...rest) => {
31+
const fetchFn: FetchFn<InboxItemView> = async (page_cursor, ...rest) => {
3232
if (!myUserId) throw new Error("Logged out");
3333

3434
const response = await client.getNotifications(
3535
{
3636
limit: 50,
37-
...pageData,
37+
page_cursor,
3838
unread_only: !showRead,
3939
},
4040
...rest,

src/routes/pages/inbox/MentionsPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ export default function MentionsPage() {
1717
const dispatch = useAppDispatch();
1818
const client = useClient();
1919

20-
const fetchFn: FetchFn<PersonMentionView> = async (pageData, ...rest) => {
20+
const fetchFn: FetchFn<PersonMentionView> = async (page_cursor, ...rest) => {
2121
const response = await client.getPersonMentions(
2222
{
23-
...pageData,
23+
page_cursor,
2424
limit: LIMIT,
2525
unread_only: false,
2626
},

src/routes/pages/inbox/RepliesPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ export default function RepliesPage({ type }: RepliesPageProps) {
2020
const dispatch = useAppDispatch();
2121
const client = useClient();
2222

23-
const fetchFn: FetchFn<CommentReplyView> = async (pageData, ...rest) => {
23+
const fetchFn: FetchFn<CommentReplyView> = async (page_cursor, ...rest) => {
2424
// TODO - actually paginate properly if Lemmy implements
2525
// reply pagination filtering by comment and post
2626
const response = await client.getReplies(
2727
{
28-
...pageData,
28+
page_cursor,
2929
limit: 50,
3030
unread_only: false,
3131
},

src/routes/pages/profile/ProfileFeedCommentsPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ export default function ProfileFeedCommentsPage() {
2727
);
2828
const sortParams = useFeedSortParams("search", sort);
2929

30-
const fetchFn: FetchFn<PostCommentItem> = async (pageData, ...rest) => {
30+
const fetchFn: FetchFn<PostCommentItem> = async (page_cursor, ...rest) => {
3131
if (sortParams === undefined) throw new AbortLoadError();
3232

3333
const person = await dispatch(getUserIfNeeded(handle));
3434

3535
return client.listPersonContent(
3636
{
37-
...pageData,
37+
page_cursor,
3838
type: "Comments",
3939
limit: LIMIT,
4040
person_id: person.id,

src/routes/pages/profile/ProfileFeedHiddenPostsPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ export default function ProfileFeedHiddenPostsPage() {
4343
const lastPageNumberRef = useRef(1);
4444
const lastPageItemsRef = useRef<IPostMetadata[]>([]);
4545

46-
const fetchFn: FetchFn<PostCommentItem> = async (pageData, ...rest) => {
46+
const fetchFn: FetchFn<PostCommentItem> = async (page_cursor, ...rest) => {
4747
postHiddenById; // eslint-disable-line @typescript-eslint/no-unused-expressions -- Trigger rerender when this changes
4848

4949
if (!handle) return { data: [] };
50-
const page = pageData.page_cursor ?? 1;
50+
const page = page_cursor ?? 1;
5151
if (typeof page === "string") return { data: [] };
5252

5353
const hiddenPostMetadatas = await db.getHiddenPostMetadatasPaginated(

src/routes/pages/profile/ProfileFeedPostsPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ export default function ProfileFeedPostsPage() {
2727
);
2828
const sortParams = useFeedSortParams("search", sort ?? "New");
2929

30-
const fetchFn: FetchFn<PostCommentItem> = async (pageData, ...rest) => {
30+
const fetchFn: FetchFn<PostCommentItem> = async (page_cursor, ...rest) => {
3131
if (sortParams === undefined) throw new AbortLoadError();
3232

3333
const person = await dispatch(getUserIfNeeded(handle));
3434

3535
return client.listPersonContent(
3636
{
37-
...pageData,
37+
page_cursor,
3838
type: "Posts",
3939
limit: LIMIT,
4040
person_id: person.id,

0 commit comments

Comments
 (0)