Wire up ReportAccount and ReportPost (#168)
This commit is contained in:
@@ -39,7 +39,7 @@ export class ServerInputModal {
|
|||||||
export class ReportPostModal {
|
export class ReportPostModal {
|
||||||
name = 'report-post'
|
name = 'report-post'
|
||||||
|
|
||||||
constructor(public postUrl: string) {
|
constructor(public postUri: string, public postCid: string) {
|
||||||
makeAutoObservable(this)
|
makeAutoObservable(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,11 +5,13 @@ import {
|
|||||||
TouchableOpacity,
|
TouchableOpacity,
|
||||||
View,
|
View,
|
||||||
} from 'react-native'
|
} from 'react-native'
|
||||||
|
import {ComAtprotoReportReasonType} from '@atproto/api'
|
||||||
import LinearGradient from 'react-native-linear-gradient'
|
import LinearGradient from 'react-native-linear-gradient'
|
||||||
import {useStores} from '../../../state'
|
import {useStores} from '../../../state'
|
||||||
import {s, colors, gradients} from '../../lib/styles'
|
import {s, colors, gradients} from '../../lib/styles'
|
||||||
import {RadioGroup, RadioGroupItem} from '../util/forms/RadioGroup'
|
import {RadioGroup, RadioGroupItem} from '../util/forms/RadioGroup'
|
||||||
import {Text} from '../util/text/Text'
|
import {Text} from '../util/text/Text'
|
||||||
|
import * as Toast from '../util/Toast'
|
||||||
import {ErrorMessage} from '../util/error/ErrorMessage'
|
import {ErrorMessage} from '../util/error/ErrorMessage'
|
||||||
import {cleanError} from '../../../lib/strings'
|
import {cleanError} from '../../../lib/strings'
|
||||||
|
|
||||||
@@ -21,7 +23,7 @@ const ITEMS: RadioGroupItem[] = [
|
|||||||
|
|
||||||
export const snapPoints = ['50%']
|
export const snapPoints = ['50%']
|
||||||
|
|
||||||
export function Component() {
|
export function Component({did}: {did: string}) {
|
||||||
const store = useStores()
|
const store = useStores()
|
||||||
const [isProcessing, setIsProcessing] = useState<boolean>(false)
|
const [isProcessing, setIsProcessing] = useState<boolean>(false)
|
||||||
const [error, setError] = useState<string>('')
|
const [error, setError] = useState<string>('')
|
||||||
@@ -29,9 +31,26 @@ export function Component() {
|
|||||||
const onSelectIssue = (v: string) => setIssue(v)
|
const onSelectIssue = (v: string) => setIssue(v)
|
||||||
const onPress = async () => {
|
const onPress = async () => {
|
||||||
setError('')
|
setError('')
|
||||||
|
if (!issue) {
|
||||||
|
return
|
||||||
|
}
|
||||||
setIsProcessing(true)
|
setIsProcessing(true)
|
||||||
try {
|
try {
|
||||||
// TODO
|
// NOTE: we should update the lexicon of reasontype to include more options -prf
|
||||||
|
let reasonType = ComAtprotoReportReasonType.OTHER
|
||||||
|
if (issue === 'spam') {
|
||||||
|
reasonType = ComAtprotoReportReasonType.SPAM
|
||||||
|
}
|
||||||
|
const reason = ITEMS.find(item => item.key === issue)?.label || ''
|
||||||
|
await store.api.com.atproto.report.create({
|
||||||
|
reasonType,
|
||||||
|
reason,
|
||||||
|
subject: {
|
||||||
|
$type: 'com.atproto.repo.repoRef',
|
||||||
|
did,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
Toast.show("Thank you for your report! We'll look into it promptly.")
|
||||||
store.shell.closeModal()
|
store.shell.closeModal()
|
||||||
return
|
return
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
|||||||
@@ -5,11 +5,13 @@ import {
|
|||||||
TouchableOpacity,
|
TouchableOpacity,
|
||||||
View,
|
View,
|
||||||
} from 'react-native'
|
} from 'react-native'
|
||||||
|
import {ComAtprotoReportReasonType} from '@atproto/api'
|
||||||
import LinearGradient from 'react-native-linear-gradient'
|
import LinearGradient from 'react-native-linear-gradient'
|
||||||
import {useStores} from '../../../state'
|
import {useStores} from '../../../state'
|
||||||
import {s, colors, gradients} from '../../lib/styles'
|
import {s, colors, gradients} from '../../lib/styles'
|
||||||
import {RadioGroup, RadioGroupItem} from '../util/forms/RadioGroup'
|
import {RadioGroup, RadioGroupItem} from '../util/forms/RadioGroup'
|
||||||
import {Text} from '../util/text/Text'
|
import {Text} from '../util/text/Text'
|
||||||
|
import * as Toast from '../util/Toast'
|
||||||
import {ErrorMessage} from '../util/error/ErrorMessage'
|
import {ErrorMessage} from '../util/error/ErrorMessage'
|
||||||
import {cleanError} from '../../../lib/strings'
|
import {cleanError} from '../../../lib/strings'
|
||||||
|
|
||||||
@@ -22,7 +24,13 @@ const ITEMS: RadioGroupItem[] = [
|
|||||||
|
|
||||||
export const snapPoints = ['50%']
|
export const snapPoints = ['50%']
|
||||||
|
|
||||||
export function Component() {
|
export function Component({
|
||||||
|
postUri,
|
||||||
|
postCid,
|
||||||
|
}: {
|
||||||
|
postUri: string
|
||||||
|
postCid: string
|
||||||
|
}) {
|
||||||
const store = useStores()
|
const store = useStores()
|
||||||
const [isProcessing, setIsProcessing] = useState<boolean>(false)
|
const [isProcessing, setIsProcessing] = useState<boolean>(false)
|
||||||
const [error, setError] = useState<string>('')
|
const [error, setError] = useState<string>('')
|
||||||
@@ -30,9 +38,27 @@ export function Component() {
|
|||||||
const onSelectIssue = (v: string) => setIssue(v)
|
const onSelectIssue = (v: string) => setIssue(v)
|
||||||
const onPress = async () => {
|
const onPress = async () => {
|
||||||
setError('')
|
setError('')
|
||||||
|
if (!issue) {
|
||||||
|
return
|
||||||
|
}
|
||||||
setIsProcessing(true)
|
setIsProcessing(true)
|
||||||
try {
|
try {
|
||||||
// TODO
|
// NOTE: we should update the lexicon of reasontype to include more options -prf
|
||||||
|
let reasonType = ComAtprotoReportReasonType.OTHER
|
||||||
|
if (issue === 'spam') {
|
||||||
|
reasonType = ComAtprotoReportReasonType.SPAM
|
||||||
|
}
|
||||||
|
const reason = ITEMS.find(item => item.key === issue)?.label || ''
|
||||||
|
await store.api.com.atproto.report.create({
|
||||||
|
reasonType,
|
||||||
|
reason,
|
||||||
|
subject: {
|
||||||
|
$type: 'com.atproto.repo.recordRef',
|
||||||
|
uri: postUri,
|
||||||
|
cid: postCid,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
Toast.show("Thank you for your report! We'll look into it promptly.")
|
||||||
store.shell.closeModal()
|
store.shell.closeModal()
|
||||||
return
|
return
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ export const PostThreadItem = observer(function PostThreadItem({
|
|||||||
const record = item.postRecord
|
const record = item.postRecord
|
||||||
const hasEngagement = item.post.upvoteCount || item.post.repostCount
|
const hasEngagement = item.post.upvoteCount || item.post.repostCount
|
||||||
|
|
||||||
|
const itemUri = item.post.uri
|
||||||
|
const itemCid = item.post.cid
|
||||||
const itemHref = useMemo(() => {
|
const itemHref = useMemo(() => {
|
||||||
const urip = new AtUri(item.post.uri)
|
const urip = new AtUri(item.post.uri)
|
||||||
return `/profile/${item.post.author.handle}/post/${urip.rkey}`
|
return `/profile/${item.post.author.handle}/post/${urip.rkey}`
|
||||||
@@ -148,6 +150,8 @@ export const PostThreadItem = observer(function PostThreadItem({
|
|||||||
<View style={s.flex1} />
|
<View style={s.flex1} />
|
||||||
<PostDropdownBtn
|
<PostDropdownBtn
|
||||||
style={styles.metaItem}
|
style={styles.metaItem}
|
||||||
|
itemUri={itemUri}
|
||||||
|
itemCid={itemCid}
|
||||||
itemHref={itemHref}
|
itemHref={itemHref}
|
||||||
itemTitle={itemTitle}
|
itemTitle={itemTitle}
|
||||||
isAuthor={item.post.author.did === store.me.did}
|
isAuthor={item.post.author.did === store.me.did}
|
||||||
@@ -227,6 +231,8 @@ export const PostThreadItem = observer(function PostThreadItem({
|
|||||||
<View style={[s.pl10, s.pb5]}>
|
<View style={[s.pl10, s.pb5]}>
|
||||||
<PostCtrls
|
<PostCtrls
|
||||||
big
|
big
|
||||||
|
itemUri={itemUri}
|
||||||
|
itemCid={itemCid}
|
||||||
itemHref={itemHref}
|
itemHref={itemHref}
|
||||||
itemTitle={itemTitle}
|
itemTitle={itemTitle}
|
||||||
isAuthor={item.post.author.did === store.me.did}
|
isAuthor={item.post.author.did === store.me.did}
|
||||||
@@ -308,6 +314,8 @@ export const PostThreadItem = observer(function PostThreadItem({
|
|||||||
) : undefined}
|
) : undefined}
|
||||||
<PostEmbeds embed={item.post.embed} style={s.mb10} />
|
<PostEmbeds embed={item.post.embed} style={s.mb10} />
|
||||||
<PostCtrls
|
<PostCtrls
|
||||||
|
itemUri={itemUri}
|
||||||
|
itemCid={itemCid}
|
||||||
itemHref={itemHref}
|
itemHref={itemHref}
|
||||||
itemTitle={itemTitle}
|
itemTitle={itemTitle}
|
||||||
isAuthor={item.post.author.did === store.me.did}
|
isAuthor={item.post.author.did === store.me.did}
|
||||||
|
|||||||
@@ -80,6 +80,8 @@ export const Post = observer(function Post({
|
|||||||
const item = view.thread
|
const item = view.thread
|
||||||
const record = view.thread.postRecord
|
const record = view.thread.postRecord
|
||||||
|
|
||||||
|
const itemUri = item.post.uri
|
||||||
|
const itemCid = item.post.cid
|
||||||
const itemUrip = new AtUri(item.post.uri)
|
const itemUrip = new AtUri(item.post.uri)
|
||||||
const itemHref = `/profile/${item.post.author.handle}/post/${itemUrip.rkey}`
|
const itemHref = `/profile/${item.post.author.handle}/post/${itemUrip.rkey}`
|
||||||
const itemTitle = `Post by ${item.post.author.handle}`
|
const itemTitle = `Post by ${item.post.author.handle}`
|
||||||
@@ -190,6 +192,8 @@ export const Post = observer(function Post({
|
|||||||
) : undefined}
|
) : undefined}
|
||||||
<PostEmbeds embed={item.post.embed} style={s.mb10} />
|
<PostEmbeds embed={item.post.embed} style={s.mb10} />
|
||||||
<PostCtrls
|
<PostCtrls
|
||||||
|
itemUri={itemUri}
|
||||||
|
itemCid={itemCid}
|
||||||
itemHref={itemHref}
|
itemHref={itemHref}
|
||||||
itemTitle={itemTitle}
|
itemTitle={itemTitle}
|
||||||
isAuthor={item.post.author.did === store.me.did}
|
isAuthor={item.post.author.did === store.me.did}
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ export const FeedItem = observer(function ({
|
|||||||
const {track} = useAnalytics()
|
const {track} = useAnalytics()
|
||||||
const [deleted, setDeleted] = useState(false)
|
const [deleted, setDeleted] = useState(false)
|
||||||
const record = item.postRecord
|
const record = item.postRecord
|
||||||
|
const itemUri = item.post.uri
|
||||||
|
const itemCid = item.post.cid
|
||||||
const itemHref = useMemo(() => {
|
const itemHref = useMemo(() => {
|
||||||
const urip = new AtUri(item.post.uri)
|
const urip = new AtUri(item.post.uri)
|
||||||
return `/profile/${item.post.author.handle}/post/${urip.rkey}`
|
return `/profile/${item.post.author.handle}/post/${urip.rkey}`
|
||||||
@@ -207,6 +209,8 @@ export const FeedItem = observer(function ({
|
|||||||
) : null}
|
) : null}
|
||||||
<PostCtrls
|
<PostCtrls
|
||||||
style={styles.ctrls}
|
style={styles.ctrls}
|
||||||
|
itemUri={itemUri}
|
||||||
|
itemCid={itemCid}
|
||||||
itemHref={itemHref}
|
itemHref={itemHref}
|
||||||
itemTitle={itemTitle}
|
itemTitle={itemTitle}
|
||||||
isAuthor={item.post.author.did === store.me.did}
|
isAuthor={item.post.author.did === store.me.did}
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ import {s, colors} from '../../lib/styles'
|
|||||||
import {useTheme} from '../../lib/ThemeContext'
|
import {useTheme} from '../../lib/ThemeContext'
|
||||||
|
|
||||||
interface PostCtrlsOpts {
|
interface PostCtrlsOpts {
|
||||||
|
itemUri: string
|
||||||
|
itemCid: string
|
||||||
itemHref: string
|
itemHref: string
|
||||||
itemTitle: string
|
itemTitle: string
|
||||||
isAuthor: boolean
|
isAuthor: boolean
|
||||||
@@ -249,6 +251,8 @@ export function PostCtrls(opts: PostCtrlsOpts) {
|
|||||||
{opts.big ? undefined : (
|
{opts.big ? undefined : (
|
||||||
<PostDropdownBtn
|
<PostDropdownBtn
|
||||||
style={styles.ctrl}
|
style={styles.ctrl}
|
||||||
|
itemUri={opts.itemUri}
|
||||||
|
itemCid={opts.itemCid}
|
||||||
itemHref={opts.itemHref}
|
itemHref={opts.itemHref}
|
||||||
itemTitle={opts.itemTitle}
|
itemTitle={opts.itemTitle}
|
||||||
isAuthor={opts.isAuthor}
|
isAuthor={opts.isAuthor}
|
||||||
|
|||||||
@@ -100,6 +100,8 @@ export function DropdownButton({
|
|||||||
export function PostDropdownBtn({
|
export function PostDropdownBtn({
|
||||||
style,
|
style,
|
||||||
children,
|
children,
|
||||||
|
itemUri,
|
||||||
|
itemCid,
|
||||||
itemHref,
|
itemHref,
|
||||||
isAuthor,
|
isAuthor,
|
||||||
onCopyPostText,
|
onCopyPostText,
|
||||||
@@ -107,6 +109,8 @@ export function PostDropdownBtn({
|
|||||||
}: {
|
}: {
|
||||||
style?: StyleProp<ViewStyle>
|
style?: StyleProp<ViewStyle>
|
||||||
children?: React.ReactNode
|
children?: React.ReactNode
|
||||||
|
itemUri: string
|
||||||
|
itemCid: string
|
||||||
itemHref: string
|
itemHref: string
|
||||||
itemTitle: string
|
itemTitle: string
|
||||||
isAuthor: boolean
|
isAuthor: boolean
|
||||||
@@ -143,7 +147,7 @@ export function PostDropdownBtn({
|
|||||||
icon: 'circle-exclamation',
|
icon: 'circle-exclamation',
|
||||||
label: 'Report post',
|
label: 'Report post',
|
||||||
onPress() {
|
onPress() {
|
||||||
store.shell.openModal(new ReportPostModal(itemHref))
|
store.shell.openModal(new ReportPostModal(itemUri, itemCid))
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
isAuthor
|
isAuthor
|
||||||
|
|||||||
Reference in New Issue
Block a user