diff --git a/packages/pl-fe/src/actions/statuses.ts b/packages/pl-fe/src/actions/statuses.ts index 3df9c6c90..a5b45533c 100644 --- a/packages/pl-fe/src/actions/statuses.ts +++ b/packages/pl-fe/src/actions/statuses.ts @@ -44,8 +44,6 @@ const STATUS_UNMUTE_FAIL = 'STATUS_UNMUTE_FAIL' as const; const STATUS_UNFILTER = 'STATUS_UNFILTER' as const; -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 }); @@ -260,12 +258,6 @@ const unfilterStatus = (statusId: string) => ({ statusId, }); -const changeStatusLanguage = (statusId: string, language: string) => ({ - type: STATUS_LANGUAGE_CHANGE, - statusId, - language, -}); - 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 } @@ -289,7 +281,6 @@ type StatusesAction = | { type: typeof STATUS_UNMUTE_SUCCESS; statusId: string } | { type: typeof STATUS_UNMUTE_FAIL; statusId: string; error: unknown } | ReturnType - | ReturnType; export { STATUS_CREATE_REQUEST, @@ -314,7 +305,6 @@ export { STATUS_UNMUTE_SUCCESS, STATUS_UNMUTE_FAIL, STATUS_UNFILTER, - STATUS_LANGUAGE_CHANGE, createStatus, editStatus, fetchStatus, @@ -326,6 +316,5 @@ export { unmuteStatus, toggleMuteStatus, unfilterStatus, - changeStatusLanguage, type StatusesAction, }; diff --git a/packages/pl-fe/src/components/polls/poll.tsx b/packages/pl-fe/src/components/polls/poll.tsx index 72aab6c93..6337c84ab 100644 --- a/packages/pl-fe/src/components/polls/poll.tsx +++ b/packages/pl-fe/src/components/polls/poll.tsx @@ -17,14 +17,15 @@ type Selected = Record; interface IPoll { id: string; - status?: Pick; + status?: Pick; + language?: string; } const messages = defineMessages({ multiple: { id: 'poll.choose_multiple', defaultMessage: 'Choose as many as you\'d like.' }, }); -const Poll: React.FC = ({ id, status }): JSX.Element | null => { +const Poll: React.FC = ({ id, status, language }): JSX.Element | null => { const { openModal } = useModalsStore(); const dispatch = useAppDispatch(); const intl = useIntl(); @@ -87,7 +88,7 @@ const Poll: React.FC = ({ id, status }): JSX.Element | null => { showResults={showResults} active={!!selected[i]} onToggle={toggleOption} - language={status?.currentLanguage} + language={language} /> ))} diff --git a/packages/pl-fe/src/components/status-content.tsx b/packages/pl-fe/src/components/status-content.tsx index 0bdf368d7..966889c42 100644 --- a/packages/pl-fe/src/components/status-content.tsx +++ b/packages/pl-fe/src/components/status-content.tsx @@ -130,10 +130,10 @@ const StatusContent: React.FC = React.memo(({ const content = useMemo( (): string => translation ? translation.content - : (status.content_map && status.currentLanguage) - ? (status.content_map[status.currentLanguage] || status.content) + : (status.content_map && statusMeta.currentLanguage) + ? (status.content_map[statusMeta.currentLanguage] || status.content) : status.content, - [status.content, translation, status.currentLanguage], + [status.content, translation, statusMeta.currentLanguage], ); const { content: parsedContent, hashtags } = useMemo(() => parseContent({ @@ -149,8 +149,8 @@ const StatusContent: React.FC = React.memo(({ const withSpoiler = status.spoiler_text.length > 0; - const spoilerText = status.spoiler_text_map && status.currentLanguage - ? status.spoiler_text_map[status.currentLanguage] || status.spoiler_text + const spoilerText = status.spoiler_text_map && statusMeta.currentLanguage + ? status.spoiler_text_map[statusMeta.currentLanguage] || status.spoiler_text : status.spoiler_text; const direction = getTextDirection(status.search_index); @@ -245,7 +245,7 @@ const StatusContent: React.FC = React.memo(({ } if (status.poll_id) { - output.push(); + output.push(); } if (translatable) { @@ -283,7 +283,7 @@ const StatusContent: React.FC = React.memo(({ } if (status.poll_id) { - output.push(); + output.push(); } if (translatable) { diff --git a/packages/pl-fe/src/components/status-language-picker.tsx b/packages/pl-fe/src/components/status-language-picker.tsx index 12af6318b..9db6409cc 100644 --- a/packages/pl-fe/src/components/status-language-picker.tsx +++ b/packages/pl-fe/src/components/status-language-picker.tsx @@ -1,12 +1,11 @@ import React from 'react'; import { defineMessages, useIntl } from 'react-intl'; -import { changeStatusLanguage } from 'pl-fe/actions/statuses'; import HStack from 'pl-fe/components/ui/hstack'; import Icon from 'pl-fe/components/ui/icon'; import Text from 'pl-fe/components/ui/text'; import { type Language, languages } from 'pl-fe/features/preferences'; -import { useAppDispatch } from 'pl-fe/hooks/use-app-dispatch'; +import { useStatusMetaStore } from 'pl-fe/stores/status-meta'; import DropdownMenu from './dropdown-menu'; @@ -17,13 +16,16 @@ const messages = defineMessages({ }); interface IStatusLanguagePicker { - status: Pick; + status: Pick; showLabel?: boolean; } const StatusLanguagePicker: React.FC = ({ status, showLabel }) => { const intl = useIntl(); - const dispatch = useAppDispatch(); + + const { statuses, setStatusLanguage } = useStatusMetaStore(); + + const { currentLanguage } = statuses[status.id] || {}; if (!status.content_map || Object.keys(status.content_map).length < 2) return null; @@ -36,8 +38,8 @@ const StatusLanguagePicker: React.FC = ({ status, showLab ({ text: languages[language as Language] || language, - action: () => dispatch(changeStatusLanguage(status.id, language)), - active: language === status.currentLanguage, + action: () => setStatusLanguage(status.id, language), + active: language === currentLanguage, }))} >