Add translate link to post menu (#261)

* Add a google translate menu item to posts

* Fix: make sure the dropdown menu is always visible (when low on the screen)
This commit is contained in:
Paul Frazee 2023-03-03 15:13:31 -06:00 committed by GitHub
parent c2bfa111ac
commit a9920d9630
6 changed files with 44 additions and 3 deletions

View file

@ -1,6 +1,6 @@
import React from 'react'
import {observer} from 'mobx-react-lite'
import {StyleSheet, View} from 'react-native'
import {Linking, StyleSheet, View} from 'react-native'
import Clipboard from '@react-native-clipboard/clipboard'
import {AtUri} from '../../../third-party/uri'
import {
@ -89,6 +89,11 @@ export const PostThreadItem = observer(function PostThreadItem({
Clipboard.setString(record?.text || '')
Toast.show('Copied to clipboard')
}, [record])
const onOpenTranslate = React.useCallback(() => {
Linking.openURL(
encodeURI(`https://translate.google.com/#auto|en|${record?.text || ''}`),
)
}, [record])
const onDeletePost = React.useCallback(() => {
item.delete().then(
() => {
@ -167,6 +172,7 @@ export const PostThreadItem = observer(function PostThreadItem({
itemTitle={itemTitle}
isAuthor={item.post.author.did === store.me.did}
onCopyPostText={onCopyPostText}
onOpenTranslate={onOpenTranslate}
onDeletePost={onDeletePost}>
<FontAwesomeIcon
icon="ellipsis-h"
@ -259,6 +265,7 @@ export const PostThreadItem = observer(function PostThreadItem({
onPressToggleRepost={onPressToggleRepost}
onPressToggleUpvote={onPressToggleUpvote}
onCopyPostText={onCopyPostText}
onOpenTranslate={onOpenTranslate}
onDeletePost={onDeletePost}
/>
</View>
@ -353,6 +360,7 @@ export const PostThreadItem = observer(function PostThreadItem({
onPressToggleRepost={onPressToggleRepost}
onPressToggleUpvote={onPressToggleUpvote}
onCopyPostText={onCopyPostText}
onOpenTranslate={onOpenTranslate}
onDeletePost={onDeletePost}
/>
</View>