import axios from "axios";
import { DiscussionBoard } from "../../components/DiscussionBoard/DiscussionBoard";
import { getUser } from "../../../lib/requests";
import { useEffect, useState } from "react";

function Forum({ posts }) {

  const [user, setUser] = useState(null)

  useEffect(async () => {
    setUser(await getUser())
  }, [])


  return (
    <>
      <DiscussionBoard posts={posts} user={user} />
    </>
  );
}

export async function getServerSideProps(context) {
  let res = await axios({
    url: "/posts",
  })
  let posts = res.data
  return {
    props: { posts: posts },
  }
}

export default Forum
