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:
committed by
GitHub
parent
4e0be91cff
commit
5ca665467e
@@ -254,6 +254,7 @@ const ThreadItemAnchorInner = memo(function ThreadItemAnchorInner({
|
||||
author: post.author,
|
||||
embed: post.embed,
|
||||
moderation,
|
||||
langs: record.langs,
|
||||
},
|
||||
onPostSuccess: onPostSuccess,
|
||||
})
|
||||
|
||||
@@ -234,6 +234,7 @@ const ThreadItemPostInner = memo(function ThreadItemPostInner({
|
||||
author: post.author,
|
||||
embed: post.embed,
|
||||
moderation,
|
||||
langs: post.record.langs,
|
||||
},
|
||||
onPostSuccess: onPostSuccess,
|
||||
})
|
||||
|
||||
@@ -298,6 +298,7 @@ const ThreadItemTreePostInner = memo(function ThreadItemTreePostInner({
|
||||
author: post.author,
|
||||
embed: post.embed,
|
||||
moderation,
|
||||
langs: post.record.langs,
|
||||
},
|
||||
onPostSuccess: onPostSuccess,
|
||||
})
|
||||
|
||||
@@ -91,6 +91,7 @@ export function PostThread({uri}: {uri: string}) {
|
||||
author: post.author,
|
||||
embed: post.embed,
|
||||
moderation: anchor.moderation,
|
||||
langs: post.record.langs,
|
||||
},
|
||||
onPostSuccess: optimisticOnPostReply,
|
||||
})
|
||||
|
||||
@@ -753,6 +753,7 @@ function Overlay({
|
||||
text: record?.text || '',
|
||||
author: post.author,
|
||||
embed: post.embed,
|
||||
langs: record?.langs,
|
||||
},
|
||||
})
|
||||
}, [openComposer, post, record])
|
||||
|
||||
@@ -20,6 +20,7 @@ export interface ComposerOptsPostRef {
|
||||
uri: string
|
||||
cid: string
|
||||
text: string
|
||||
langs?: string[]
|
||||
author: AppBskyActorDefs.ProfileViewBasic
|
||||
embed?: AppBskyFeedDefs.PostView['embed']
|
||||
moderation?: ModerationDecision
|
||||
|
||||
@@ -621,7 +621,11 @@ export const ComposePost = ({
|
||||
|
||||
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
|
||||
isReply={!!replyTo}
|
||||
post={activePost}
|
||||
|
||||
@@ -19,16 +19,29 @@ import {Text} from '#/components/Typography'
|
||||
const onIdle = globalThis.requestIdleCallback || (cb => setTimeout(cb, 1))
|
||||
const cancelIdle = globalThis.cancelIdleCallback || clearTimeout
|
||||
|
||||
export function SuggestedLanguage({text}: {text: string}) {
|
||||
export function SuggestedLanguage({
|
||||
text,
|
||||
replyToLanguage,
|
||||
}: {
|
||||
text: string
|
||||
replyToLanguage?: string
|
||||
}) {
|
||||
const [suggestedLanguage, setSuggestedLanguage] = useState<
|
||||
string | undefined
|
||||
>()
|
||||
>(text.length === 0 ? replyToLanguage : undefined)
|
||||
const langPrefs = useLanguagePrefs()
|
||||
const setLangPrefs = useLanguagePrefsApi()
|
||||
const t = useTheme()
|
||||
const {_} = useLingui()
|
||||
|
||||
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()
|
||||
|
||||
// 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)
|
||||
}, [text])
|
||||
}, [text, replyToLanguage])
|
||||
|
||||
if (
|
||||
suggestedLanguage &&
|
||||
|
||||
@@ -420,6 +420,7 @@ export function PostThread({uri}: {uri: string}) {
|
||||
author: thread.post.author,
|
||||
embed: thread.post.embed,
|
||||
moderation: threadModerationCache.get(thread),
|
||||
langs: thread.record.langs,
|
||||
},
|
||||
onPost: onPostReply,
|
||||
})
|
||||
|
||||
@@ -299,6 +299,7 @@ let PostThreadItemLoaded = ({
|
||||
author: post.author,
|
||||
embed: post.embed,
|
||||
moderation,
|
||||
langs: record.langs,
|
||||
},
|
||||
onPost: onPostReply,
|
||||
onPostSuccess: onPostSuccess,
|
||||
|
||||
@@ -131,6 +131,7 @@ function PostInner({
|
||||
author: post.author,
|
||||
embed: post.embed,
|
||||
moderation,
|
||||
langs: record.langs,
|
||||
},
|
||||
})
|
||||
}, [openComposer, post, record, moderation])
|
||||
|
||||
@@ -193,6 +193,7 @@ let FeedItemInner = ({
|
||||
author: post.author,
|
||||
embed: post.embed,
|
||||
moderation,
|
||||
langs: record.langs,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user