import React, {useEffect, useState} from 'react'; import NewPostForm from './components/NewPostForm'; import './App.scss'; import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"; import {faPenToSquare, faRotate, faTimes} from "@fortawesome/free-solid-svg-icons"; import {postApi} from "./api/posts.api"; import {locationUtils} from "./utils/location"; import Post from "./components/Post"; import keycloak from "./Authentification/Keycloak"; const App = () => { const [posts, setPosts] = useState([]); const [selectedPost, selectPost] = useState(null); const [comment, setComment] = useState(''); useEffect(() => { if(posts.length === 0) { reload().then(null); } }); useEffect(() => { if(selectedPost) { selectPost(posts.find(post => post.id === selectedPost.id)); } }, [posts]); const reload = async () => { await loadPosts().then(data => { setPosts(data); }); } const loadPosts = async () => { const location = await locationUtils.getCurrentLocation(); return await postApi.getPostsByCoords(location.lon, location.lat); } const addPost = async (title, text) => { await postApi.createNewPost(title, text); await reload(); }; const addComment = async (postId, commentText) => { await postApi.createNewPost("", commentText, postId).then(await reload); }; const handleCommentSubmit = async (e) => { e.preventDefault(); if (comment.trim() && selectedPost) { await addComment(selectedPost.id, comment); setComment(''); await reload(); selectPost(selectedPost); } }; const closePost = () => { selectPost(null); }; return (

SWA - Jodel

{posts.map(post => )}
{selectedPost && (