Skip to content

Commit 3042f3d

Browse files
author
GilbertoASJ
committed
Feature: ✨ Creating Dashboard page and updating post css
1 parent b9d6c6d commit 3042f3d

File tree

4 files changed

+59
-7
lines changed

4 files changed

+59
-7
lines changed

src/hooks/useFetchDocuments.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ export const useFetchDocuments = (docCollection, search = null, uid = null) => {
3737
orderBy('createdAt', 'desc')
3838
);
3939

40+
} else if(uid) {
41+
42+
q = await query(
43+
collectionRef,
44+
where('uid', '==', uid),
45+
orderBy('createdAt', 'desc')
46+
);
47+
4048
} else {
4149

4250
q = await query(collectionRef, orderBy('createdAt', 'desc'));
@@ -65,7 +73,7 @@ export const useFetchDocuments = (docCollection, search = null, uid = null) => {
6573

6674
loadData();
6775

68-
}, [docCollection, search, documents, uid, cancelled])
76+
}, [docCollection, search, uid, cancelled])
6977

7078
// deal with memory leak
7179
useEffect(() => {

src/pages/Dashboard/Dashboard.jsx

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,41 @@
11
import styles from './Dashboard.module.scss';
2+
import { Link } from 'react-router-dom';
3+
4+
// hooks
5+
import { useAuthValue } from '../../context/AuthContext';
6+
import { useFetchDocuments } from '../../hooks/useFetchDocuments';
27

38
const Dashboard = () => {
49

10+
const { user } = useAuthValue();
11+
const uid = user.uid;
12+
13+
const { documents: posts, loading, error } = useFetchDocuments('posts', null, uid)
14+
515
return (
6-
<>
16+
<div>
717
<h1>Dashboard</h1>
8-
</>
18+
<p>Gerencie os seus posts</p>
19+
{posts && posts.length === 0 ? (
20+
21+
<div className={styles.noposts}>
22+
<p>Não foram encontrados posts!</p>
23+
<Link to="/posts/create" className="btn">
24+
Crie seu primeiro post
25+
</Link>
26+
</div>
27+
) : (
28+
29+
<div>
30+
<p>Tem posts!</p>
31+
</div>
32+
)}
33+
34+
{posts && posts.map((post) => (
35+
36+
<h3>{post.title}</h3>
37+
))}
38+
</div>
939
)
1040
}
1141

src/pages/Post/Post.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const Post = () => {
1313
<div className={styles.post_container}>
1414
{loading && (<p>Carregando post...</p>)}
1515
{post && (
16-
<div>
16+
<div className={styles.post_detail}>
1717
<h1>{post.title}</h1>
1818
<img
1919
src={post.image}

src/pages/Post/Post.module.scss

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
11
.post_container {
22
text-align: center;
3+
padding-top: 3.5rem;
4+
display: flex;
5+
flex-direction: column;
6+
align-items: center;
7+
justify-content: center;
38

4-
// p.body {
5-
// text-align: justify;
6-
// }
9+
p.body {
10+
text-align: justify;
11+
margin: 1rem 0;
12+
}
13+
14+
img {
15+
margin-top: 1rem;
16+
}
717

818
h3 {
919
margin-bottom: .2rem;
1020
}
1121

22+
.post_detail {
23+
width: 600px;
24+
}
25+
1226
.tags {
1327
display: flex;
1428
justify-content: center;

0 commit comments

Comments
 (0)