diff --git a/src/App.js b/src/App.js index 6278a9b..5658916 100644 --- a/src/App.js +++ b/src/App.js @@ -1,18 +1,16 @@ import React, {useEffect, useState} from 'react'; -import PostCommentList from './components/PostCommentList'; import NewPostForm from './components/NewPostForm'; import './App.scss'; import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"; import {faTimes} from "@fortawesome/free-solid-svg-icons"; import {postApi} from "./api/posts.api"; import {locationUtils} from "./utils/location"; -import PostComment from "./components/PostComment"; +import Post from "./components/Post"; import keycloak from "./Authentification/Keycloak"; const App = () => { const [posts, setPosts] = useState([]); - const [comments, setComments] = useState([]); - const [selectedPost, setSelectedPost] = useState(null); + const [selectedPost, selectPost] = useState(null); const [comment, setComment] = useState(''); useEffect(() => { @@ -23,15 +21,10 @@ const App = () => { useEffect(() => { if(selectedPost) { - setSelectedPost(posts.find(post => post.id === selectedPost.id)); + selectPost(posts.find(post => post.id === selectedPost.id)); } }, [posts]); - useEffect(() => { - if(selectedPost) { - setComments(selectedPost.comments); - } - }, [selectedPost]); const reload = async () => { await loadPosts().then(data => { @@ -53,44 +46,28 @@ const App = () => { await postApi.createNewPost("", commentText, postId).then(await reload); }; - const vote = (postId, reaction) => { - // TODO postApi.reactToPost(postId) - console.log(postId, reaction); - }; - - const handlePostClick = (post) => { - setSelectedPost(post); - }; - const handleCommentSubmit = async (e) => { e.preventDefault(); if (comment.trim() && selectedPost) { await addComment(selectedPost.id, comment); setComment(''); await reload(); - handlePostClick(selectedPost); + selectPost(selectedPost); } }; const closePost = () => { - setSelectedPost(null); - setComment(''); + selectPost(null); }; return (