fix remember language/emoji use
Signed-off-by: mkljczk <git@mkljczk.pl>
This commit is contained in:
parent
7a85ef413b
commit
edf831bed9
5 changed files with 17 additions and 46 deletions
|
@ -13,10 +13,9 @@ import { useSettingsStore } from 'pl-fe/stores/settings';
|
||||||
import toast from 'pl-fe/toast';
|
import toast from 'pl-fe/toast';
|
||||||
import { isLoggedIn } from 'pl-fe/utils/auth';
|
import { isLoggedIn } from 'pl-fe/utils/auth';
|
||||||
|
|
||||||
import { chooseEmoji } from './emojis';
|
|
||||||
import { importEntities } from './importer';
|
import { importEntities } from './importer';
|
||||||
import { rememberLanguageUse } from './languages';
|
|
||||||
import { uploadFile, updateMedia } from './media';
|
import { uploadFile, updateMedia } from './media';
|
||||||
|
import { saveSettings } from './settings';
|
||||||
import { createStatus } from './statuses';
|
import { createStatus } from './statuses';
|
||||||
|
|
||||||
import type { EditorState } from 'lexical';
|
import type { EditorState } from 'lexical';
|
||||||
|
@ -384,7 +383,8 @@ const submitCompose = (composeId: string, opts: SubmitComposeOpts = {}) =>
|
||||||
useModalsStore.getState().closeModal('COMPOSE');
|
useModalsStore.getState().closeModal('COMPOSE');
|
||||||
|
|
||||||
if (compose.language && !statusId) {
|
if (compose.language && !statusId) {
|
||||||
dispatch(rememberLanguageUse(compose.language));
|
useSettingsStore.getState().rememberLanguageUse(compose.language);
|
||||||
|
dispatch(saveSettings());
|
||||||
}
|
}
|
||||||
|
|
||||||
const idempotencyKey = compose.idempotencyKey;
|
const idempotencyKey = compose.idempotencyKey;
|
||||||
|
@ -686,7 +686,8 @@ const selectComposeSuggestion = (composeId: string, position: number, token: str
|
||||||
completion = isNativeEmoji(suggestion) ? suggestion.native : suggestion.colons;
|
completion = isNativeEmoji(suggestion) ? suggestion.native : suggestion.colons;
|
||||||
startPosition = position - 1;
|
startPosition = position - 1;
|
||||||
|
|
||||||
dispatch(chooseEmoji(suggestion));
|
useSettingsStore.getState().rememberEmojiUse(suggestion);
|
||||||
|
dispatch(saveSettings());
|
||||||
} else if (typeof suggestion === 'string' && suggestion[0] === '#') {
|
} else if (typeof suggestion === 'string' && suggestion[0] === '#') {
|
||||||
completion = suggestion;
|
completion = suggestion;
|
||||||
startPosition = position - 1;
|
startPosition = position - 1;
|
||||||
|
|
|
@ -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,
|
|
||||||
};
|
|
|
@ -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 };
|
|
|
@ -33,11 +33,12 @@ import React, {
|
||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom';
|
||||||
|
|
||||||
import { clearComposeSuggestions, fetchComposeSuggestions } from 'pl-fe/actions/compose';
|
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 AutosuggestEmoji from 'pl-fe/components/autosuggest-emoji';
|
||||||
import { useAppDispatch } from 'pl-fe/hooks/use-app-dispatch';
|
import { useAppDispatch } from 'pl-fe/hooks/use-app-dispatch';
|
||||||
import { useCompose } from 'pl-fe/hooks/use-compose';
|
import { useCompose } from 'pl-fe/hooks/use-compose';
|
||||||
import { selectAccount } from 'pl-fe/selectors';
|
import { selectAccount } from 'pl-fe/selectors';
|
||||||
|
import { useSettingsStore } from 'pl-fe/stores/settings';
|
||||||
import { textAtCursorMatchesToken } from 'pl-fe/utils/suggestions';
|
import { textAtCursorMatchesToken } from 'pl-fe/utils/suggestions';
|
||||||
|
|
||||||
import AutosuggestAccount from '../../components/autosuggest-account';
|
import AutosuggestAccount from '../../components/autosuggest-account';
|
||||||
|
@ -285,6 +286,7 @@ const AutosuggestPlugin = ({
|
||||||
suggestionsHidden,
|
suggestionsHidden,
|
||||||
setSuggestionsHidden,
|
setSuggestionsHidden,
|
||||||
}: AutosuggestPluginProps): JSX.Element | null => {
|
}: AutosuggestPluginProps): JSX.Element | null => {
|
||||||
|
const { rememberEmojiUse } = useSettingsStore();
|
||||||
const { suggestions } = useCompose(composeId);
|
const { suggestions } = useCompose(composeId);
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
|
|
||||||
|
@ -324,7 +326,10 @@ const AutosuggestPlugin = ({
|
||||||
|
|
||||||
if (typeof suggestion === 'object') {
|
if (typeof suggestion === 'object') {
|
||||||
if (!suggestion.id) return;
|
if (!suggestion.id) return;
|
||||||
dispatch(chooseEmoji(suggestion));
|
|
||||||
|
rememberEmojiUse(suggestion);
|
||||||
|
dispatch(saveSettings());
|
||||||
|
|
||||||
replaceMatch($createEmojiNode(suggestion));
|
replaceMatch($createEmojiNode(suggestion));
|
||||||
} else if (suggestion[0] === '#') {
|
} else if (suggestion[0] === '#') {
|
||||||
(node as TextNode).setTextContent(`${suggestion} `);
|
(node as TextNode).setTextContent(`${suggestion} `);
|
||||||
|
|
|
@ -2,13 +2,13 @@ import React, { useEffect, useState, useLayoutEffect, Suspense, useMemo } from '
|
||||||
import { defineMessages, useIntl } from 'react-intl';
|
import { defineMessages, useIntl } from 'react-intl';
|
||||||
import { createSelector } from 'reselect';
|
import { createSelector } from 'reselect';
|
||||||
|
|
||||||
import { chooseEmoji } from 'pl-fe/actions/emojis';
|
import { changeSetting, saveSettings } from 'pl-fe/actions/settings';
|
||||||
import { changeSetting } from 'pl-fe/actions/settings';
|
|
||||||
import { useAppDispatch } from 'pl-fe/hooks/use-app-dispatch';
|
import { useAppDispatch } from 'pl-fe/hooks/use-app-dispatch';
|
||||||
import { useAppSelector } from 'pl-fe/hooks/use-app-selector';
|
import { useAppSelector } from 'pl-fe/hooks/use-app-selector';
|
||||||
import { useSettings } from 'pl-fe/hooks/use-settings';
|
import { useSettings } from 'pl-fe/hooks/use-settings';
|
||||||
import { useTheme } from 'pl-fe/hooks/use-theme';
|
import { useTheme } from 'pl-fe/hooks/use-theme';
|
||||||
import { RootState } from 'pl-fe/store';
|
import { RootState } from 'pl-fe/store';
|
||||||
|
import { useSettingsStore } from 'pl-fe/stores/settings';
|
||||||
|
|
||||||
import { buildCustomEmojis } from '../../emoji';
|
import { buildCustomEmojis } from '../../emoji';
|
||||||
import { EmojiPicker } from '../../ui/util/async-components';
|
import { EmojiPicker } from '../../ui/util/async-components';
|
||||||
|
@ -128,6 +128,7 @@ const EmojiPickerDropdown: React.FC<IEmojiPickerDropdown> = ({
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const title = intl.formatMessage(messages.emoji);
|
const title = intl.formatMessage(messages.emoji);
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
const { rememberEmojiUse } = useSettingsStore();
|
||||||
|
|
||||||
const customEmojis = useAppSelector((state) => getCustomEmojis(state));
|
const customEmojis = useAppSelector((state) => getCustomEmojis(state));
|
||||||
|
|
||||||
|
@ -156,7 +157,8 @@ const EmojiPickerDropdown: React.FC<IEmojiPickerDropdown> = ({
|
||||||
} as CustomEmoji;
|
} as CustomEmoji;
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch(chooseEmoji(pickedEmoji));
|
rememberEmojiUse(pickedEmoji);
|
||||||
|
dispatch(saveSettings());
|
||||||
|
|
||||||
if (onPickEmoji) {
|
if (onPickEmoji) {
|
||||||
onPickEmoji(pickedEmoji);
|
onPickEmoji(pickedEmoji);
|
||||||
|
|
Loading…
Reference in a new issue