Skip to content

Commit

Permalink
[๐Ÿฅ : feat] ๋‚ด๊ฐ€ ์ž‘์„ฑํ•œ ๊ธ€ ๋ชฉ๋ก ๋ณด๊ธฐ
Browse files Browse the repository at this point in the history
- where('userId', '==', user?.uid), ์ฟผ๋ฆฌ๋ฅผ ์›ํ™œํ•˜๊ฒŒ ์ ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š”, ์ด๋Ÿฐ ํ•„ํ„ฐ๋ง์ด ์ ์šฉ๋  ๊ฑฐ๋ผ๊ณ  firestore์— ์•Œ๋ ค์ฃผ๋Š” ๊ณผ์ •์ด ํ•„์š”ํ•จ. ์ฝ˜์†” ์—๋Ÿฌ๋ฅผ ํ†ตํ•ด ์—ฐ๊ฒฐ๋œ URL์—์„œ ๋ณตํ•ฉ ์ธ๋ฑ์Šค๋ฅผ ์ƒ์„ฑํ•ด์ฃผ์–ด์•ผ ํ•จ
- ๊ณตํ†ต์ ์œผ๋กœ ์ž์ฃผ ์‚ฌ์šฉ๋˜๋Š” ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๋ณ„๋„์˜ ์ปดํฌ๋„ŒํŠธ๋กœ ๋ถ„๋ฆฌ
  • Loading branch information
sryung1225 committed Dec 12, 2023
1 parent 550601b commit 1d657ff
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 11 deletions.
10 changes: 1 addition & 9 deletions src/components/timeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,7 @@ import { Unsubscribe } from 'firebase/auth';
import { db } from '../firebase.ts';
import Tweet from './tweet.tsx';
import * as S from '../styles/layout.ts';

export interface ITweet {
id: string;
userId: string;
userName: string;
tweet: string;
createdAt: number;
photo: string;
}
import ITweet from '../interfaces/ITweet.ts';

export default function Timeline() {
const [tweets, setTweets] = useState<ITweet[]>([]);
Expand Down
2 changes: 1 addition & 1 deletion src/components/tweet.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { deleteDoc, doc } from 'firebase/firestore';
import { deleteObject, ref } from 'firebase/storage';
import { auth, db, storage } from '../firebase.ts';
import { ITweet } from './timeline.tsx';
import ITweet from '../interfaces/ITweet.ts';
import FormattedDate from '../utils/formattedDate.tsx';
import * as S from '../styles/components/tweet.ts';

Expand Down
49 changes: 49 additions & 0 deletions src/components/user-timeline.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { useEffect, useState } from 'react';
import {
collection,
getDocs,
limit,
orderBy,
query,
where,
} from 'firebase/firestore';
import { auth, db } from '../firebase.ts';
import Tweet from './tweet.tsx';
import * as S from '../styles/layout.ts';
import ITweet from '../interfaces/ITweet.ts';

export default function UserTimeline() {
const user = auth.currentUser;
const [tweets, setTweets] = useState<ITweet[]>([]);
const fetchTweets = async () => {
const tweetsQuery = query(
collection(db, 'tweets'),
where('userId', '==', user?.uid),
orderBy('createdAt', 'desc'),
limit(25),
);
const snapshot = await getDocs(tweetsQuery);
const tweetList = snapshot.docs.map((doc) => {
const { userId, userName, tweet, createdAt, photo } = doc.data();
return {
userId,
userName,
tweet,
createdAt,
photo,
id: doc.id,
};
});
setTweets(tweetList);
};
useEffect(() => {
fetchTweets();
}, []);
return (
<S.UserTimeLineWrapper>
{tweets.map((tweet) => (
<Tweet key={tweet.id} {...tweet} />
))}
</S.UserTimeLineWrapper>
);
}
8 changes: 8 additions & 0 deletions src/interfaces/ITweet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default interface ITweet {
id: string;
userId: string;
userName: string;
tweet: string;
createdAt: number;
photo: string;
}
2 changes: 2 additions & 0 deletions src/routes/profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useState } from 'react';
import { getDownloadURL, ref, uploadBytes } from 'firebase/storage';
import { updateProfile } from 'firebase/auth';
import { auth, storage } from '../firebase.ts';
import UserTimeline from '../components/user-timeline.tsx';
import * as S from '../styles/profile.ts';
import { ReactComponent as IconUser } from '../assets/images/i-user.svg';

Expand Down Expand Up @@ -34,6 +35,7 @@ export default function Profile() {
accept="image/*"
/>
<S.Name>{user?.displayName ?? 'Anonymous'}</S.Name>
<UserTimeline />
</S.Wrapper>
);
}
4 changes: 4 additions & 0 deletions src/styles/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ export const TimeLineWrapper = styled.ul`
margin-top: 250px;
overflow-y: auto;
`;

export const UserTimeLineWrapper = styled.ul`
display: block;
`;
3 changes: 2 additions & 1 deletion src/styles/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export const Popup = styled.div`
justify-content: center;
width: calc(100vw - 100px);
max-width: 757px;
height: 728px;
height: calc(100vh - 100px);
max-height: 728px;
padding: 30px;
background-color: ${whiteColor};
border-radius: 10px;
Expand Down

0 comments on commit 1d657ff

Please sign in to comment.