Skip to content
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

[#557] [도서 검색] 최근 검색어 api 요청 #587

Merged
merged 2 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/apis/book/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ const bookAPI = {
publicApi.get<APIBestSellerRes>(
`/aladin-api?QueryType=Bestseller&Cover=Big`
),

storeRecentSearch: (queryKeyword: string) =>
publicApi.get(
`/service-api/books?page=1&pageSize=1&query=${queryKeyword}&isStoreRecent=true`
),
};

export default bookAPI;
10 changes: 8 additions & 2 deletions src/app/book/search/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { APIBook } from '@/types/book';

import useBookSearchQuery from '@/queries/book/useBookSearchQuery';
import { useRecentSearchListQuery } from '@/queries/book/useRecentSearchesQuery';
import bookAPI from '@/apis/book';

import SSRSafeSuspense from '@/components/SSRSafeSuspense';
import useDebounceValue from '@/hooks/useDebounce';
Expand Down Expand Up @@ -96,8 +97,13 @@ const BookSearchResult = ({ queryKeyword }: { queryKeyword: string }) => {
? bookSearchInfo.data.pages[0].totalCount
: 0;

const handleBookClick = ({ bookId }: { bookId: APIBook['bookId'] }) => {
router.push(`/book/${bookId}`);
const handleBookClick = async ({ bookId }: { bookId: APIBook['bookId'] }) => {
try {
await bookAPI.storeRecentSearch(queryKeyword);
router.push(`/book/${bookId}`);
} catch (error) {
console.error(error);
}
};

useEffect(() => {
Expand Down
Loading