feat: use OP's language as recommendation when replying (#8832)

* feat: use OP's language as recommendation when replying

* fix: address nits
This commit is contained in:
Elijah Seed-Arita
2025-08-15 06:16:13 -07:00
committed by GitHub
parent 4e0be91cff
commit 5ca665467e
12 changed files with 31 additions and 4 deletions
@@ -254,6 +254,7 @@ const ThreadItemAnchorInner = memo(function ThreadItemAnchorInner({
author: post.author, author: post.author,
embed: post.embed, embed: post.embed,
moderation, moderation,
langs: record.langs,
}, },
onPostSuccess: onPostSuccess, onPostSuccess: onPostSuccess,
}) })
@@ -234,6 +234,7 @@ const ThreadItemPostInner = memo(function ThreadItemPostInner({
author: post.author, author: post.author,
embed: post.embed, embed: post.embed,
moderation, moderation,
langs: post.record.langs,
}, },
onPostSuccess: onPostSuccess, onPostSuccess: onPostSuccess,
}) })
@@ -298,6 +298,7 @@ const ThreadItemTreePostInner = memo(function ThreadItemTreePostInner({
author: post.author, author: post.author,
embed: post.embed, embed: post.embed,
moderation, moderation,
langs: post.record.langs,
}, },
onPostSuccess: onPostSuccess, onPostSuccess: onPostSuccess,
}) })
+1
View File
@@ -91,6 +91,7 @@ export function PostThread({uri}: {uri: string}) {
author: post.author, author: post.author,
embed: post.embed, embed: post.embed,
moderation: anchor.moderation, moderation: anchor.moderation,
langs: post.record.langs,
}, },
onPostSuccess: optimisticOnPostReply, onPostSuccess: optimisticOnPostReply,
}) })
+1
View File
@@ -753,6 +753,7 @@ function Overlay({
text: record?.text || '', text: record?.text || '',
author: post.author, author: post.author,
embed: post.embed, embed: post.embed,
langs: record?.langs,
}, },
}) })
}, [openComposer, post, record]) }, [openComposer, post, record])
+1
View File
@@ -20,6 +20,7 @@ export interface ComposerOptsPostRef {
uri: string uri: string
cid: string cid: string
text: string text: string
langs?: string[]
author: AppBskyActorDefs.ProfileViewBasic author: AppBskyActorDefs.ProfileViewBasic
embed?: AppBskyFeedDefs.PostView['embed'] embed?: AppBskyFeedDefs.PostView['embed']
moderation?: ModerationDecision moderation?: ModerationDecision
+5 -1
View File
@@ -621,7 +621,11 @@ export const ComposePost = ({
const footer = ( const footer = (
<> <>
<SuggestedLanguage text={activePost.richtext.text} /> <SuggestedLanguage
text={activePost.richtext.text}
// NOTE(@elijaharita): currently just choosing the first language if any exists
replyToLanguage={replyTo?.langs?.[0]}
/>
<ComposerPills <ComposerPills
isReply={!!replyTo} isReply={!!replyTo}
post={activePost} post={activePost}
@@ -19,16 +19,29 @@ import {Text} from '#/components/Typography'
const onIdle = globalThis.requestIdleCallback || (cb => setTimeout(cb, 1)) const onIdle = globalThis.requestIdleCallback || (cb => setTimeout(cb, 1))
const cancelIdle = globalThis.cancelIdleCallback || clearTimeout const cancelIdle = globalThis.cancelIdleCallback || clearTimeout
export function SuggestedLanguage({text}: {text: string}) { export function SuggestedLanguage({
text,
replyToLanguage,
}: {
text: string
replyToLanguage?: string
}) {
const [suggestedLanguage, setSuggestedLanguage] = useState< const [suggestedLanguage, setSuggestedLanguage] = useState<
string | undefined string | undefined
>() >(text.length === 0 ? replyToLanguage : undefined)
const langPrefs = useLanguagePrefs() const langPrefs = useLanguagePrefs()
const setLangPrefs = useLanguagePrefsApi() const setLangPrefs = useLanguagePrefsApi()
const t = useTheme() const t = useTheme()
const {_} = useLingui() const {_} = useLingui()
useEffect(() => { useEffect(() => {
// For replies, suggest the language of the post being replied to if no text
// has been typed yet
if (replyToLanguage && text.length === 0) {
setSuggestedLanguage(replyToLanguage)
return
}
const textTrimmed = text.trim() const textTrimmed = text.trim()
// Don't run the language model on small posts, the results are likely // Don't run the language model on small posts, the results are likely
@@ -43,7 +56,7 @@ export function SuggestedLanguage({text}: {text: string}) {
}) })
return () => cancelIdle(idle) return () => cancelIdle(idle)
}, [text]) }, [text, replyToLanguage])
if ( if (
suggestedLanguage && suggestedLanguage &&
+1
View File
@@ -420,6 +420,7 @@ export function PostThread({uri}: {uri: string}) {
author: thread.post.author, author: thread.post.author,
embed: thread.post.embed, embed: thread.post.embed,
moderation: threadModerationCache.get(thread), moderation: threadModerationCache.get(thread),
langs: thread.record.langs,
}, },
onPost: onPostReply, onPost: onPostReply,
}) })
@@ -299,6 +299,7 @@ let PostThreadItemLoaded = ({
author: post.author, author: post.author,
embed: post.embed, embed: post.embed,
moderation, moderation,
langs: record.langs,
}, },
onPost: onPostReply, onPost: onPostReply,
onPostSuccess: onPostSuccess, onPostSuccess: onPostSuccess,
+1
View File
@@ -131,6 +131,7 @@ function PostInner({
author: post.author, author: post.author,
embed: post.embed, embed: post.embed,
moderation, moderation,
langs: record.langs,
}, },
}) })
}, [openComposer, post, record, moderation]) }, [openComposer, post, record, moderation])
+1
View File
@@ -193,6 +193,7 @@ let FeedItemInner = ({
author: post.author, author: post.author,
embed: post.embed, embed: post.embed,
moderation, moderation,
langs: record.langs,
}, },
}) })
} }