mirror of
https://github.com/mastodon/mastodon.git
synced 2026-07-28 05:17:28 -05:00
Some checks failed
Check i18n / check-i18n (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
CodeQL / Analyze (ruby) (push) Has been cancelled
Check formatting / lint (push) Has been cancelled
JavaScript Linting / lint (push) Has been cancelled
JavaScript Testing / test (push) Has been cancelled
Ruby Testing / build (production) (push) Has been cancelled
Ruby Testing / build (test) (push) Has been cancelled
Ruby Testing / test (.ruby-version) (push) Has been cancelled
Ruby Testing / test (3.2) (push) Has been cancelled
Ruby Testing / test (3.3) (push) Has been cancelled
Ruby Testing / Libvips tests (.ruby-version) (push) Has been cancelled
Ruby Testing / Libvips tests (3.2) (push) Has been cancelled
Ruby Testing / Libvips tests (3.3) (push) Has been cancelled
Ruby Testing / End to End testing (.ruby-version) (push) Has been cancelled
Ruby Testing / End to End testing (3.2) (push) Has been cancelled
Ruby Testing / End to End testing (3.3) (push) Has been cancelled
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Has been cancelled
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.10.2) (push) Has been cancelled
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Has been cancelled
Ruby Testing / Elastic Search integration testing (3.2, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Has been cancelled
Ruby Testing / Elastic Search integration testing (3.3, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Has been cancelled
41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
import { apiGetPoll, apiPollVote } from 'mastodon/api/polls';
|
|
import type { ApiPollJSON } from 'mastodon/api_types/polls';
|
|
import { createPollFromServerJSON } from 'mastodon/models/poll';
|
|
import {
|
|
createAppAsyncThunk,
|
|
createDataLoadingThunk,
|
|
} from 'mastodon/store/typed_functions';
|
|
|
|
import { importPolls } from './importer/polls';
|
|
|
|
export const importFetchedPoll = createAppAsyncThunk(
|
|
'poll/importFetched',
|
|
(args: { poll: ApiPollJSON }, { dispatch, getState }) => {
|
|
const { poll } = args;
|
|
|
|
dispatch(
|
|
importPolls({
|
|
polls: [createPollFromServerJSON(poll, getState().polls[poll.id])],
|
|
}),
|
|
);
|
|
},
|
|
);
|
|
|
|
export const vote = createDataLoadingThunk(
|
|
'poll/vote',
|
|
({ pollId, choices }: { pollId: string; choices: string[] }) =>
|
|
apiPollVote(pollId, choices),
|
|
async (poll, { dispatch, discardLoadData }) => {
|
|
await dispatch(importFetchedPoll({ poll }));
|
|
return discardLoadData;
|
|
},
|
|
);
|
|
|
|
export const fetchPoll = createDataLoadingThunk(
|
|
'poll/fetch',
|
|
({ pollId }: { pollId: string }) => apiGetPoll(pollId),
|
|
async (poll, { dispatch }) => {
|
|
await dispatch(importFetchedPoll({ poll }));
|
|
},
|
|
);
|