From 3e7b7e824fce31f8cda9bd2c6aa7bdcc2f64cf2e Mon Sep 17 00:00:00 2001 From: lemon Date: Sat, 23 May 2026 22:40:50 -0700 Subject: [PATCH] fix: move note translation action --- src/components/NoteCard.tsx | 45 ++++++++++++++++-------------- src/components/TranslateButton.tsx | 20 +++++++++---- 2 files changed, 39 insertions(+), 26 deletions(-) diff --git a/src/components/NoteCard.tsx b/src/components/NoteCard.tsx index fbdef663..2ef0ef55 100644 --- a/src/components/NoteCard.tsx +++ b/src/components/NoteCard.tsx @@ -409,6 +409,7 @@ export const NoteCard = memo(function NoteCard({ const { data: btcPrice } = useBtcPrice(); const [moreMenuOpen, setMoreMenuOpen] = useState(false); const [replyOpen, setReplyOpen] = useState(false); + const [translatedContent, setTranslatedContent] = useState(null); // Check if the current user can zap this event's author // TODO: Enable zapping split-recipient NIP-75 goals once zap split payments are supported. @@ -540,6 +541,12 @@ export const NoteCard = memo(function NoteCard({ const isComment = event.kind === 1111; const isReply = isTextNote && !isComment && isReplyEvent(event); + const canTranslate = isTextNote && event.content.trim().length > 0; + const contentEvent = translatedContent ? { ...event, content: translatedContent } : event; + + useEffect(() => { + setTranslatedContent(null); + }, [event.id]); // Find all people being replied to (for "Replying to @user1 and @user2") const replyToPubkeys = useMemo(() => { @@ -743,7 +750,7 @@ export const NoteCard = memo(function NoteCard({ ) : ( )} @@ -878,6 +885,17 @@ export const NoteCard = memo(function NoteCard({
+ {canTranslate && ( + setTranslatedContent(null)} + responsiveLabel + className="h-9 px-3 text-sm font-medium" + /> + )} + - )} - {canTranslate && ( - setTranslatedContent(null)} - /> - )} -
+ + )} ); } diff --git a/src/components/TranslateButton.tsx b/src/components/TranslateButton.tsx index 1c73b03a..58ecc97d 100644 --- a/src/components/TranslateButton.tsx +++ b/src/components/TranslateButton.tsx @@ -32,6 +32,8 @@ interface TranslateButtonProps { onReset: () => void; /** Whether translated content is currently visible. */ isTranslated: boolean; + /** Hide label on narrow screens so the action row can collapse to an icon. */ + responsiveLabel?: boolean; className?: string; } @@ -40,6 +42,7 @@ export function TranslateButton({ onTranslated, onReset, isTranslated, + responsiveLabel, className, }: TranslateButtonProps) { const { t, i18n } = useTranslation(); @@ -98,8 +101,15 @@ export function TranslateButton({ void handleClick(); }} disabled={loading || !text.trim()} + aria-label={ + error + ? t("translate.error") + : isTranslated + ? t("translate.showOriginal") + : t("translate.translate") + } className={cn( - "h-7 gap-1.5 px-2 text-xs transition-colors", + "h-7 gap-1.5 rounded-full px-2 text-xs transition-colors", isTranslated || error ? "text-primary hover:text-primary/80" : "text-muted-foreground hover:text-primary", @@ -114,13 +124,13 @@ export function TranslateButton({ } > {loading ? ( - + ) : isTranslated ? ( - + ) : ( - + )} - + {loading ? t("translate.translating") : error