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

View File

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

View File

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

View File

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

View File

@ -14,6 +14,7 @@ interface PostMetaOpts {
authorDisplayName: string | undefined
timestamp: string
isAuthor: boolean
onCopyPostText: () => void
onDeletePost: () => void
}
@ -40,6 +41,7 @@ export function PostMeta(opts: PostMetaOpts) {
itemHref={opts.itemHref}
itemTitle={opts.itemTitle}
isAuthor={opts.isAuthor}
onCopyPostText={opts.onCopyPostText}
onDeletePost={opts.onDeletePost}>
<FontAwesomeIcon icon="ellipsis-h" size={14} style={[s.mt2, s.mr5]} />
</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 {faMessage} from '@fortawesome/free-regular-svg-icons/faMessage'
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 {faPenNib} from '@fortawesome/free-solid-svg-icons/faPenNib'
import {faPenToSquare} from '@fortawesome/free-solid-svg-icons/faPenToSquare'
@ -101,6 +102,7 @@ export function setup() {
faMagnifyingGlass,
faMessage,
faNoteSticky,
faPaste,
faPen,
faPenNib,
faPenToSquare,