-
Notifications
You must be signed in to change notification settings - Fork 1
[feat] 리뷰검색 api 연결 #90
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
Merged
The head ref may contain hidden characters: "feat/#77/\uD6C4\uAE30\uAC80\uC0C9-api\uC5F0\uACB0"
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,59 +1,92 @@ | ||
| import { useState } from 'react'; | ||
| import { useNavigate } from 'react-router-dom'; | ||
| import {SearchInput, Badge, BottomNavigation} from '@/components' | ||
| const initialKeywords = [ | ||
| '뭔가검색했겠지...', '뭐가있지', '아무거나', | ||
| '두줄은', '채워야되니까', '일단써보기' | ||
| ]; | ||
| import { useState, useEffect } from 'react'; | ||
| import { useNavigate } from 'react-router-dom'; | ||
| import { SearchInput, Badge, BottomNavigation } from '@/components'; | ||
| import api from '@/api/api'; | ||
|
|
||
| type Keyword = { | ||
| content: string; | ||
| }; | ||
|
|
||
| export default function ReviewSearchPage() { | ||
| const [search, setSearch] = useState(''); | ||
| const [recentKeywords, setRecentKeywords] = useState(initialKeywords); | ||
| const navigate = useNavigate(); | ||
| const [recentKeywords, setRecentKeywords] = useState<Keyword[]>([]); | ||
| const navigate = useNavigate(); | ||
|
|
||
| const handleRemove = (index: number) => { | ||
| setRecentKeywords(prev => prev.filter((_, i) => i !== index)); | ||
| }; | ||
| useEffect(() => { | ||
| const fetchRecentKeywords = async () => { | ||
| try { | ||
| const res = await api.get('/search'); | ||
|
|
||
| if (res.data?.success && Array.isArray(res.data.data)) { | ||
| setRecentKeywords(res.data.data); | ||
| } else { | ||
| console.warn('유효하지 않은 검색어 응답:', res.data); | ||
| setRecentKeywords([]); | ||
| } | ||
| } catch (error) { | ||
| console.error('최근 검색어 조회 실패', error); | ||
| setRecentKeywords([]); | ||
| } | ||
| }; | ||
|
|
||
| const handleSearch = () => { | ||
| fetchRecentKeywords(); | ||
| }, []); | ||
|
|
||
| const handleSearch = () => { | ||
| if (!search.trim()) { | ||
| alert('검색어를 입력해주세요.'); | ||
| return; | ||
| } | ||
| navigate(`/search/result?query=${search}`); | ||
|
|
||
| navigate(`/search/result?query=${encodeURIComponent(search)}`); | ||
| }; | ||
|
|
||
| const handleRemove = async (index: number) => { | ||
| const keyword = recentKeywords[index].content; | ||
|
|
||
| try { | ||
| await api.delete('/search', { | ||
| params: { keyword }, | ||
| }); | ||
| setRecentKeywords((prev) => prev.filter((_, i) => i !== index)); | ||
| } catch (error) { | ||
| console.error('검색어 삭제 실패', error); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <div className="relative flex justify-center min-h-screen text-white "> | ||
| return ( | ||
| <div className="relative flex justify-center min-h-screen text-white"> | ||
| <div className="w-full max-w-[400px] px-4 pt-4 pb-20"> | ||
| <SearchInput | ||
| value={search} | ||
| onChange={setSearch} | ||
| placeholder="검색어를 입력해주세요" | ||
| onSearch={handleSearch} | ||
| onSearch={handleSearch} | ||
| /> | ||
|
|
||
| <div className="mt-6"> | ||
| <h2 className="mb-2 text-title-3">최근 검색어</h2> | ||
| <div className="flex flex-wrap gap-2"> | ||
| {recentKeywords.map((word, index) => ( | ||
| <Badge | ||
| key={index} | ||
| type="removable" | ||
| onRemove={() => handleRemove(index)} | ||
| > | ||
| {word} | ||
| </Badge> | ||
| ))} | ||
| {recentKeywords.length > 0 ? ( | ||
| recentKeywords.map((wordObj, index) => ( | ||
| <Badge | ||
| key={index} | ||
| type="removable" | ||
| onRemove={() => handleRemove(index)} | ||
| > | ||
| {wordObj.content} | ||
| </Badge> | ||
| )) | ||
| ) : ( | ||
| <p className="text-body-3 text-gray-400">최근 검색어가 없습니다.</p> | ||
| )} | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div className="fixed bottom-0 left-1/2 w-full max-w-[430px] -translate-x-1/2"> | ||
| <BottomNavigation /> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
영화관 목록은 api로 가져와야할 것 같아요..ㅠㅠ 피그마에는 일부만 나와있어서 ..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵 최대한수정해보겠습니다!