From 93f5ed0fcecee13a59c2ca9e59c40b60574c0d4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Heath=20Dutton=F0=9F=95=B4=EF=B8=8F?= Date: Thu, 15 Jan 2026 12:02:17 -0500 Subject: [PATCH] Fix directory showing load more button when no more profiles exist (#37465) --- app/javascript/mastodon/actions/directory.ts | 13 +++++++++---- .../mastodon/features/directory/index.tsx | 5 ++++- app/javascript/mastodon/reducers/user_lists.js | 4 ++-- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/app/javascript/mastodon/actions/directory.ts b/app/javascript/mastodon/actions/directory.ts index 34ac309c66..a50a377ffc 100644 --- a/app/javascript/mastodon/actions/directory.ts +++ b/app/javascript/mastodon/actions/directory.ts @@ -6,15 +6,17 @@ import { createDataLoadingThunk } from 'mastodon/store/typed_functions'; import { fetchRelationships } from './accounts'; import { importFetchedAccounts } from './importer'; +const DIRECTORY_FETCH_LIMIT = 20; + export const fetchDirectory = createDataLoadingThunk( 'directory/fetch', async (params: Parameters[0]) => - apiGetDirectory(params), + apiGetDirectory(params, DIRECTORY_FETCH_LIMIT), (data, { dispatch }) => { dispatch(importFetchedAccounts(data)); dispatch(fetchRelationships(data.map((x) => x.id))); - return { accounts: data }; + return { accounts: data, isLast: data.length < DIRECTORY_FETCH_LIMIT }; }, ); @@ -26,12 +28,15 @@ export const expandDirectory = createDataLoadingThunk( 'items', ]) as ImmutableList; - return apiGetDirectory({ ...params, offset: loadedItems.size }, 20); + return apiGetDirectory( + { ...params, offset: loadedItems.size }, + DIRECTORY_FETCH_LIMIT, + ); }, (data, { dispatch }) => { dispatch(importFetchedAccounts(data)); dispatch(fetchRelationships(data.map((x) => x.id))); - return { accounts: data }; + return { accounts: data, isLast: data.length < DIRECTORY_FETCH_LIMIT }; }, ); diff --git a/app/javascript/mastodon/features/directory/index.tsx b/app/javascript/mastodon/features/directory/index.tsx index 0fe140b4eb..54317a6c76 100644 --- a/app/javascript/mastodon/features/directory/index.tsx +++ b/app/javascript/mastodon/features/directory/index.tsx @@ -83,6 +83,9 @@ export const Directory: React.FC<{ (state) => state.user_lists.getIn(['directory', 'isLoading'], true) as boolean, ); + const hasMore = useAppSelector( + (state) => !!state.user_lists.getIn(['directory', 'next']), + ); useEffect(() => { void dispatch(fetchDirectory({ order, local })); @@ -182,7 +185,7 @@ export const Directory: React.FC<{ diff --git a/app/javascript/mastodon/reducers/user_lists.js b/app/javascript/mastodon/reducers/user_lists.js index 466bfe54d6..0393c06763 100644 --- a/app/javascript/mastodon/reducers/user_lists.js +++ b/app/javascript/mastodon/reducers/user_lists.js @@ -204,9 +204,9 @@ export default function userLists(state = initialState, action) { else if (fetchFeaturedTags.rejected.match(action)) return state.setIn(['featured_tags', action.meta.arg.accountId, 'isLoading'], false); else if (fetchDirectory.fulfilled.match(action)) - return normalizeList(state, ['directory'], action.payload.accounts, undefined); + return normalizeList(state, ['directory'], action.payload.accounts, action.payload.isLast ? null : true); else if (expandDirectory.fulfilled.match(action)) - return appendToList(state, ['directory'], action.payload.accounts, undefined); + return appendToList(state, ['directory'], action.payload.accounts, action.payload.isLast ? null : true); else if (fetchDirectory.pending.match(action) || expandDirectory.pending.match(action)) return state.setIn(['directory', 'isLoading'], true);