Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added loading animation for posts #29

Merged
merged 2 commits into from
Oct 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 38 additions & 19 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ function App() {
const [user, setUser] = useState(null);
const [signingUp, setSigningUp] = useState(false);
const [logginIn, setLogginIn] = useState(false);
const [loadingPosts, setLoadingPosts] = useState(true);
const processingAuth = useMemo(
() => logginIn || signingUp,
[logginIn, signingUp]
() => logginIn || signingUp || loadingPosts,
[logginIn, signingUp, loadingPosts]
);

useEffect(() => {
Expand All @@ -70,6 +71,7 @@ function App() {
db.collection("posts")
.orderBy("timestamp", "desc")
.onSnapshot((snapshot) => {
setLoadingPosts(false);
setPosts(
snapshot.docs.map((doc) => ({
id: doc.id,
Expand Down Expand Up @@ -237,25 +239,42 @@ function App() {
</div>
</Modal>

<center>
<div className="app__posts">
{posts.map(({ id, post }) => (
<Post
key={id}
postId={id}
user={user}
username={post.username}
avatar={post.avatar}
imageUrl={post.imageUrl}
caption={post.caption}
/>
))}
</div>
{user ? (
<ImgUpload username={user.displayName} />
<center
style={
!loadingPosts
? {}
: {
width: "100%",
minHeight: "100vh",
display: "flex",
justifyContent: "center",
alignItems: "center",
}
}
>
{loadingPosts ? (
<Loader />
) : (
<h3>Sorry you need to login to upload posts</h3>
<div className="app__posts">
{posts.map(({ id, post }) => (
<Post
key={id}
postId={id}
user={user}
username={post.username}
avatar={post.avatar}
imageUrl={post.imageUrl}
caption={post.caption}
/>
))}
</div>
)}
{!loadingPosts &&
(user ? (
<ImgUpload username={user.displayName} />
) : (
<h3>Sorry you need to login to upload posts</h3>
))}
</center>
</div>
);
Expand Down