-
Notifications
You must be signed in to change notification settings - Fork 0
feat: 관심 페이지 및 좋아요 기능 구현 #118
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
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c4fe3ef
feat: 관심 페이지 퍼블리싱 및 조회 api 연동
hyeeuncho 9881d58
feat: 좋아요 생성/삭제 api 연동
hyeeuncho 86dc43f
refact: Optimistic UI 적용
hyeeuncho 0d4ed2c
fix: EventDeatailsPage url 수정
hyeeuncho a8c86b6
refact: bookmarked, bookmarkId 필드 추가
hyeeuncho b8f0dac
refact: 예약 메일 발송 로직 변경. targetType설정
hyeeuncho 42d9b50
refact: bookmarkId 추가 및 예약 메일 조회 필드 targetName으로 변경
hyeeuncho 5e53204
refact: bookmark 등록/삭제 실패 시 에러 메세지 추가
hyeeuncho 12018b9
feat: bookmark page에 이벤트 상세페이지 이동 연결
hyeeuncho c15c60b
refact: 예약 메일 및 이벤트 상세 페이지 시간 형식 변경
hyeeuncho 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
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 |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import { axiosClient } from "../../../shared/types/api/http-client" | ||
| import { BookmarkResponse } from "../model/bookmarkInformation"; | ||
|
|
||
| export const readBookmark = async (): Promise<BookmarkResponse[]> => { | ||
| const response = await axiosClient.get<{result:BookmarkResponse[]}>('/events/{eventId}/bookmark'); | ||
| return response.data.result; | ||
| } | ||
hyeeuncho marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| export const createBookmark = async (eventId: number) => { | ||
| const response = await axiosClient.post(`/events/${eventId}/bookmark`); | ||
| return response.data; | ||
| } | ||
|
|
||
| export const deleteBookmark = async (eventId: number, bookmarkId: number) => { | ||
| const response = await axiosClient.delete(`/events/${eventId}/bookmark/${bookmarkId}`); | ||
| return response.data; | ||
| } | ||
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 |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| export interface BookmarkResponse { | ||
| id: number; | ||
| bannerImageUrl: string; | ||
| title: string; | ||
| hostChannelName: string; | ||
| startDate: string; | ||
| address: string; | ||
| onlineType: 'ONLINE' | 'OFFLINE'; | ||
| hashtags: string[]; | ||
| remainDays: string; | ||
| } |
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 |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query" | ||
| import { BookmarkResponse } from "./bookmarkInformation" | ||
| import { createBookmark, deleteBookmark, readBookmark } from "../api/bookmark" | ||
|
|
||
| export const useBookmarks = () => { | ||
| return useQuery<BookmarkResponse[]>({ | ||
| queryKey: ['bookmarks'], | ||
| queryFn: readBookmark, | ||
| }) | ||
| } | ||
hyeeuncho marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| export const useCreateBookmark = () => { | ||
| const queryClient = useQueryClient(); | ||
| return useMutation({ | ||
| mutationFn: createBookmark, | ||
| // Optimistic | ||
| onMutate: async (eventId: number) => { | ||
| await queryClient.cancelQueries({ queryKey: ['eventDetail', eventId] }); | ||
| const previous = queryClient.getQueryData(['eventDetail', eventId]); | ||
|
|
||
| queryClient.setQueryData(['eventDetail', eventId], (old: any) => ({ | ||
| ...old, | ||
| bookmarked: true, | ||
| })); | ||
|
|
||
| return { previous }; | ||
| }, | ||
| onError: (_err, eventId, context) => { | ||
| if (context?.previous) { | ||
| queryClient.setQueryData(['eventDetail', eventId], context.previous); | ||
| alert("좋아요 등록에 실패했습니다. 잠시후 다시 시도해 주세요."); | ||
| } | ||
| }, | ||
| onSettled: (_data, _error, eventId) => { | ||
| queryClient.invalidateQueries({ queryKey: ['eventDetail', eventId] }); | ||
| }, | ||
| }) | ||
| } | ||
| export const useDeleteBookmark = () => { | ||
| const queryClient = useQueryClient(); | ||
| return useMutation({ | ||
| mutationFn: (params: { eventId: number; bookmarkId: number }) => | ||
| deleteBookmark(params.eventId, params.bookmarkId), | ||
| // Optimistic | ||
| onMutate: async ({ eventId }) => { | ||
| await queryClient.cancelQueries({ queryKey: ['eventDetail', eventId] }); | ||
| const previous = queryClient.getQueryData(['eventDetail', eventId]); | ||
|
|
||
| queryClient.setQueryData(['eventDetail', eventId], (old: any) => ({ | ||
| ...old, | ||
| bookmarked: false, | ||
| })); | ||
|
|
||
| return { previous }; | ||
| }, | ||
| onError: (_err, { eventId }, context) => { | ||
| if (context?.previous) { | ||
| queryClient.setQueryData(['eventDetail', eventId], context.previous); | ||
| alert("좋아요 삭제에 실패했습니다. 잠시후 다시 시도해 주세요."); | ||
| } | ||
| }, | ||
| onSettled: (_data, _error, { eventId }) => { | ||
| queryClient.invalidateQueries({ queryKey: ['eventDetail', eventId] }); | ||
| }, | ||
| }); | ||
| } | ||
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 |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import { useNavigate } from "react-router-dom"; | ||
| import Header from "../../../../design-system/ui/Header"; | ||
| import searchIcon from '../../../../design-system/icons/Search.svg'; | ||
| import BottomBar from "../../../widgets/main/ui/BottomBar"; | ||
| import EventCard from "../../../shared/ui/EventCard"; | ||
| import { useBookmarks } from "../../../features/bookmark/model/useBookmarkHook"; | ||
|
|
||
| const BookmarkPage = () => { | ||
| const navigate = useNavigate(); | ||
| const { data } = useBookmarks(); | ||
hyeeuncho marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return ( | ||
| <div className="relative"> | ||
| <Header | ||
| centerContent="관심 있는 이벤트" | ||
| rightContent={ | ||
| <button type="button" className="w-5 z-10" onClick={() => navigate('/search')}> | ||
| <img src={searchIcon} alt="Search Icon" /> | ||
| </button> | ||
| } | ||
| /> | ||
| <div className="grid grid-cols-2 gap-4 mx-5 mt-3 md:grid-cols-2 lg:grid-cols-2 z-50"> | ||
| {data?.map(event => ( | ||
| <EventCard | ||
| id={event.id} | ||
| key={event.id} | ||
| img={event.bannerImageUrl} | ||
| eventTitle={event.title} | ||
| dDay={event.remainDays} | ||
| host={event.hostChannelName} | ||
| eventDate={event.startDate} | ||
| location={event.onlineType} | ||
| hashtags={event.hashtags} | ||
| onClick={() => navigate(`/event-details/${event.id}`)} | ||
| /> | ||
| ))} | ||
| </div> | ||
| <BottomBar /> | ||
| </div> | ||
| ); | ||
| } | ||
| export default BookmarkPage; | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.