Proposal: a modern & typed way of writing Redux actions doing API requests (#30270)

This commit is contained in:
Renaud Chaput 2024-05-23 11:50:13 +02:00 committed by GitHub
parent 3a862439df
commit 10ec421dd4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 281 additions and 125 deletions

View file

@ -1,18 +1,9 @@
import type { ApiRelationshipJSON } from 'mastodon/api_types/relationships';
import { createAppAsyncThunk } from 'mastodon/store/typed_functions';
import { apiSubmitAccountNote } from 'mastodon/api/accounts';
import { createDataLoadingThunk } from 'mastodon/store/typed_functions';
import api from '../api';
export const submitAccountNote = createAppAsyncThunk(
export const submitAccountNote = createDataLoadingThunk(
'account_note/submit',
async (args: { id: string; value: string }) => {
const response = await api().post<ApiRelationshipJSON>(
`/api/v1/accounts/${args.id}/note`,
{
comment: args.value,
},
);
return { relationship: response.data };
},
(accountId: string, note: string) => apiSubmitAccountNote(accountId, note),
(relationship) => ({ relationship }),
{ skipLoading: true },
);