From 32bd7530645747fe8a17bc914a2a8f5ab33a399d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Tue, 26 Nov 2024 13:20:33 +0100 Subject: [PATCH] pl-fe: types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- packages/pl-fe/src/actions/statuses.ts | 49 ++++++++++++++++++-------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/packages/pl-fe/src/actions/statuses.ts b/packages/pl-fe/src/actions/statuses.ts index e90b572a5..5f63737da 100644 --- a/packages/pl-fe/src/actions/statuses.ts +++ b/packages/pl-fe/src/actions/statuses.ts @@ -9,7 +9,7 @@ import { setComposeToStatus } from './compose'; import { importEntities } from './importer'; import { deleteFromTimelines } from './timelines'; -import type { CreateStatusParams, Status as BaseStatus } from 'pl-api'; +import type { CreateStatusParams, Status as BaseStatus, ScheduledStatus, Translation } from 'pl-api'; import type { Status } from 'pl-fe/normalizers/status'; import type { AppDispatch, RootState } from 'pl-fe/store'; import type { IntlShape } from 'react-intl'; @@ -59,7 +59,7 @@ const STATUS_LANGUAGE_CHANGE = 'STATUS_LANGUAGE_CHANGE' as const; const createStatus = (params: CreateStatusParams, idempotencyKey: string, statusId: string | null) => (dispatch: AppDispatch, getState: () => RootState) => { - dispatch({ type: STATUS_CREATE_REQUEST, params, idempotencyKey, editing: !!statusId }); + dispatch({ type: STATUS_CREATE_REQUEST, params, idempotencyKey, editing: !!statusId }); return (statusId === null ? getClient(getState()).statuses.createStatus(params) : getClient(getState()).statuses.editStatus(statusId, params)) .then((status) => { @@ -67,7 +67,7 @@ const createStatus = (params: CreateStatusParams, idempotencyKey: string, status const expectsCard = status.scheduled_at === null && !status.card && shouldHaveCard(status); if (status.scheduled_at === null) dispatch(importEntities({ statuses: [{ ...status, expectsCard }] }, { idempotencyKey, withParents: true })); - dispatch({ type: STATUS_CREATE_SUCCESS, status, params, idempotencyKey, editing: !!statusId }); + dispatch({ type: STATUS_CREATE_SUCCESS, status, params, idempotencyKey, editing: !!statusId }); // Poll the backend for the updated card if (expectsCard) { @@ -88,7 +88,7 @@ const createStatus = (params: CreateStatusParams, idempotencyKey: string, status return status; }).catch(error => { - dispatch({ type: STATUS_CREATE_FAIL, error, params, idempotencyKey, editing: !!statusId }); + dispatch({ type: STATUS_CREATE_FAIL, error, params, idempotencyKey, editing: !!statusId }); throw error; }); }; @@ -188,11 +188,11 @@ const muteStatus = (statusId: string) => (dispatch: AppDispatch, getState: () => RootState) => { if (!isLoggedIn(getState)) return; - dispatch({ type: STATUS_MUTE_REQUEST, statusId }); + dispatch({ type: STATUS_MUTE_REQUEST, statusId }); return getClient(getState()).statuses.muteStatus(statusId).then((status) => { - dispatch({ type: STATUS_MUTE_SUCCESS, statusId }); + dispatch({ type: STATUS_MUTE_SUCCESS, statusId }); }).catch(error => { - dispatch({ type: STATUS_MUTE_FAIL, statusId, error }); + dispatch({ type: STATUS_MUTE_FAIL, statusId, error }); }); }; @@ -200,11 +200,11 @@ const unmuteStatus = (statusId: string) => (dispatch: AppDispatch, getState: () => RootState) => { if (!isLoggedIn(getState)) return; - dispatch({ type: STATUS_UNMUTE_REQUEST, statusId }); + dispatch({ type: STATUS_UNMUTE_REQUEST, statusId }); return getClient(getState()).statuses.unmuteStatus(statusId).then(() => { - dispatch({ type: STATUS_UNMUTE_SUCCESS, statusId }); + dispatch({ type: STATUS_UNMUTE_SUCCESS, statusId }); }).catch(error => { - dispatch({ type: STATUS_UNMUTE_FAIL, statusId, error }); + dispatch({ type: STATUS_UNMUTE_FAIL, statusId, error }); }); }; @@ -277,7 +277,7 @@ const translateStatus = (statusId: string, targetLanguage: string, lazy?: boolea const client = getClient(getState); const features = client.features; - dispatch({ type: STATUS_TRANSLATE_REQUEST, statusId }); + dispatch({ type: STATUS_TRANSLATE_REQUEST, statusId }); const handleTranslateMany = () => { const copy = [...TRANSLATIONS_QUEUE]; @@ -286,7 +286,7 @@ const translateStatus = (statusId: string, targetLanguage: string, lazy?: boolea return client.statuses.translateStatuses(copy, targetLanguage).then((response) => { response.forEach((translation) => { - dispatch({ + dispatch({ type: STATUS_TRANSLATE_SUCCESS, statusId: translation.id, translation: translation, @@ -294,13 +294,13 @@ const translateStatus = (statusId: string, targetLanguage: string, lazy?: boolea copy .filter((statusId) => !response.some(({ id }) => id === statusId)) - .forEach((statusId) => dispatch({ + .forEach((statusId) => dispatch({ type: STATUS_TRANSLATE_FAIL, statusId, })); }); }).catch(error => { - dispatch({ + dispatch({ type: STATUS_TRANSLATE_FAIL, statusId, error, @@ -351,6 +351,27 @@ const changeStatusLanguage = (statusId: string, language: string) => ({ }); type StatusesAction = + | { type: typeof STATUS_CREATE_REQUEST; params: CreateStatusParams; idempotencyKey: string; editing: boolean } + | { type: typeof STATUS_CREATE_SUCCESS; status: BaseStatus | ScheduledStatus; params: CreateStatusParams; idempotencyKey: string; editing: boolean } + | { type: typeof STATUS_CREATE_FAIL; error: unknown; params: CreateStatusParams; idempotencyKey: string; editing: boolean } +// editStatus, +// fetchStatus, +// deleteStatus, +// updateStatus, +// fetchContext, + | { type: typeof STATUS_MUTE_REQUEST; statusId: string } + | { type: typeof STATUS_MUTE_SUCCESS; statusId: string } + | { type: typeof STATUS_MUTE_FAIL; statusId: string; error: unknown } + | { type: typeof STATUS_UNMUTE_REQUEST; statusId: string } + | { type: typeof STATUS_UNMUTE_SUCCESS; statusId: string } + | { type: typeof STATUS_UNMUTE_FAIL; statusId: string; error: unknown } + | ReturnType + | ReturnType + | ReturnType + | ReturnType + | { type: typeof STATUS_TRANSLATE_REQUEST; statusId: string } + | { type: typeof STATUS_TRANSLATE_SUCCESS; statusId: string | null; translation: Translation } + | { type: typeof STATUS_TRANSLATE_FAIL; statusId: string; error?: unknown } | ReturnType | ReturnType | ReturnType;