-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from nnivxix/feat/watchlist
Feat/watchlist
- Loading branch information
Showing
28 changed files
with
1,407 additions
and
783 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,24 +1,26 @@ | ||
import "./App.css"; | ||
|
||
function App() { | ||
return ( | ||
<ThemeProvider defaultTheme="dark" storageKey="vilm-theme"> | ||
<AccountProvider> | ||
<Router> | ||
<Navbar /> | ||
<Routes> | ||
<Route path="/" element={<Home />} /> | ||
<Route path="/show/tv/:id" element={<Tv />} /> | ||
<Route path="/show/movie/:id" element={<Movie />} /> | ||
<Route path="/search" element={<Search />} /> | ||
<Route path="/setting" element={<Setting />} /> | ||
<Route path="*" element={<NotFound />} /> | ||
</Routes> | ||
<Toaster /> | ||
</Router> | ||
</AccountProvider> | ||
</ThemeProvider> | ||
); | ||
return ( | ||
<ThemeProvider defaultTheme="dark" storageKey="vilm-theme"> | ||
<AccountProvider> | ||
<Router> | ||
<Navbar /> | ||
<Routes> | ||
<Route path="/" element={<Home />} /> | ||
<Route path="/show/tv/:id" element={<Tv />} /> | ||
<Route path="/show/movie/:id" element={<Movie />} /> | ||
<Route path="/search" element={<Search />} /> | ||
<Route path="/setting" element={<Setting />} /> | ||
<Route path="/watchlist/movie" element={<Movies />} /> | ||
<Route path="/watchlist/tv" element={<TvShows />} /> | ||
<Route path="*" element={<NotFound />} /> | ||
</Routes> | ||
<Toaster /> | ||
</Router> | ||
</AccountProvider> | ||
</ThemeProvider> | ||
); | ||
} | ||
|
||
export default App; |
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,40 @@ | ||
import type { AccountStates } from '@/types/response'; | ||
import { ResponseMessage } from '@/utils/$fetch'; | ||
|
||
interface Props { | ||
states: AccountStates; | ||
type: 'movie' | 'tv'; | ||
mediaId: number | string; | ||
} | ||
|
||
export default function AddToWatchlistButton({ states, type, mediaId }: Props) { | ||
const { account } = useAccount(); | ||
const { toast } = useToast(); | ||
const [isWatchlisted, setIsWatchlisted] = useState(states.watchlist) | ||
const addToWatchlist = async () => { | ||
try { | ||
const { data } = await $fetch<ResponseMessage>(`/account/${account?.id}/watchlist`, { | ||
method: 'POST', | ||
body: { | ||
"media_type": type, | ||
"media_id": mediaId, | ||
"watchlist": isWatchlisted === true ? false : true, | ||
} | ||
}); | ||
setIsWatchlisted(!isWatchlisted); | ||
|
||
toast({ | ||
description: data.status_message | ||
}) | ||
} catch (e) { | ||
console.error(e) | ||
} | ||
}; | ||
|
||
|
||
return ( | ||
<Button className='lg:col-span-1 col-span-full' onClick={addToWatchlist} variant={isWatchlisted ? 'secondary' : 'default'} > | ||
{isWatchlisted === true ? 'Remove from' : 'Add to'} Watchlist | ||
</Button> | ||
) | ||
} |
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,40 @@ | ||
import type { ComponentPropsWithRef } from "react"; | ||
|
||
export interface SimpleBaseMedia { | ||
adult: boolean; | ||
backdrop_path: string; | ||
genre_ids: number[]; | ||
id: number; | ||
original_language: string; | ||
overview: string; | ||
popularity: number; | ||
poster_path: string; | ||
vote_average: number; | ||
vote_count: number; | ||
} | ||
|
||
|
||
interface BackdropCardProps<T> extends ComponentPropsWithRef<'div'> { | ||
media: T; | ||
title: string; | ||
} | ||
|
||
export default function BackdropCard<T extends SimpleBaseMedia>({ media, title, ...props }: BackdropCardProps<T>) { | ||
const isMovieType = Object.prototype.hasOwnProperty.call(media, 'video'); | ||
|
||
return ( | ||
<div {...props} className={`${props.className} rounded-md group transition-transform overflow-clip hover:scale-110`}> | ||
<RImage src={imageUrl({ | ||
path: media.backdrop_path, | ||
size: 'w300', | ||
type: 'backdrop' | ||
})} | ||
type="backdrop" | ||
alt={media.overview} | ||
/> | ||
<div className="block lg:hidden group-hover:block"> | ||
<Link to={`/show/${isMovieType ? 'movie' : 'tv'}/${media.id}`}>{title}</Link> | ||
</div> | ||
</div> | ||
) | ||
} |
Oops, something went wrong.