pl-fe: remove some unused actions

Signed-off-by: mkljczk <git@mkljczk.pl>
This commit is contained in:
mkljczk 2024-12-05 13:41:43 +01:00
parent 771cb6b6b8
commit ea8c07676e
4 changed files with 7 additions and 89 deletions

View file

@ -286,7 +286,6 @@ type NotificationsAction =
export {
NOTIFICATIONS_UPDATE,
NOTIFICATIONS_UPDATE_NOOP,
NOTIFICATIONS_EXPAND_REQUEST,
NOTIFICATIONS_EXPAND_SUCCESS,
NOTIFICATIONS_EXPAND_FAIL,

View file

@ -7,49 +7,29 @@ import { importEntities } from './importer';
import type { PaginatedResponse, Status } from 'pl-api';
import type { AppDispatch, RootState } from 'pl-fe/store';
const PINNED_STATUSES_FETCH_REQUEST = 'PINNED_STATUSES_FETCH_REQUEST' as const;
const PINNED_STATUSES_FETCH_SUCCESS = 'PINNED_STATUSES_FETCH_SUCCESS' as const;
const PINNED_STATUSES_FETCH_FAIL = 'PINNED_STATUSES_FETCH_FAIL' as const;
const fetchPinnedStatuses = () =>
(dispatch: AppDispatch, getState: () => RootState) => {
if (!isLoggedIn(getState)) return;
const me = getState().me;
dispatch(fetchPinnedStatusesRequest());
return getClient(getState()).accounts.getAccountStatuses(me as string, { pinned: true }).then(response => {
dispatch(importEntities({ statuses: response.items }));
dispatch(fetchPinnedStatusesSuccess(response.items, response.next));
}).catch(error => {
dispatch(fetchPinnedStatusesFail(error));
});
};
const fetchPinnedStatusesRequest = () => ({
type: PINNED_STATUSES_FETCH_REQUEST,
});
const fetchPinnedStatusesSuccess = (statuses: Array<Status>, next: (() => Promise<PaginatedResponse<Status>>) | null) => ({
type: PINNED_STATUSES_FETCH_SUCCESS,
statuses,
next,
});
const fetchPinnedStatusesFail = (error: unknown) => ({
type: PINNED_STATUSES_FETCH_FAIL,
error,
});
type PinStatusesAction =
ReturnType<typeof fetchPinnedStatusesRequest>
| ReturnType<typeof fetchPinnedStatusesSuccess>
| ReturnType<typeof fetchPinnedStatusesFail>;
type PinStatusesAction = ReturnType<typeof fetchPinnedStatusesSuccess>;
export {
PINNED_STATUSES_FETCH_REQUEST,
PINNED_STATUSES_FETCH_SUCCESS,
PINNED_STATUSES_FETCH_FAIL,
fetchPinnedStatuses,
type PinStatusesAction,
};

View file

@ -103,5 +103,4 @@ export {
getPlFeConfig,
fetchPlFeConfig,
loadPlFeConfig,
importPlFeConfig,
};

View file

@ -2,81 +2,21 @@ import { getClient } from '../api';
import { importEntities } from './importer';
import type { Poll } from 'pl-api';
import type { AppDispatch, RootState } from 'pl-fe/store';
const POLL_VOTE_REQUEST = 'POLL_VOTE_REQUEST' as const;
const POLL_VOTE_SUCCESS = 'POLL_VOTE_SUCCESS' as const;
const POLL_VOTE_FAIL = 'POLL_VOTE_FAIL' as const;
const POLL_FETCH_REQUEST = 'POLL_FETCH_REQUEST' as const;
const POLL_FETCH_SUCCESS = 'POLL_FETCH_SUCCESS' as const;
const POLL_FETCH_FAIL = 'POLL_FETCH_FAIL' as const;
const vote = (pollId: string, choices: number[]) =>
(dispatch: AppDispatch, getState: () => RootState) => {
dispatch(voteRequest());
return getClient(getState()).polls.vote(pollId, choices).then((data) => {
(dispatch: AppDispatch, getState: () => RootState) =>
getClient(getState()).polls.vote(pollId, choices).then((data) => {
dispatch(importEntities({ polls: [data] }));
dispatch(voteSuccess(data));
}).catch(err => dispatch(voteFail(err)));
};
});
const fetchPoll = (pollId: string) =>
(dispatch: AppDispatch, getState: () => RootState) => {
dispatch(fetchPollRequest());
return getClient(getState()).polls.getPoll(pollId).then((data) => {
(dispatch: AppDispatch, getState: () => RootState) =>
getClient(getState()).polls.getPoll(pollId).then((data) => {
dispatch(importEntities({ polls: [data] }));
dispatch(fetchPollSuccess(data));
}).catch(err => dispatch(fetchPollFail(err)));
};
const voteRequest = () => ({
type: POLL_VOTE_REQUEST,
});
const voteSuccess = (poll: Poll) => ({
type: POLL_VOTE_SUCCESS,
poll,
});
const voteFail = (error: unknown) => ({
type: POLL_VOTE_FAIL,
error,
});
const fetchPollRequest = () => ({
type: POLL_FETCH_REQUEST,
});
const fetchPollSuccess = (poll: Poll) => ({
type: POLL_FETCH_SUCCESS,
poll,
});
const fetchPollFail = (error: unknown) => ({
type: POLL_FETCH_FAIL,
error,
});
type PollsAction =
| ReturnType<typeof voteRequest>
| ReturnType<typeof voteSuccess>
| ReturnType<typeof voteFail>
| ReturnType<typeof fetchPollRequest>
| ReturnType<typeof fetchPollSuccess>
| ReturnType<typeof fetchPollFail>;
});
export {
POLL_VOTE_REQUEST,
POLL_VOTE_SUCCESS,
POLL_VOTE_FAIL,
POLL_FETCH_REQUEST,
POLL_FETCH_SUCCESS,
POLL_FETCH_FAIL,
vote,
fetchPoll,
type PollsAction,
};