[Glitch] Fix directory showing load more button when no more profiles exist
Port 93f5ed0fcecee13a59c2ca9e59c40b60574c0d4d to glitch-soc Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
parent
b6b6e142ba
commit
edf50bd073
@ -6,15 +6,17 @@ import { createDataLoadingThunk } from 'flavours/glitch/store/typed_functions';
|
|||||||
import { fetchRelationships } from './accounts';
|
import { fetchRelationships } from './accounts';
|
||||||
import { importFetchedAccounts } from './importer';
|
import { importFetchedAccounts } from './importer';
|
||||||
|
|
||||||
|
const DIRECTORY_FETCH_LIMIT = 20;
|
||||||
|
|
||||||
export const fetchDirectory = createDataLoadingThunk(
|
export const fetchDirectory = createDataLoadingThunk(
|
||||||
'directory/fetch',
|
'directory/fetch',
|
||||||
async (params: Parameters<typeof apiGetDirectory>[0]) =>
|
async (params: Parameters<typeof apiGetDirectory>[0]) =>
|
||||||
apiGetDirectory(params),
|
apiGetDirectory(params, DIRECTORY_FETCH_LIMIT),
|
||||||
(data, { dispatch }) => {
|
(data, { dispatch }) => {
|
||||||
dispatch(importFetchedAccounts(data));
|
dispatch(importFetchedAccounts(data));
|
||||||
dispatch(fetchRelationships(data.map((x) => x.id)));
|
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',
|
'items',
|
||||||
]) as ImmutableList<unknown>;
|
]) as ImmutableList<unknown>;
|
||||||
|
|
||||||
return apiGetDirectory({ ...params, offset: loadedItems.size }, 20);
|
return apiGetDirectory(
|
||||||
|
{ ...params, offset: loadedItems.size },
|
||||||
|
DIRECTORY_FETCH_LIMIT,
|
||||||
|
);
|
||||||
},
|
},
|
||||||
(data, { dispatch }) => {
|
(data, { dispatch }) => {
|
||||||
dispatch(importFetchedAccounts(data));
|
dispatch(importFetchedAccounts(data));
|
||||||
dispatch(fetchRelationships(data.map((x) => x.id)));
|
dispatch(fetchRelationships(data.map((x) => x.id)));
|
||||||
|
|
||||||
return { accounts: data };
|
return { accounts: data, isLast: data.length < DIRECTORY_FETCH_LIMIT };
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
@ -86,6 +86,9 @@ export const Directory: React.FC<{
|
|||||||
(state) =>
|
(state) =>
|
||||||
state.user_lists.getIn(['directory', 'isLoading'], true) as boolean,
|
state.user_lists.getIn(['directory', 'isLoading'], true) as boolean,
|
||||||
);
|
);
|
||||||
|
const hasMore = useAppSelector(
|
||||||
|
(state) => !!state.user_lists.getIn(['directory', 'next']),
|
||||||
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
void dispatch(fetchDirectory({ order, local }));
|
void dispatch(fetchDirectory({ order, local }));
|
||||||
@ -185,7 +188,7 @@ export const Directory: React.FC<{
|
|||||||
|
|
||||||
<LoadMore
|
<LoadMore
|
||||||
onClick={handleLoadMore}
|
onClick={handleLoadMore}
|
||||||
visible={!initialLoad}
|
visible={!initialLoad && hasMore}
|
||||||
loading={isLoading}
|
loading={isLoading}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -204,9 +204,9 @@ export default function userLists(state = initialState, action) {
|
|||||||
else if (fetchFeaturedTags.rejected.match(action))
|
else if (fetchFeaturedTags.rejected.match(action))
|
||||||
return state.setIn(['featured_tags', action.meta.arg.accountId, 'isLoading'], false);
|
return state.setIn(['featured_tags', action.meta.arg.accountId, 'isLoading'], false);
|
||||||
else if (fetchDirectory.fulfilled.match(action))
|
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))
|
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) ||
|
else if (fetchDirectory.pending.match(action) ||
|
||||||
expandDirectory.pending.match(action))
|
expandDirectory.pending.match(action))
|
||||||
return state.setIn(['directory', 'isLoading'], true);
|
return state.setIn(['directory', 'isLoading'], true);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user