// © XlXi 2021 // Graphictoria 5 import axios from 'axios'; import React, { useEffect, useState } from "react"; import { Link, useHistory, useParams } from "react-router-dom"; import Config from '../config.js'; import SetTitle from "../Helpers/Title.js"; import Loader from '../Components/Loader.js'; import { GenericErrorModal } from './Errors.js'; import { Card, CardTitle } from '../Layouts/Card.js'; var url = Config.BaseUrl.replace('http://', ''); var protocol = Config.Protocol; const Forum = (props) => { var id = useParams().id; const [state, setState] = useState({offline: false, loading: true}); const [categories, setCategoires] = useState([]); const [category, setCategory] = useState([]); const [posts, setPosts] = useState({posts: [], currentPage: 0, meta: []}); const user = props.user; if (!id) id = 1; const fetchCategories = async () => { await axios.get(`${protocol}apis.${url}/fetch/categories`, {headers: {"X-Requested-With":"XMLHttpRequest"}}).then(data=>{ setCategoires(data.data.data); }).catch(error=>{console.log(error);}); } const fetchCategory = async () => { await axios.get(`${protocol}apis.${url}/fetch/category/${id}`, {headers: {"X-Requested-With":"XMLHttpRequest"}}).then(data=>{ if (!data.data) {window.location.href=`/forum`;return;} setCategory(data.data.data); setPosts({...posts, posts: data.data.posts.data, meta: data.data.posts}); }).catch(error=>{console.log(error);}); } useEffect(async ()=>{ SetTitle(`Forum`); await fetchCategories(); await fetchCategory(); setState({...state, loading: false}); }, []); return ( state.loading ? :

Welcome to {category.title}!

{category.description}

{user?
Create a post
: null}

Categories:

{categories.map(category=>( <> {category.title}
))}
{posts.posts.length <= 0 ?

There are currently no posts!

: null} {posts.posts.map(post=>( <>
[Avatar.]
{post.title}

Posted by:

{post.creator.username}
))}
); } export default Forum;