mirror of
https://git.kescher.at/CatCatNya/catstodon.git
synced 2024-12-05 02:09:03 +01:00
8160a655a5
Port 863c470a2b
to glitch-soc
Signed-off-by: Claire <claire.github-309c@sitedethib.com>
37 lines
1.1 KiB
TypeScript
37 lines
1.1 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';
|
|
|
|
export const fetchDirectory = createDataLoadingThunk(
|
|
'directory/fetch',
|
|
async (params: Parameters<typeof apiGetDirectory>[0]) =>
|
|
apiGetDirectory(params),
|
|
(data, { dispatch }) => {
|
|
dispatch(importFetchedAccounts(data));
|
|
dispatch(fetchRelationships(data.map((x) => x.id)));
|
|
|
|
return { accounts: data };
|
|
},
|
|
);
|
|
|
|
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 }, 20);
|
|
},
|
|
(data, { dispatch }) => {
|
|
dispatch(importFetchedAccounts(data));
|
|
dispatch(fetchRelationships(data.map((x) => x.id)));
|
|
|
|
return { accounts: data };
|
|
},
|
|
);
|