import { View, Text, Pressable } from "react-native"; import { useCallback, useMemo, useState } from "react"; import { handleError, ReportReasonKey, reportReasons, useUser, useCommentSection, useSubmitReport, } from "replyke-core"; import BottomSheet, { BottomSheetBackdrop, BottomSheetBackdropProps, BottomSheetView, } from "@gorhom/bottom-sheet"; import useSheetManager from "../../../hooks/useSheetManager"; import { FlagIcon } from "../../icons"; import CustomButton from "../CustomButton"; const ReportCommentSheet = () => { const { user } = useUser(); const { callbacks } = useCommentSection(); const { reportCommentSheetRef, reportedComment, setReportedComment, closeReportCommentSheet, } = useSheetManager(); const { submitCommentReport } = useSubmitReport(); const [submitting, setSubmitting] = useState(false); const [reason, setReason] = useState(null); const snapPoints = useMemo(() => ["100%"], []); const buttonActive = useMemo( () => !!reason && !!reportedComment, [reason, reportedComment] ); const renderBackdrop = useCallback( (props: BottomSheetBackdropProps) => ( ), [] ); const handleSubmitReport = async () => { try { if (!reportedComment) throw new Error("No comment to report selected"); if (!reason) throw new Error("No reason to report selected"); if (!user) { callbacks?.loginRequiredCallback?.(); return; } setSubmitting(true); await submitCommentReport({ targetId: reportedComment.id, reason }); closeReportCommentSheet?.(); setReportedComment?.(null); setReason(null); } catch (err) { handleError(err, "Submtting report failed"); } finally { setSubmitting(false); } }; return ( { if (state === -1) { setReportedComment?.(null); } }} backgroundStyle={{ backgroundColor: "#18181B" }} handleIndicatorStyle={{ backgroundColor: "#fff" }} > Submit a report Thank you for looking out for our community. Let us know what is happening, and we'll look into it. {Object.entries(reportReasons).map(([key, value], index) => ( setReason(key as ReportReasonKey)} key={index} style={{ borderWidth: 1, borderColor: "#e5e7eb", paddingHorizontal: 16, paddingVertical: 10, borderRadius: 12, backgroundColor: key === reason ? "#f9fafb" : "transparent", }} > {value} ))} ); }; export default ReportCommentSheet;