Heath Dutton🕴️ edf50bd073 [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>
2026-01-16 22:31:54 +01:00

43 lines
1.3 KiB
TypeScript

import type { List as ImmutableList } from 'immutable';
import { apiGetDirectory } from 'flavours/glitch/api/directory';
import { createDataLoadingThunk } from 'flavours/glitch/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<typeof apiGetDirectory>[0]) =>
apiGetDirectory(params, DIRECTORY_FETCH_LIMIT),
(data, { dispatch }) => {
dispatch(importFetchedAccounts(data));
dispatch(fetchRelationships(data.map((x) => x.id)));
return { accounts: data, isLast: data.length < DIRECTORY_FETCH_LIMIT };
},
);
export const expandDirectory = createDataLoadingThunk(
'directory/expand',
async (params: Parameters<typeof apiGetDirectory>[0], { getState }) => {
const loadedItems = getState().user_lists.getIn([
'directory',
'items',
]) as ImmutableList<unknown>;
return apiGetDirectory(
{ ...params, offset: loadedItems.size },
DIRECTORY_FETCH_LIMIT,
);
},
(data, { dispatch }) => {
dispatch(importFetchedAccounts(data));
dispatch(fetchRelationships(data.map((x) => x.id)));
return { accounts: data, isLast: data.length < DIRECTORY_FETCH_LIMIT };
},
);