import React, { useState, useEffect } from "react"; const Post = (props) => { const id = props.match.params.id const [state, setState] = useState({ user: { username: "HyperionLegion" }, post_title: "CLIMATE CHANGE", post_text: "We are gonna die if we don't do anything about climate change!", upvotes: 2, topics: ["climate change", "death"], comments: [ "this guy is weird", "no he is right. Climate change is a serious issue today oawtoa jto jwao jwo jwoap rjpwoarj woarj pwoajpfjpoajrpowaj pwoaj pwoa tjpwoa jpoawj posaj poasj pojawp ojwapo jposaj ", "factual", "Great speech!", "really?", "wow i didn't know that", ], }); const requestOptions = { method: "GET", headers: { Authorization: `Bearer ${localStorage.getItem("token")}`, }, }; const callAPI = () => { fetch(`${process.env.REACT_APP_API_ENDPOINT}/post/${id}`, requestOptions) .then((response) => response.json()) .then((data) => { if (data !== undefined) { setState(data); } }); }; const onSubmit = (e) => { e.preventDefault(); const requestOptions = { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${localStorage.getItem("token")}`, }, body: JSON.stringify({ postid: props.id }), }; fetch(`${process.env.REACT_APP_API_ENDPOINT}/post/upvote`, requestOptions) .then((response) => response.json()) .then((data) => { console.log(data); }); }; const onComment = (e) => { e.preventDefault(); const requestOptions = { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${localStorage.getItem("token")}`, }, body: JSON.stringify({ postid: props.id }), }; fetch(`${process.env.REACT_APP_API_ENDPOINT}/postcomment`, requestOptions) .then((response) => response.json()) .then((data) => { console.log(data); }); }; useEffect(() => { callAPI(); }, []); return (

Post {id}

Hello {state.user.username}!

{state.post_title}

{state.post_text}

Topics:

{state.topics.map((topic) => { return (

{topic}

); })}

{state.upvotes} Likes