You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.1 KiB
37 lines
1.1 KiB
import type { List as ImmutableList } from 'immutable'; |
|
|
|
import { apiGetDirectory } from 'mastodon/api/directory'; |
|
import { createDataLoadingThunk } from 'mastodon/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 }; |
|
}, |
|
);
|
|
|