-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
237 additions
and
34 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
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,17 @@ | ||
import { QueryFunction } from '@tanstack/react-query' | ||
|
||
import { Bookmark } from '@/entities/local_movie/model' | ||
|
||
export const getMovieBookMark: QueryFunction<Bookmark, [string, string, string]> = async ({ queryKey }) => { | ||
const [_1, _2, movieId] = queryKey | ||
const res = await fetch(`${process.env.NEXT_PUBLIC_LOCAL_BASE_URL}/bookmark/${movieId}`, { | ||
credentials: 'include', | ||
cache: 'no-store', | ||
}) | ||
|
||
if (!res.ok) { | ||
throw new Error('Failed to fetch data') | ||
} | ||
|
||
return res.json() | ||
} |
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 @@ | ||
export { getMovieBookMark } from './getMovieBookMark' |
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,3 @@ | ||
export type Bookmark = { | ||
isLike: boolean | ||
} |
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 @@ | ||
export type { Bookmark } from './bookmark' |
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,45 @@ | ||
'use client' | ||
|
||
import StarRoundedIcon from '@mui/icons-material/StarRounded' | ||
import { IconButton } from '@mui/material' | ||
import { useSuspenseQuery } from '@tanstack/react-query' | ||
import { useMemo } from 'react' | ||
|
||
import { getMovieBookMark } from '@/entities/local_movie/api' | ||
import { DeleteMovieDisLikeContainer, PostMovieLikeContainer } from '@/features/bookmark/ui' | ||
import { LOCAL_QUERY_KEY } from '@/shared/constants' | ||
|
||
type Props = { | ||
movieId: string | ||
size: 'small' | 'medium' | ||
} | ||
|
||
export function MovieBookMarkButton({ movieId, size }: Props) { | ||
const { data } = useSuspenseQuery({ | ||
queryKey: LOCAL_QUERY_KEY.movieBookMark(movieId), | ||
queryFn: getMovieBookMark, | ||
}) | ||
|
||
const [width, height, right, top] = useMemo(() => { | ||
switch (size) { | ||
case 'medium': | ||
return [100, 100, 10, 10] | ||
case 'small': | ||
return [40, 40, 0, 20] | ||
} | ||
}, [size]) | ||
|
||
return ( | ||
<IconButton sx={{ position: 'absolute', zIndex: 10, right, top }}> | ||
{data?.isLike ? ( | ||
<DeleteMovieDisLikeContainer movieId={movieId}> | ||
<StarRoundedIcon sx={{ color: '#ffff00', width, height }} /> | ||
</DeleteMovieDisLikeContainer> | ||
) : ( | ||
<PostMovieLikeContainer movieId={movieId}> | ||
<StarRoundedIcon sx={{ color: '#5F6368', width, height }} /> | ||
</PostMovieLikeContainer> | ||
)} | ||
</IconButton> | ||
) | ||
} |
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 @@ | ||
export { MovieBookMarkButton } from './MovieBookMarkButton' |
16 changes: 16 additions & 0 deletions
16
src/entities/local_movie/ui/movie-book-mark-button.module.scss
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,16 @@ | ||
.button { | ||
position: absolute; | ||
top: 10px; | ||
right: 10px; | ||
z-index: 10; | ||
} | ||
|
||
.smallButton { | ||
width: 40px; | ||
aspect-ratio: 1/1; | ||
} | ||
|
||
.mediumButton{ | ||
width: 80px; | ||
aspect-ratio: 1/1; | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { UseDeleteMovieBookMark } from './useDeleteMovieBookMark' | ||
export { UsePostMovieBookMark } from './usePostMovieBookMark' |
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,23 @@ | ||
import { useMutation, useQueryClient } from '@tanstack/react-query' | ||
|
||
import { deleteMovieBookMark } from '@/features/bookmark/lib' | ||
import { LOCAL_QUERY_KEY } from '@/shared/constants' | ||
|
||
export function UseDeleteMovieBookMark() { | ||
const queryClient = useQueryClient() | ||
|
||
return useMutation({ | ||
mutationFn: (movieId: string) => deleteMovieBookMark(movieId), | ||
onMutate: movieId => { | ||
queryClient.setQueryData(LOCAL_QUERY_KEY.movieBookMark(movieId), (prevData: { isLike: boolean }) => { | ||
return { isLike: !prevData.isLike } | ||
}) | ||
return movieId | ||
}, | ||
onError: async (_, movieId) => { | ||
await queryClient.invalidateQueries({ | ||
queryKey: LOCAL_QUERY_KEY.movieBookMark(movieId), | ||
}) | ||
}, | ||
}) | ||
} |
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,22 @@ | ||
import { useMutation, useQueryClient } from '@tanstack/react-query' | ||
|
||
import { postMovieBookMark } from '@/features/bookmark/lib' | ||
import { LOCAL_QUERY_KEY } from '@/shared/constants' | ||
|
||
export function UsePostMovieBookMark(movieId: string) { | ||
const queryClient = useQueryClient() | ||
|
||
return useMutation({ | ||
mutationFn: () => postMovieBookMark(movieId), | ||
onMutate: () => { | ||
queryClient.setQueryData(LOCAL_QUERY_KEY.movieBookMark(movieId), (prevData: { isLike: boolean }) => { | ||
return { isLike: !prevData.isLike } | ||
}) | ||
}, | ||
onError: () => { | ||
queryClient.invalidateQueries({ | ||
queryKey: LOCAL_QUERY_KEY.movieBookMark(movieId), | ||
}) | ||
}, | ||
}) | ||
} |
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,13 @@ | ||
export const deleteMovieBookMark = async (movieId: string) => { | ||
const res = await fetch(`${process.env.NEXT_PUBLIC_LOCAL_BASE_URL}/bookmark/${movieId}`, { | ||
method: 'DELETE', | ||
credentials: 'include', | ||
cache: 'no-store', | ||
}) | ||
|
||
if (!res.ok) { | ||
throw new Error('Failed to fetch data') | ||
} | ||
|
||
return res.json() | ||
} |
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,2 @@ | ||
export { deleteMovieBookMark } from './deleteMovieBookMark' | ||
export { postMovieBookMark } from './postMovieBookMark' |
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,14 @@ | ||
export const postMovieBookMark = async (movieId: string) => { | ||
const res = await fetch(`${process.env.NEXT_PUBLIC_LOCAL_BASE_URL}/bookmark`, { | ||
method: 'POST', | ||
credentials: 'include', | ||
cache: 'no-store', | ||
body: JSON.parse(movieId), | ||
}) | ||
|
||
if (!res.ok) { | ||
throw new Error('Failed to fetch data') | ||
} | ||
|
||
return res.json() | ||
} |
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,19 @@ | ||
'use client' | ||
|
||
import { PropsWithChildren } from 'react' | ||
|
||
import { UseDeleteMovieBookMark } from '@/features/bookmark/hook' | ||
|
||
type Props = { | ||
movieId: string | ||
} | ||
|
||
export function DeleteMovieDisLikeContainer({ movieId, children }: PropsWithChildren<Props>) { | ||
const { mutateAsync } = UseDeleteMovieBookMark() | ||
|
||
const onClick = async () => { | ||
await mutateAsync(movieId) | ||
} | ||
|
||
return <div onClick={onClick}>{children}</div> | ||
} |
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,2 @@ | ||
export { DeleteMovieDisLikeContainer } from './deleteMovieDisLikeContainer' | ||
export { PostMovieLikeContainer } from './postMovieLikeContainer' |
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,18 @@ | ||
'use client' | ||
|
||
import { PropsWithChildren } from 'react' | ||
|
||
import { UsePostMovieBookMark } from '@/features/bookmark/hook' | ||
|
||
type Props = { | ||
movieId: string | ||
} | ||
|
||
export function PostMovieLikeContainer({ movieId, children }: PropsWithChildren<Props>) { | ||
const { mutateAsync } = UsePostMovieBookMark(movieId) | ||
|
||
const onClick = async () => { | ||
await mutateAsync() | ||
} | ||
return <div onClick={onClick}>{children}</div> | ||
} |
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,5 +1,5 @@ | ||
export { GENRES } from './GENRES' | ||
export { IMAGE_SIZE } from './IMAGE_SIZE' | ||
export { LANDING_TITLE } from './LANDING_TITLE' | ||
export { MOVIE_QUERY_KEY } from './QUERY_KEY' | ||
export { LOCAL_QUERY_KEY, MOVIE_QUERY_KEY } from './QUERY_KEY' | ||
export { SITE_PATH } from './SITE_PATH' |
Oops, something went wrong.