import React, {useCallback} from 'react' import { StyleProp, StyleSheet, TouchableOpacity, View, ViewStyle, } from 'react-native' import {AppBskyFeedDefs, AppBskyFeedPost} from '@atproto/api' import {Text} from '../text/Text' import {PostDropdownBtn} from '../forms/PostDropdownBtn' import {HeartIcon, HeartIconSolid, CommentBottomArrow} from 'lib/icons' import {s, colors} from 'lib/styles' import {pluralize} from 'lib/strings/helpers' import {useTheme} from 'lib/ThemeContext' import {RepostButton} from './RepostButton' import {Haptics} from 'lib/haptics' import {HITSLOP_10, HITSLOP_20} from 'lib/constants' import {useModalControls} from '#/state/modals' import { usePostLikeMutation, usePostUnlikeMutation, usePostRepostMutation, usePostUnrepostMutation, } from '#/state/queries/post' import {useComposerControls} from '#/state/shell/composer' export function PostCtrls({ big, post, record, style, onPressReply, }: { big?: boolean post: AppBskyFeedDefs.PostView record: AppBskyFeedPost.Record style?: StyleProp onPressReply: () => void }) { const theme = useTheme() const {openComposer} = useComposerControls() const {closeModal} = useModalControls() const postLikeMutation = usePostLikeMutation() const postUnlikeMutation = usePostUnlikeMutation() const postRepostMutation = usePostRepostMutation() const postUnrepostMutation = usePostUnrepostMutation() const defaultCtrlColor = React.useMemo( () => ({ color: theme.palette.default.postCtrl, }), [theme], ) as StyleProp const onPressToggleLike = React.useCallback(async () => { if (!post.viewer?.like) { Haptics.default() postLikeMutation.mutate({ uri: post.uri, cid: post.cid, likeCount: post.likeCount || 0, }) } else { postUnlikeMutation.mutate({ postUri: post.uri, likeUri: post.viewer.like, likeCount: post.likeCount || 0, }) } }, [post, postLikeMutation, postUnlikeMutation]) const onRepost = useCallback(() => { closeModal() if (!post.viewer?.repost) { Haptics.default() postRepostMutation.mutate({ uri: post.uri, cid: post.cid, repostCount: post.repostCount || 0, }) } else { postUnrepostMutation.mutate({ postUri: post.uri, repostUri: post.viewer.repost, repostCount: post.repostCount || 0, }) } }, [post, closeModal, postRepostMutation, postUnrepostMutation]) const onQuote = useCallback(() => { closeModal() openComposer({ quote: { uri: post.uri, cid: post.cid, text: record.text, author: post.author, indexedAt: post.indexedAt, }, }) Haptics.default() }, [post, record, openComposer, closeModal]) return ( {typeof post.replyCount !== 'undefined' ? ( {post.replyCount} ) : undefined} {post.viewer?.like ? ( ) : ( )} {typeof post.likeCount !== 'undefined' ? ( {post.likeCount} ) : undefined} {big ? undefined : ( )} {/* used for adding pad to the right side */} ) } const styles = StyleSheet.create({ ctrls: { flexDirection: 'row', justifyContent: 'space-between', }, ctrl: { flexDirection: 'row', alignItems: 'center', }, ctrlPad: { paddingTop: 5, paddingBottom: 5, paddingLeft: 5, paddingRight: 5, }, ctrlIconLiked: { color: colors.like, }, mt1: { marginTop: 1, }, })