-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Firebase 쿼리문μ μ΄μ©νλ κ²½μ° νκ³κ° μ‘΄μ¬ν΄ ν€μλλ‘ μμνλ λ¬Έμμ΄λ§ νμ κ°λ₯ (ex. "μ€λ" κ²μ => "μ€λ λν΄?" (O) "λνλ μ€λ?" (X) - νμλΌμΈμ μ΄μ©ν΄ κ²μμ΄κ° ν¬ν¨λ ν¬μ€ν λ§ λμ΄νλ search-timeline
- Loading branch information
1 parent
ed4848b
commit f9136dd
Showing
10 changed files
with
141 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { atom } from 'recoil'; | ||
|
||
export const searchKeywordAtom = atom({ | ||
key: 'searchKeyword', | ||
default: '', | ||
}); | ||
|
||
export const tmp = ''; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { | ||
collection, | ||
getDocs, | ||
limit, | ||
orderBy, | ||
query, | ||
where, | ||
} from 'firebase/firestore'; | ||
import { useRecoilValue } from 'recoil'; | ||
import { db } from '../firebase.ts'; | ||
import { searchKeywordAtom } from '../atoms.tsx'; | ||
import Tweet from './tweet.tsx'; | ||
import * as S from '../styles/timeline.ts'; | ||
import ITweet from '../interfaces/ITweet.ts'; | ||
|
||
export default function SearchTimeline() { | ||
const [tweets, setTweets] = useState<ITweet[]>([]); | ||
const searchKeyword = useRecoilValue(searchKeywordAtom); | ||
const fetchTweets = async () => { | ||
const tweetsQuery = query( | ||
collection(db, 'tweets'), | ||
orderBy('tweet'), | ||
where('tweet', '>=', searchKeyword), | ||
where('tweet', '<=', `${searchKeyword}\uf8ff`), | ||
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, | ||
}; | ||
}); | ||
tweetList.sort((a, b) => b.createdAt - a.createdAt); | ||
setTweets(tweetList); | ||
}; | ||
useEffect(() => { | ||
fetchTweets(); | ||
}, [searchKeyword]); | ||
return tweets.length !== 0 ? ( | ||
<S.TimelineWrapper> | ||
{tweets.map((tweet) => ( | ||
<Tweet key={tweet.id} {...tweet} /> | ||
))} | ||
</S.TimelineWrapper> | ||
) : ( | ||
<S.Text>κ²μ κ²°κ³Όκ° μμ΅λλ€.</S.Text> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
import SearchTimeline from '../components/search-timeline.tsx'; | ||
import WindowTop from '../components/window-top.tsx'; | ||
import * as W from '../styles/window.ts'; | ||
|
||
export default function SearchResult() { | ||
return null; | ||
return ( | ||
<W.Window> | ||
<WindowTop /> | ||
<SearchTimeline /> | ||
</W.Window> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,31 @@ | ||
import { styled } from 'styled-components'; | ||
import { Input } from './button.ts'; | ||
import { grayColor } from './global.ts'; | ||
|
||
export const Form = styled.form` | ||
position: relative; | ||
display: flex; | ||
flex-direction: column; | ||
gap: 10px; | ||
width: 100%; | ||
max-width: 500px; | ||
`; | ||
|
||
export const FormInput = styled(Input)``; | ||
export const FormInput = styled(Input)` | ||
padding-right: 50px; | ||
`; | ||
|
||
export const FormButton = styled.button` | ||
position: absolute; | ||
top: 3px; | ||
right: 3px; | ||
bottom: 3px; | ||
height: 37px; | ||
width: 37px; | ||
background-color: transparent; | ||
border-radius: 50%; | ||
border: none; | ||
svg { | ||
stroke: ${grayColor}; | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
import styled from 'styled-components'; | ||
|
||
const TimelineWrapper = styled.ul` | ||
export const TimelineWrapper = styled.ul` | ||
display: block; | ||
overflow-y: auto; | ||
`; | ||
|
||
export default TimelineWrapper; | ||
export const Text = styled.p` | ||
margin: 20px 0; | ||
text-align: center; | ||
`; |