import { JSXElement, createSignal, onMount, useContext } from "solid-js"; import { LoginContext } from "../../Context/GlobalState"; import { EngagementIcon } from "../../Util/Icons"; import { engage, getEngagementCount } from "../../Util/api"; export default function EngagementButton(props: { postId: string; }): JSXElement { const [engagementCount, setEngagementCount] = createSignal(0); const login_ctx = useContext(LoginContext)!; onMount((): void => { void setUp(); }); const setUp = async (): Promise => { const r = await getEngagementCount(props.postId); setEngagementCount(r); }; // Function to handle engagement const handleEngagement = async (): Promise => { try { const response = await engage(props.postId, login_ctx.token()); if (response.ok) { // Update engagement count if the request is successful setEngagementCount(await response.json()); } else { console.error("Failed to engage:", response.statusText); } } catch (error) { console.error("Error engaging:", error); } }; return (

); }