import { useMemo, useState } from "react"; import { ActivityIndicator, Text, View } from "react-native"; import { useFeedbackBody } from "../../../shared/context/FeedbackBodyProvider"; import { useFeedbackUi } from "../../../shared/context/FeedbackProvider"; import { allowAuthenticatedAction } from "../../../shared/helpers.js"; import type { FeedbackScreenEntryDetailProps } from "../../../shared/types"; import { Button } from "./Button"; import { CommentBranch } from "./CommentBranch"; import { EditEntryModal } from "./EditEntry.js"; import { FeedbackEntry, FeedbackForm } from "./primitives"; import { MetadataModal } from "./MetadataModal"; import { useNativeAction } from "../helpers.js"; export function EntryDetail({ entryId, onBack, hideBackButton, hideEditButton = false, }: FeedbackScreenEntryDetailProps) { const { hooks, commentSort, transformComments, isAuthenticated, onUnauthenticated, } = useFeedbackBody(); const { messages, theme } = useFeedbackUi(); const entry = hooks.useEntry(entryId); const comments = hooks.useComments({ entryId, sort: commentSort }); const setUpvote = hooks.useSetEntryUpvote(); const createComment = hooks.useCreateComment(); const [body, setBody] = useState(""); const [showMetadata, setShowMetadata] = useState(false); const [editOpen, setEditOpen] = useState(false); const upvoteAction = useNativeAction(); const commentAction = useNativeAction(); const toggleUpvote = (desiredState: boolean) => { if ( !allowAuthenticatedAction(isAuthenticated, onUnauthenticated) || upvoteAction.pending ) { return; } void upvoteAction.run( () => setUpvote({ entryId, desiredState }), "Could not update vote", ); }; const visible = useMemo( () => transformComments?.(comments.results) ?? comments.results, [comments.results, transformComments], ); if (entry === undefined) return ( {messages.board.loading} ); if (entry === null) { if (hideBackButton) return; return