Handle user override more explicitly
This commit is contained in:
@@ -197,12 +197,28 @@ export const ComposePost = ({
|
|||||||
const [isPublishing, setIsPublishing] = useState(false)
|
const [isPublishing, setIsPublishing] = useState(false)
|
||||||
const [publishingStage, setPublishingStage] = useState('')
|
const [publishingStage, setPublishingStage] = useState('')
|
||||||
const [error, setError] = useState('')
|
const [error, setError] = useState('')
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A temporarly local reference to a language suggestion that the user has
|
||||||
|
* accepted. This overrides the global post language preference, but is not
|
||||||
|
* stored permanently.
|
||||||
|
*/
|
||||||
const [acceptedLanguageSuggestion, setAcceptedLanguageSuggestion] = useState<
|
const [acceptedLanguageSuggestion, setAcceptedLanguageSuggestion] = useState<
|
||||||
string | null
|
string | null
|
||||||
>(null)
|
>(null)
|
||||||
|
|
||||||
// NOTE(@elijaharita): if a temporary language suggestion has been accepted,
|
/**
|
||||||
// show that as the post language instead of the one from langPrefs.
|
* The language of the post being replied to, if any. We just use the first
|
||||||
|
* language available, for now.
|
||||||
|
*/
|
||||||
|
const [replyToLanguage, setReplyToLanguage] = useState<string | undefined>(
|
||||||
|
replyTo?.langs?.[0],
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The currently selected languages of the post. Prefer local temporary
|
||||||
|
* language suggestion over global lang prefs, if available.
|
||||||
|
*/
|
||||||
const currentLanguages = useMemo(
|
const currentLanguages = useMemo(
|
||||||
() =>
|
() =>
|
||||||
acceptedLanguageSuggestion
|
acceptedLanguageSuggestion
|
||||||
@@ -211,11 +227,15 @@ export const ComposePost = ({
|
|||||||
[acceptedLanguageSuggestion, langPrefs.postLanguage],
|
[acceptedLanguageSuggestion, langPrefs.postLanguage],
|
||||||
)
|
)
|
||||||
|
|
||||||
// This effect clears the temporary language suggestion if the post language
|
/**
|
||||||
// is manually changed, so the user doesn't get stuck with the suggestion.
|
* When the user selects a language from the composer language selector,
|
||||||
useEffect(() => {
|
* clear any temporary language suggestions they may have selected
|
||||||
|
* previously, and any we might try to suggest to them.
|
||||||
|
*/
|
||||||
|
const onSelectLanguage = () => {
|
||||||
setAcceptedLanguageSuggestion(null)
|
setAcceptedLanguageSuggestion(null)
|
||||||
}, [langPrefs.postLanguage])
|
setReplyToLanguage(undefined)
|
||||||
|
}
|
||||||
|
|
||||||
const [composerState, composerDispatch] = useReducer(
|
const [composerState, composerDispatch] = useReducer(
|
||||||
composerReducer,
|
composerReducer,
|
||||||
@@ -674,8 +694,7 @@ export const ComposePost = ({
|
|||||||
<>
|
<>
|
||||||
<SuggestedLanguage
|
<SuggestedLanguage
|
||||||
text={activePost.richtext.text}
|
text={activePost.richtext.text}
|
||||||
// Use the first language if any exists
|
replyToLanguage={replyToLanguage}
|
||||||
replyToLanguage={replyTo?.langs?.[0]}
|
|
||||||
currentLanguages={currentLanguages}
|
currentLanguages={currentLanguages}
|
||||||
onAcceptSuggestedLanguage={setAcceptedLanguageSuggestion}
|
onAcceptSuggestedLanguage={setAcceptedLanguageSuggestion}
|
||||||
/>
|
/>
|
||||||
@@ -701,6 +720,7 @@ export const ComposePost = ({
|
|||||||
})
|
})
|
||||||
}}
|
}}
|
||||||
currentLanguages={currentLanguages}
|
currentLanguages={currentLanguages}
|
||||||
|
onSelectLanguage={onSelectLanguage}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
@@ -1313,6 +1333,7 @@ function ComposerFooter({
|
|||||||
onSelectVideo,
|
onSelectVideo,
|
||||||
onAddPost,
|
onAddPost,
|
||||||
currentLanguages,
|
currentLanguages,
|
||||||
|
onSelectLanguage,
|
||||||
}: {
|
}: {
|
||||||
post: PostDraft
|
post: PostDraft
|
||||||
dispatch: (action: PostAction) => void
|
dispatch: (action: PostAction) => void
|
||||||
@@ -1322,6 +1343,7 @@ function ComposerFooter({
|
|||||||
onSelectVideo: (postId: string, asset: ImagePickerAsset) => void
|
onSelectVideo: (postId: string, asset: ImagePickerAsset) => void
|
||||||
onAddPost: () => void
|
onAddPost: () => void
|
||||||
currentLanguages: string[]
|
currentLanguages: string[]
|
||||||
|
onSelectLanguage?: (language: string) => void
|
||||||
}) {
|
}) {
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
@@ -1475,7 +1497,10 @@ function ComposerFooter({
|
|||||||
<PlusIcon size="lg" />
|
<PlusIcon size="lg" />
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
<PostLanguageSelect currentLanguages={currentLanguages} />
|
<PostLanguageSelect
|
||||||
|
currentLanguages={currentLanguages}
|
||||||
|
onSelectLanguage={onSelectLanguage}
|
||||||
|
/>
|
||||||
<CharProgress
|
<CharProgress
|
||||||
count={post.shortenedGraphemeLength}
|
count={post.shortenedGraphemeLength}
|
||||||
style={{width: 65}}
|
style={{width: 65}}
|
||||||
|
|||||||
@@ -19,8 +19,10 @@ import {PostLanguageSelectDialog} from './PostLanguageSelectDialog'
|
|||||||
|
|
||||||
export function PostLanguageSelect({
|
export function PostLanguageSelect({
|
||||||
currentLanguages: currentLanguagesProp,
|
currentLanguages: currentLanguagesProp,
|
||||||
|
onSelectLanguage,
|
||||||
}: {
|
}: {
|
||||||
currentLanguages?: string[]
|
currentLanguages?: string[]
|
||||||
|
onSelectLanguage?: (language: string) => void
|
||||||
}) {
|
}) {
|
||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
const langPrefs = useLanguagePrefs()
|
const langPrefs = useLanguagePrefs()
|
||||||
@@ -68,7 +70,10 @@ export function PostLanguageSelect({
|
|||||||
<Menu.Item
|
<Menu.Item
|
||||||
key={historyItem}
|
key={historyItem}
|
||||||
label={_(msg`Select ${langName}`)}
|
label={_(msg`Select ${langName}`)}
|
||||||
onPress={() => setLangPrefs.setPostLanguage(historyItem)}>
|
onPress={() => {
|
||||||
|
setLangPrefs.setPostLanguage(historyItem)
|
||||||
|
onSelectLanguage?.(historyItem)
|
||||||
|
}}>
|
||||||
<Menu.ItemText>{langName}</Menu.ItemText>
|
<Menu.ItemText>{langName}</Menu.ItemText>
|
||||||
<Menu.ItemRadio
|
<Menu.ItemRadio
|
||||||
selected={currentLanguages.includes(historyItem)}
|
selected={currentLanguages.includes(historyItem)}
|
||||||
|
|||||||
Reference in New Issue
Block a user