Add 'copy post text' tool

zio/stable
Paul Frazee 2022-12-05 15:03:42 -06:00
parent 73c84f6f64
commit bbe6bf8fc2
6 changed files with 32 additions and 0 deletions

View File

@ -1,6 +1,7 @@
import React, {useMemo, useState} from 'react' import React, {useMemo, useState} from 'react'
import {observer} from 'mobx-react-lite' import {observer} from 'mobx-react-lite'
import {StyleSheet, Text, View} from 'react-native' import {StyleSheet, Text, View} from 'react-native'
import Clipboard from '@react-native-clipboard/clipboard'
import {AtUri} from '../../../third-party/uri' import {AtUri} from '../../../third-party/uri'
import * as PostType from '../../../third-party/api/src/client/types/app/bsky/feed/post' import * as PostType from '../../../third-party/api/src/client/types/app/bsky/feed/post'
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome' import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
@ -75,6 +76,10 @@ export const PostThreadItem = observer(function PostThreadItem({
.toggleUpvote() .toggleUpvote()
.catch(e => console.error('Failed to toggle upvote', record, e)) .catch(e => console.error('Failed to toggle upvote', record, e))
} }
const onCopyPostText = () => {
Clipboard.setString(record.text)
Toast.show('Copied to clipboard')
}
const onDeletePost = () => { const onDeletePost = () => {
item.delete().then( item.delete().then(
() => { () => {
@ -130,6 +135,7 @@ export const PostThreadItem = observer(function PostThreadItem({
itemHref={itemHref} itemHref={itemHref}
itemTitle={itemTitle} itemTitle={itemTitle}
isAuthor={item.author.did === store.me.did} isAuthor={item.author.did === store.me.did}
onCopyPostText={onCopyPostText}
onDeletePost={onDeletePost}> onDeletePost={onDeletePost}>
<FontAwesomeIcon <FontAwesomeIcon
icon="ellipsis-h" icon="ellipsis-h"
@ -257,6 +263,7 @@ export const PostThreadItem = observer(function PostThreadItem({
authorDisplayName={item.author.displayName} authorDisplayName={item.author.displayName}
timestamp={item.indexedAt} timestamp={item.indexedAt}
isAuthor={item.author.did === store.me.did} isAuthor={item.author.did === store.me.did}
onCopyPostText={onCopyPostText}
onDeletePost={onDeletePost} onDeletePost={onDeletePost}
/> />
<View style={styles.postTextContainer}> <View style={styles.postTextContainer}>

View File

@ -8,6 +8,7 @@ import {
ViewStyle, ViewStyle,
} from 'react-native' } from 'react-native'
import {observer} from 'mobx-react-lite' import {observer} from 'mobx-react-lite'
import Clipboard from '@react-native-clipboard/clipboard'
import {AtUri} from '../../../third-party/uri' import {AtUri} from '../../../third-party/uri'
import * as PostType from '../../../third-party/api/src/client/types/app/bsky/feed/post' import * as PostType from '../../../third-party/api/src/client/types/app/bsky/feed/post'
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome' import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
@ -110,6 +111,10 @@ export const Post = observer(function Post({
.toggleUpvote() .toggleUpvote()
.catch(e => console.error('Failed to toggle upvote', record, e)) .catch(e => console.error('Failed to toggle upvote', record, e))
} }
const onCopyPostText = () => {
Clipboard.setString(record.text)
Toast.show('Copied to clipboard')
}
const onDeletePost = () => { const onDeletePost = () => {
item.delete().then( item.delete().then(
() => { () => {
@ -144,6 +149,7 @@ export const Post = observer(function Post({
authorDisplayName={item.author.displayName} authorDisplayName={item.author.displayName}
timestamp={item.indexedAt} timestamp={item.indexedAt}
isAuthor={item.author.did === store.me.did} isAuthor={item.author.did === store.me.did}
onCopyPostText={onCopyPostText}
onDeletePost={onDeletePost} onDeletePost={onDeletePost}
/> />
{replyHref !== '' && ( {replyHref !== '' && (

View File

@ -1,6 +1,7 @@
import React, {useMemo, useState} from 'react' import React, {useMemo, useState} from 'react'
import {observer} from 'mobx-react-lite' import {observer} from 'mobx-react-lite'
import {StyleSheet, Text, View} from 'react-native' import {StyleSheet, Text, View} from 'react-native'
import Clipboard from '@react-native-clipboard/clipboard'
import {AtUri} from '../../../third-party/uri' import {AtUri} from '../../../third-party/uri'
import * as PostType from '../../../third-party/api/src/client/types/app/bsky/feed/post' import * as PostType from '../../../third-party/api/src/client/types/app/bsky/feed/post'
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome' import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
@ -66,6 +67,10 @@ export const FeedItem = observer(function FeedItem({
.toggleUpvote() .toggleUpvote()
.catch(e => console.error('Failed to toggle upvote', record, e)) .catch(e => console.error('Failed to toggle upvote', record, e))
} }
const onCopyPostText = () => {
Clipboard.setString(record.text)
Toast.show('Copied to clipboard')
}
const onDeletePost = () => { const onDeletePost = () => {
item.delete().then( item.delete().then(
() => { () => {
@ -147,6 +152,7 @@ export const FeedItem = observer(function FeedItem({
authorDisplayName={item.author.displayName} authorDisplayName={item.author.displayName}
timestamp={item.indexedAt} timestamp={item.indexedAt}
isAuthor={item.author.did === store.me.did} isAuthor={item.author.did === store.me.did}
onCopyPostText={onCopyPostText}
onDeletePost={onDeletePost} onDeletePost={onDeletePost}
/> />
) : undefined} ) : undefined}

View File

@ -79,6 +79,7 @@ export function PostDropdownBtn({
itemHref, itemHref,
itemTitle, itemTitle,
isAuthor, isAuthor,
onCopyPostText,
onDeletePost, onDeletePost,
}: { }: {
style?: StyleProp<ViewStyle> style?: StyleProp<ViewStyle>
@ -86,6 +87,7 @@ export function PostDropdownBtn({
itemHref: string itemHref: string
itemTitle: string itemTitle: string
isAuthor: boolean isAuthor: boolean
onCopyPostText: () => void
onDeletePost: () => void onDeletePost: () => void
}) { }) {
const store = useStores() const store = useStores()
@ -100,6 +102,13 @@ export function PostDropdownBtn({
}, },
} }
: undefined, : undefined,
{
icon: ['far', 'paste'],
label: 'Copy post text',
onPress() {
onCopyPostText()
},
},
{ {
icon: 'share', icon: 'share',
label: 'Share...', label: 'Share...',

View File

@ -14,6 +14,7 @@ interface PostMetaOpts {
authorDisplayName: string | undefined authorDisplayName: string | undefined
timestamp: string timestamp: string
isAuthor: boolean isAuthor: boolean
onCopyPostText: () => void
onDeletePost: () => void onDeletePost: () => void
} }
@ -40,6 +41,7 @@ export function PostMeta(opts: PostMetaOpts) {
itemHref={opts.itemHref} itemHref={opts.itemHref}
itemTitle={opts.itemTitle} itemTitle={opts.itemTitle}
isAuthor={opts.isAuthor} isAuthor={opts.isAuthor}
onCopyPostText={opts.onCopyPostText}
onDeletePost={opts.onDeletePost}> onDeletePost={opts.onDeletePost}>
<FontAwesomeIcon icon="ellipsis-h" size={14} style={[s.mt2, s.mr5]} /> <FontAwesomeIcon icon="ellipsis-h" size={14} style={[s.mt2, s.mr5]} />
</PostDropdownBtn> </PostDropdownBtn>

View File

@ -38,6 +38,7 @@ import {faLock} from '@fortawesome/free-solid-svg-icons/faLock'
import {faMagnifyingGlass} from '@fortawesome/free-solid-svg-icons/faMagnifyingGlass' import {faMagnifyingGlass} from '@fortawesome/free-solid-svg-icons/faMagnifyingGlass'
import {faMessage} from '@fortawesome/free-regular-svg-icons/faMessage' import {faMessage} from '@fortawesome/free-regular-svg-icons/faMessage'
import {faNoteSticky} from '@fortawesome/free-solid-svg-icons/faNoteSticky' import {faNoteSticky} from '@fortawesome/free-solid-svg-icons/faNoteSticky'
import {faPaste} from '@fortawesome/free-regular-svg-icons/faPaste'
import {faPen} from '@fortawesome/free-solid-svg-icons/faPen' import {faPen} from '@fortawesome/free-solid-svg-icons/faPen'
import {faPenNib} from '@fortawesome/free-solid-svg-icons/faPenNib' import {faPenNib} from '@fortawesome/free-solid-svg-icons/faPenNib'
import {faPenToSquare} from '@fortawesome/free-solid-svg-icons/faPenToSquare' import {faPenToSquare} from '@fortawesome/free-solid-svg-icons/faPenToSquare'
@ -101,6 +102,7 @@ export function setup() {
faMagnifyingGlass, faMagnifyingGlass,
faMessage, faMessage,
faNoteSticky, faNoteSticky,
faPaste,
faPen, faPen,
faPenNib, faPenNib,
faPenToSquare, faPenToSquare,