import type { PostProps } from "./Post";
import Icon from "@/components/Icon";
import { useState } from "react";
import useLocalState from "@/state/state";
import { useLocation } from "wouter";
import { displayCount } from "@/logic/utils";
import { TrillReactModal, stringToReact } from "./Reactions";
import toast from "react-hot-toast";
import NostrIcon from "./wrappers/NostrIcon";
// TODO abstract this somehow
function Footer({ poast, refetch }: PostProps) {
const [_showMenu, setShowMenu] = useState(false);
const [location, navigate] = useLocation();
const [reposting, _setReposting] = useState(false);
const { api, setComposerData, setModal, addNotification } = useLocalState((s) => ({
api: s.api,
setComposerData: s.setComposerData,
setModal: s.setModal,
addNotification: s.addNotification,
}));
const our = api!.airlock.our!;
function doReply(e: React.MouseEvent) {
e.stopPropagation();
setComposerData({ type: "reply", post: { trill: poast } });
// Only add notification if replying to someone else's post
if (poast.author !== our) {
addNotification({
type: "reply",
from: our,
message: `You replied to ${poast.author}'s post`,
postId: poast.id,
});
}
}
function doQuote(e: React.MouseEvent) {
e.stopPropagation();
setComposerData({
type: "quote",
post: { trill: poast },
});
navigate("/composer");
}
const childrenCount = poast.children
? poast.children.length
? poast.children.length
: Object.keys(poast.children).length
: 0;
const myRP = poast.engagement.shared.find((r) => r.pid.ship === our);
async function cancelRP(e: React.MouseEvent) {
e.stopPropagation();
const r = await api!.deletePost(our);
if (r) toast.success("Repost deleted");
refetch();
if (location.includes(poast.id)) navigate("/");
}
async function sendRP(e: React.MouseEvent) {
// TODO update backend because contents are only markdown now
e.stopPropagation();
// const c = [
// {
// ref: {
// type: "trill",
// ship: poast.host,
// path: `/${poast.id}`,
// },
// },
// ];
// const post: SentPoast = {
// host: our,
// author: our,
// thread: null,
// parent: null,
// contents: input,
// read: openLock,
// write: openLock,
// tags: [], // TODO
// };
// const r = await api!.addPost(post, false);
// setReposting(true);
// if (r) {
// setReposting(false);
// toast.success("Your post was published");
// }
}
function doReact(e: React.MouseEvent) {
e.stopPropagation();
const modal =