-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathForum.jsx
More file actions
85 lines (77 loc) · 2.27 KB
/
Copy pathForum.jsx
File metadata and controls
85 lines (77 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import React, { useEffect, useState } from "react";
import axios from "axios";
// Styles
import "./Styles/Forum.scss";
// Components
import Post from "./Post.jsx";
import MakePost from "./MakePost.jsx";
import IDE from './IDE';
export default function Forum(props) {
const [isLoading, setLoading] = useState(true);
const [posts, setPosts] = useState([]);
const [banner, setBanner] = useState([]);
const [showIDE, setShowIDE] =useState(false);
useEffect(() => {
Promise.all([
axios.get(`/api/forums/${props.forum_id}`),
axios.get(`/api/posts/${props.forum_id}`),
])
.then((data) => {
setPosts(data[1].data);
setBanner(data[0].data);
setLoading(false);
})
.catch((err) => console.error(err.message));
}, [props.forum_id]);
const reFetchPosts = () => {
axios
.get(`/api/posts/${props.forum_id}`)
.then((data) => setPosts(data.data));
};
if (isLoading) {
return <div>LOADING...</div>;
}
return (
<section>
<div>
{banner.length && (
<img
className="forum-banner"
src={banner[0].img}
alt={banner[0].title}
/>
)}
</div>
<div className="forum-main-container">
{!showIDE && <div className="ideslideoutbutton" onClick={()=>setShowIDE(true)}>
<img src='https://i.imgur.com/i7lkHS2.png' alt='IDE'/>
</div>}
{showIDE && <div className="forum-ide"><IDE/><div className="ideslideinbutton" onClick={()=>setShowIDE(false)}>
<img src='https://i.imgur.com/YUeWiqa.png' alt='IDE'/>
</div></div>}
<div className='forum-postContainer' >
{!props.user.user_id && (
<MakePost forum_id={props.forum_id} user={props.user} />
)}
{props.user.user_id && (
<MakePost
reFetchPosts={reFetchPosts}
forum_id={props.forum_id}
user={props.user}
/>
)}
{posts.map(function (postdata) {
return (
<Post
reFetchPosts={reFetchPosts}
key={postdata.id}
{...postdata}
user={props.user}
/>
);
})}
</div>
</div>
</section>
);
}