Skip to content

Commit

Permalink
User page fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
RafaelBahiense committed Jun 4, 2021
1 parent 21374cd commit 9e69f57
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/components/UserPosts/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from "axios";
import { useHistory, useParams } from "react-router-dom";
import React, { useEffect, useContext, useState } from "react";
import React, { useEffect, useContext, useState, useRef } from "react";
import useInterval from '@use-it/interval';

import TimelineLayout from "../Timeline/TimelineLayout";
Expand All @@ -15,6 +15,7 @@ const UserPosts = () => {
const history = useHistory();
const [refresh, setRefresh] = React.useState([]);
const [hasMore, setHasMore] = useState(true);
const initialRender = useRef(true);

function refreshPosts() {
setRefresh([...refresh]);
Expand Down Expand Up @@ -63,7 +64,16 @@ const UserPosts = () => {

useEffect(() => {
loadPosts();
}, [id, refresh]);
}, [refresh]);

useEffect(() => {
if (initialRender.current) {
initialRender.current = false;
} else {
setPosts(null);
refreshPosts();
}
}, [id]);

useInterval(() => {
refreshPosts();
Expand All @@ -74,6 +84,7 @@ const UserPosts = () => {
user={user}
title={user ? `${user.username}'s posts` : "Loading user"}
userPost={true}
refreshPosts={refreshPosts}
loadPosts={loadPosts}
hasMore={hasMore}
/>
Expand Down

0 comments on commit 9e69f57

Please sign in to comment.