Skip to content

Commit

Permalink
#15 Add no results and filters
Browse files Browse the repository at this point in the history
  • Loading branch information
SandraBergstrom committed Jun 26, 2023
1 parent 8e7641e commit 3e47db2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
Binary file added src/assets/no-results.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 43 additions & 3 deletions src/pages/posts/PostsPage.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,59 @@
import React from "react";
import React, { useEffect, useState } from "react";

import Form from "react-bootstrap/Form";
import Col from "react-bootstrap/Col";
import Row from "react-bootstrap/Row";
import Container from "react-bootstrap/Container";
import Post from "./Post";
import Asset from "../../components/Asset";

import appStyles from "../../App.module.css";
import styles from "../../styles/PostsPage.module.css";
import { useLocation } from "react-router-dom";
import { axiosReq } from "../../api/axiosDefaults";

import NoResults from "../../assets/no-results.png";

function PostsPage({ message, filter = "" }) {
const [posts, setPosts] = useState({ results: [] });
const [hasLoaded, setHasLoaded] = useState(false);
const { pathname } = useLocation();

useEffect(() => {
const fetchPosts = async () => {
try {
const { data } = await axiosReq.get(`/posts/?${filter}`);
setPosts(data);
setHasLoaded(true);
} catch (err) {
console.log(err);
}
};
setHasLoaded(false);
fetchPosts();
}, [filter, pathname]);

function PostsPage() {
return (
<Row className="h-100">
<Col className="py-2 p-0 p-lg-2" lg={8}>
<p>Popular profiles mobile</p>
<p>List of posts here</p>
{hasLoaded ? (
<>
{posts.results.length ? (
posts.results.map((post) => (
<Post key={post.id} {...post} setPosts={setPosts} />
))
) : (
<Container className="appStyles.Content">
<Asset src={NoResults} message={message} />
</Container>
)}
</>
) : (
<Container className="appStyles.Content">
<Asset spinner />
</Container>
)}
</Col>
<Col md={4} className="d-none d-lg-block p-0 p-lg-2">
<p>Popular profiles for desktop</p>
Expand Down

0 comments on commit 3e47db2

Please sign in to comment.