diff --git a/src/App.js b/src/App.js index 3f1c749..cb94a72 100644 --- a/src/App.js +++ b/src/App.js @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React, {useEffect, useState} from 'react'; import PostList from './components/PostList'; import NewPostForm from './components/NewPostForm'; import Modal from './components/Modal'; @@ -6,12 +6,24 @@ import './App.scss'; import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"; import {faCaretDown, faCaretUp} from "@fortawesome/free-solid-svg-icons"; import {postApi} from "./api/posts.api"; +import {locationUtils} from "./utils/location"; const App = () => { const [posts, setPosts] = useState([]); const [selectedPost, setSelectedPost] = useState(null); const [comment, setComment] = useState(''); + useEffect(() => { + if(posts.length === 0) { + loadPosts().then(data => setPosts(data)) + } + }) + + const loadPosts = async () => { + const location = await locationUtils.getCurrentLocation(); + return await postApi.getPostsByCoords(location.lon, location.lat); + } + const addPost = (text) => { const newPost = { id: Date.now(), text, comments: [], upvotes: 0, downvotes: 0 }; setPosts([newPost, ...posts]); @@ -77,7 +89,6 @@ const App = () => { return (
- {console.log(postApi.getPostsByCoords(48, 9), process.env.REACT_APP_AUTH_USERNAME, process.env.REACT_APP_AUTH_PASSWORD)}

SWA - Jodel