diff options
author | Paul Frazee <pfrazee@gmail.com> | 2023-07-06 20:28:10 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-06 20:28:10 -0500 |
commit | e14c9783e0cea73ada1d20e8a798738c39319315 (patch) | |
tree | 41be4e050c1e7cf4ade0e0ff1c66342599618935 /src/view/com/post/Post.tsx | |
parent | f05c2f06d665cb3a9989154fbc82a2b0ea60669a (diff) | |
download | voidsky-e14c9783e0cea73ada1d20e8a798738c39319315.tar.zst |
[APP-735] Post language improvements (#982)
* Fix composer character-counter bouncing around UI elements * Fix composer toolbar padding when keyboard is dismissed on iOS * Use the full name of the language in the composer footer * Add headings to the DropdownButton * Update the composer language control to use a simpler dropdown * Fix lint * Add translate link to Post component used in notifications * Fix lint
Diffstat (limited to 'src/view/com/post/Post.tsx')
-rw-r--r-- | src/view/com/post/Post.tsx | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/src/view/com/post/Post.tsx b/src/view/com/post/Post.tsx index 12ab0e901..c380c9743 100644 --- a/src/view/com/post/Post.tsx +++ b/src/view/com/post/Post.tsx @@ -1,4 +1,4 @@ -import React, {useEffect, useState} from 'react' +import React, {useEffect, useState, useMemo} from 'react' import { ActivityIndicator, Linking, @@ -29,7 +29,7 @@ import {UserAvatar} from '../util/UserAvatar' import {useStores} from 'state/index' import {s, colors} from 'lib/styles' import {usePalette} from 'lib/hooks/usePalette' -import {getTranslatorLink} from '../../../locale/helpers' +import {getTranslatorLink, isPostInLanguage} from '../../../locale/helpers' export const Post = observer(function Post({ uri, @@ -134,6 +134,16 @@ const PostLoaded = observer( const urip = new AtUri(record.reply.parent?.uri || record.reply.root.uri) replyAuthorDid = urip.hostname } + + const primaryLanguage = store.preferences.contentLanguages[0] || 'en' + const translatorUrl = getTranslatorLink(primaryLanguage, record?.text || '') + const needsTranslation = useMemo( + () => + store.preferences.contentLanguages.length > 0 && + !isPostInLanguage(item.post, store.preferences.contentLanguages), + [item.post, store.preferences.contentLanguages], + ) + const onPressReply = React.useCallback(() => { store.shell.openComposer({ replyTo: { @@ -166,9 +176,6 @@ const PostLoaded = observer( Toast.show('Copied to clipboard') }, [record]) - const primaryLanguage = store.preferences.contentLanguages[0] || 'en' - const translatorUrl = getTranslatorLink(primaryLanguage, record?.text || '') - const onOpenTranslate = React.useCallback(() => { Linking.openURL(translatorUrl) }, [translatorUrl]) @@ -263,6 +270,15 @@ const PostLoaded = observer( <ImageHider moderation={item.moderation.list} style={s.mb10}> <PostEmbeds embed={item.post.embed} style={s.mb10} /> </ImageHider> + {needsTranslation && ( + <View style={[pal.borderDark, styles.translateLink]}> + <Link href={translatorUrl} title="Translate"> + <Text type="sm" style={pal.link}> + Translate this post + </Text> + </Link> + </View> + )} </ContentHider> <PostCtrls itemUri={itemUri} @@ -320,6 +336,9 @@ const styles = StyleSheet.create({ flexWrap: 'wrap', paddingBottom: 8, }, + translateLink: { + marginBottom: 12, + }, replyLine: { position: 'absolute', left: 36, |