Skip to content

Commit

Permalink
[๐Ÿฅ : feat] ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ url๋กœ ์ ‘๊ทผ ๋ฐ ์ƒˆ๋กœ๊ณ ์นจ ํ™œ์„ฑํ™” (#23)
Browse files Browse the repository at this point in the history
- before) ๊ฒ€์ƒ‰์ฐฝ์— ์ž…๋ ฅํ•œ ํ‚ค์›Œ๋“œ๋ฅผ atom์— ์ €์žฅํ•œ ๋’ค ๊ฐ€์ ธ์™€ ์‚ฌ์šฉํ•˜๋Š” ํ˜•ํƒœ์ด๊ธฐ ๋•Œ๋ฌธ์— ์ƒˆ๋กœ๊ณ ์นจํ•˜๊ฑฐ๋‚˜ url๋กœ ์ ‘๊ทผํ•˜๋Š” ๊ฒฝ์šฐ๋Š” ๊ฒฐ๊ณผ๋ฅผ ๋ถˆ๋Ÿฌ์˜ฌ ์ˆ˜ ์—†์—ˆ์Œ
- after) useLocation์„ ํ™œ์šฉํ•ด url์— ์ž…๋ ฅ๋œ ๊ฐ’์„ ์ €์žฅํ•ด atom๊ณผ ๋น„๊ตํ•˜๋ฉฐ ์‚ฌ์šฉ
- decodeURLComponent : ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ URL ๋””์ฝ”๋”ฉ ๋ฉ”์„œ๋“œ. ์•”ํ˜ธํ™”๋œ ํ•œ๊ธ€์„ ํ•ด๋…
- useParams๋Š” router๋กœ ๋ฐ”๋กœ ์—ฐ๊ฒฐ๋œ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์•„๋‹ˆ๋ฉด ํ™œ์šฉํ•  ์ˆ˜ ์—†์Œ์„ ์œ ์˜. ๋Œ€์‹ ์— useLocation์„ ์ฑ„ํƒํ•จ
  • Loading branch information
sryung1225 committed Dec 27, 2023
1 parent 8eedd32 commit e441194
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/components/search-result/search-timeline.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useEffect, useState } from 'react';
import { useLocation } from 'react-router-dom';
import {
collection,
getDocs,
Expand All @@ -7,16 +8,21 @@ import {
query,
where,
} from 'firebase/firestore';
import { useRecoilValue } from 'recoil';
import { db } from '@/firebase.ts';
import { useRecoilValue } from 'recoil';
import { searchKeywordAtom } from '@/atoms.tsx';
import Tweet from '@compo/home/tweet.tsx';
import ITweet from '@type/ITweet.ts';
import * as S from '@style/timeline.ts';

export default function SearchTimeline() {
const location = useLocation();
const [tweets, setTweets] = useState<ITweet[]>([]);
const searchKeyword = useRecoilValue(searchKeywordAtom);
const searchKeywordFromLocation = decodeURIComponent(
location.search.slice(7),
);
const searchKeywordAtomValue = useRecoilValue(searchKeywordAtom);
const searchKeyword = searchKeywordFromLocation || searchKeywordAtomValue;
const fetchTweets = async () => {
const tweetsQuery = query(
collection(db, 'tweets'),
Expand Down Expand Up @@ -50,6 +56,8 @@ export default function SearchTimeline() {
))}
</S.TimelineWrapper>
) : (
<S.Text>๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.</S.Text>
<S.Text>
[<span>{searchKeyword}</span>] ์— ๋Œ€ํ•œ ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.
</S.Text>
);
}
5 changes: 5 additions & 0 deletions src/styles/timeline.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import styled from 'styled-components';
import { primaryColor } from '@style/global.ts';

export const TimelineWrapper = styled.ul`
display: block;
Expand All @@ -9,4 +10,8 @@ export const TimelineWrapper = styled.ul`
export const Text = styled.p`
margin: 20px 0;
text-align: center;
span {
color: ${primaryColor};
font-weight: 600;
}
`;

0 comments on commit e441194

Please sign in to comment.