From 5ca665467e9cbedd78f21df76db8cfde8eaa66b4 Mon Sep 17 00:00:00 2001
From: Elijah Seed-Arita <elijaharita@gmail.com>
Date: Fri, 15 Aug 2025 06:16:13 -0700
Subject: feat: use OP's language as recommendation when replying (#8832)

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

* fix: address nits
---
 .../composer/select-language/SuggestedLanguage.tsx    | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

(limited to 'src/view/com/composer/select-language/SuggestedLanguage.tsx')

diff --git a/src/view/com/composer/select-language/SuggestedLanguage.tsx b/src/view/com/composer/select-language/SuggestedLanguage.tsx
index 1e0948899..48e2187b8 100644
--- a/src/view/com/composer/select-language/SuggestedLanguage.tsx
+++ b/src/view/com/composer/select-language/SuggestedLanguage.tsx
@@ -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 &&
-- 
cgit 1.4.1

