diff --git a/packages/pl-fe/src/actions/compose.ts b/packages/pl-fe/src/actions/compose.ts index 3d8fb8fed..ca0fdf661 100644 --- a/packages/pl-fe/src/actions/compose.ts +++ b/packages/pl-fe/src/actions/compose.ts @@ -13,10 +13,9 @@ import { useSettingsStore } from 'pl-fe/stores/settings'; import toast from 'pl-fe/toast'; import { isLoggedIn } from 'pl-fe/utils/auth'; -import { chooseEmoji } from './emojis'; import { importEntities } from './importer'; -import { rememberLanguageUse } from './languages'; import { uploadFile, updateMedia } from './media'; +import { saveSettings } from './settings'; import { createStatus } from './statuses'; import type { EditorState } from 'lexical'; @@ -384,7 +383,8 @@ const submitCompose = (composeId: string, opts: SubmitComposeOpts = {}) => useModalsStore.getState().closeModal('COMPOSE'); if (compose.language && !statusId) { - dispatch(rememberLanguageUse(compose.language)); + useSettingsStore.getState().rememberLanguageUse(compose.language); + dispatch(saveSettings()); } const idempotencyKey = compose.idempotencyKey; @@ -686,7 +686,8 @@ const selectComposeSuggestion = (composeId: string, position: number, token: str completion = isNativeEmoji(suggestion) ? suggestion.native : suggestion.colons; startPosition = position - 1; - dispatch(chooseEmoji(suggestion)); + useSettingsStore.getState().rememberEmojiUse(suggestion); + dispatch(saveSettings()); } else if (typeof suggestion === 'string' && suggestion[0] === '#') { completion = suggestion; startPosition = position - 1; diff --git a/packages/pl-fe/src/actions/emojis.ts b/packages/pl-fe/src/actions/emojis.ts deleted file mode 100644 index b4b949314..000000000 --- a/packages/pl-fe/src/actions/emojis.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { saveSettings } from './settings'; - -import type { Emoji } from 'pl-fe/features/emoji'; -import type { AppDispatch } from 'pl-fe/store'; - -const EMOJI_CHOOSE = 'EMOJI_CHOOSE'; - -const chooseEmoji = (emoji: Emoji) => - (dispatch: AppDispatch) => { - dispatch({ - type: EMOJI_CHOOSE, - emoji, - }); - - dispatch(saveSettings()); - }; - -export { - EMOJI_CHOOSE, - chooseEmoji, -}; diff --git a/packages/pl-fe/src/actions/languages.ts b/packages/pl-fe/src/actions/languages.ts deleted file mode 100644 index fe26a5345..000000000 --- a/packages/pl-fe/src/actions/languages.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { saveSettings } from './settings'; - -import type { AppDispatch } from 'pl-fe/store'; - -const LANGUAGE_USE = 'LANGUAGE_USE' as const; - -const rememberLanguageUse = (language: string) => (dispatch: AppDispatch) => { - dispatch({ - type: LANGUAGE_USE, - language, - }); - - dispatch(saveSettings()); -}; - -export { LANGUAGE_USE, rememberLanguageUse }; diff --git a/packages/pl-fe/src/features/compose/editor/plugins/autosuggest-plugin.tsx b/packages/pl-fe/src/features/compose/editor/plugins/autosuggest-plugin.tsx index ee270402a..1784eb7ae 100644 --- a/packages/pl-fe/src/features/compose/editor/plugins/autosuggest-plugin.tsx +++ b/packages/pl-fe/src/features/compose/editor/plugins/autosuggest-plugin.tsx @@ -33,11 +33,12 @@ import React, { import ReactDOM from 'react-dom'; import { clearComposeSuggestions, fetchComposeSuggestions } from 'pl-fe/actions/compose'; -import { chooseEmoji } from 'pl-fe/actions/emojis'; +import { saveSettings } from 'pl-fe/actions/settings'; import AutosuggestEmoji from 'pl-fe/components/autosuggest-emoji'; import { useAppDispatch } from 'pl-fe/hooks/use-app-dispatch'; import { useCompose } from 'pl-fe/hooks/use-compose'; import { selectAccount } from 'pl-fe/selectors'; +import { useSettingsStore } from 'pl-fe/stores/settings'; import { textAtCursorMatchesToken } from 'pl-fe/utils/suggestions'; import AutosuggestAccount from '../../components/autosuggest-account'; @@ -285,6 +286,7 @@ const AutosuggestPlugin = ({ suggestionsHidden, setSuggestionsHidden, }: AutosuggestPluginProps): JSX.Element | null => { + const { rememberEmojiUse } = useSettingsStore(); const { suggestions } = useCompose(composeId); const dispatch = useAppDispatch(); @@ -324,7 +326,10 @@ const AutosuggestPlugin = ({ if (typeof suggestion === 'object') { if (!suggestion.id) return; - dispatch(chooseEmoji(suggestion)); + + rememberEmojiUse(suggestion); + dispatch(saveSettings()); + replaceMatch($createEmojiNode(suggestion)); } else if (suggestion[0] === '#') { (node as TextNode).setTextContent(`${suggestion} `); diff --git a/packages/pl-fe/src/features/emoji/components/emoji-picker-dropdown.tsx b/packages/pl-fe/src/features/emoji/components/emoji-picker-dropdown.tsx index a43f076ef..3209af4e5 100644 --- a/packages/pl-fe/src/features/emoji/components/emoji-picker-dropdown.tsx +++ b/packages/pl-fe/src/features/emoji/components/emoji-picker-dropdown.tsx @@ -2,13 +2,13 @@ import React, { useEffect, useState, useLayoutEffect, Suspense, useMemo } from ' import { defineMessages, useIntl } from 'react-intl'; import { createSelector } from 'reselect'; -import { chooseEmoji } from 'pl-fe/actions/emojis'; -import { changeSetting } from 'pl-fe/actions/settings'; +import { changeSetting, saveSettings } from 'pl-fe/actions/settings'; import { useAppDispatch } from 'pl-fe/hooks/use-app-dispatch'; import { useAppSelector } from 'pl-fe/hooks/use-app-selector'; import { useSettings } from 'pl-fe/hooks/use-settings'; import { useTheme } from 'pl-fe/hooks/use-theme'; import { RootState } from 'pl-fe/store'; +import { useSettingsStore } from 'pl-fe/stores/settings'; import { buildCustomEmojis } from '../../emoji'; import { EmojiPicker } from '../../ui/util/async-components'; @@ -128,6 +128,7 @@ const EmojiPickerDropdown: React.FC = ({ const dispatch = useAppDispatch(); const title = intl.formatMessage(messages.emoji); const theme = useTheme(); + const { rememberEmojiUse } = useSettingsStore(); const customEmojis = useAppSelector((state) => getCustomEmojis(state)); @@ -156,7 +157,8 @@ const EmojiPickerDropdown: React.FC = ({ } as CustomEmoji; } - dispatch(chooseEmoji(pickedEmoji)); + rememberEmojiUse(pickedEmoji); + dispatch(saveSettings()); if (onPickEmoji) { onPickEmoji(pickedEmoji);