diff --git a/client-solid/src/Components/Buttons/Engegament.tsx b/client-solid/src/Components/Buttons/Engegament.tsx index c768418..de87ae5 100644 --- a/client-solid/src/Components/Buttons/Engegament.tsx +++ b/client-solid/src/Components/Buttons/Engegament.tsx @@ -1,21 +1,54 @@ -import { JSXElement } from "solid-js"; +import { JSXElement, createSignal,onMount,useContext } from "solid-js"; import { EngagementIcon } from "../../Util/Icons"; +import { engage } from "../../Util/api"; +import { LoginContext } from "../../Context/GlobalState"; +import { getEngagementCount } from "../../Util/api"; + +export default function EngagementButton({ + postId, +}: { + postId: string; +}): JSXElement { + const [engagementCount, setEngagementCount] = createSignal(0); + const login_ctx = useContext(LoginContext)!; + + onMount((): void => { + void setUp() + }) + + const setUp = async () => { + const r = await getEngagementCount(postId) + setEngagementCount(r) + } + + // Function to handle engagement + const handleEngagement = async () => { + try { + const response = await engage(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); + } + }; -export default function EngagementButton(): JSXElement { return ( - <> -
This post has been edited
{props.post.content}
+{post.content}