+ <>
+ {toggleWatchlist ? (
+
+
+
+ ) : (
+
+
+
+ )}
+ >
{title} added to watchlist successfully!',
+ watchlistDeleted:
+ '{title} Removed from watchlist successfully!',
+ watchlistError: 'Something went wrong try again.',
+ removefromwatchlist: 'Remove From Watchlist',
+ addtowatchlist: 'Add To Watchlist',
});
interface TvDetailsProps {
@@ -106,7 +122,12 @@ const TvDetails = ({ tv }: TvDetailsProps) => {
router.query.manage == '1' ? true : false
);
const [showIssueModal, setShowIssueModal] = useState(false);
+ const [isUpdating, setIsUpdating] = useState(false);
+ const [toggleWatchlist, setToggleWatchlist] = useState(
+ !tv?.onUserWatchlist
+ );
const { publicRuntimeConfig } = getConfig();
+ const { addToast } = useToasts();
const {
data,
@@ -302,6 +323,82 @@ const TvDetails = ({ tv }: TvDetailsProps) => {
return intl.formatMessage(messages.play4k, { mediaServerName: 'Jellyfin' });
}
+ const onClickWatchlistBtn = async (): Promise => {
+ setIsUpdating(true);
+
+ const res = await fetch('/api/v1/watchlist', {
+ method: 'POST',
+ headers: {
+ Accept: 'application/json',
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify({
+ tmdbId: tv?.id,
+ mediaType: MediaType.TV,
+ title: tv?.name,
+ }),
+ });
+
+ if (!res.ok) {
+ addToast(intl.formatMessage(messages.watchlistError), {
+ appearance: 'error',
+ autoDismiss: true,
+ });
+
+ setIsUpdating(false);
+ return;
+ }
+
+ const data = await res.json();
+
+ if (data) {
+ addToast(
+
+ {intl.formatMessage(messages.watchlistSuccess, {
+ title: tv?.name,
+ strong: (msg: React.ReactNode) => {msg},
+ })}
+ ,
+ { appearance: 'success', autoDismiss: true }
+ );
+ }
+
+ setIsUpdating(false);
+ setToggleWatchlist((prevState) => !prevState);
+ };
+
+ const onClickDeleteWatchlistBtn = async (): Promise => {
+ setIsUpdating(true);
+
+ const res = await fetch('/api/v1/watchlist/' + tv?.id, {
+ method: 'DELETE',
+ });
+
+ if (!res.ok) {
+ addToast(intl.formatMessage(messages.watchlistError), {
+ appearance: 'error',
+ autoDismiss: true,
+ });
+
+ setIsUpdating(false);
+ return;
+ }
+
+ if (res.status === 204) {
+ addToast(
+
+ {intl.formatMessage(messages.watchlistDeleted, {
+ title: tv?.name,
+ strong: (msg: React.ReactNode) => {msg},
+ })}
+ ,
+ { appearance: 'info', autoDismiss: true }
+ );
+ setIsUpdating(false);
+ setToggleWatchlist((prevState) => !prevState);
+ }
+ };
+
return (
{
+ <>
+ {toggleWatchlist ? (
+
+
+
+ ) : (
+
+
+
+ )}
+ >
{title} Removed from watchlist successfully!",
+ "components.MovieDetails.watchlistError": "Something went wrong try again.",
+ "components.MovieDetails.watchlistSuccess": "{title} added to watchlist successfully!",
"components.MovieDetails.watchtrailer": "Watch Trailer",
"components.NotificationTypeSelector.adminissuecommentDescription": "Get notified when other users comment on issues.",
"components.NotificationTypeSelector.adminissuereopenedDescription": "Get notified when issues are reopened by other users.",
@@ -1071,6 +1076,7 @@
"components.TvDetails.Season.somethingwentwrong": "Something went wrong while retrieving season data.",
"components.TvDetails.TvCast.fullseriescast": "Full Series Cast",
"components.TvDetails.TvCrew.fullseriescrew": "Full Series Crew",
+ "components.TvDetails.addtowatchlist": "Add To Watchlist",
"components.TvDetails.anime": "Anime",
"components.TvDetails.cast": "Cast",
"components.TvDetails.episodeCount": "{episodeCount, plural, one {# Episode} other {# Episodes}}",
@@ -1088,6 +1094,7 @@
"components.TvDetails.play4k": "Play 4K on {mediaServerName}",
"components.TvDetails.productioncountries": "Production {countryCount, plural, one {Country} other {Countries}}",
"components.TvDetails.recommendations": "Recommendations",
+ "components.TvDetails.removefromwatchlist": "Remove From Watchlist",
"components.TvDetails.reportissue": "Report an Issue",
"components.TvDetails.rtaudiencescore": "Rotten Tomatoes Audience Score",
"components.TvDetails.rtcriticsscore": "Rotten Tomatoes Tomatometer",
@@ -1100,6 +1107,9 @@
"components.TvDetails.streamingproviders": "Currently Streaming On",
"components.TvDetails.tmdbuserscore": "TMDB User Score",
"components.TvDetails.viewfullcrew": "View Full Crew",
+ "components.TvDetails.watchlistDeleted": "{title} Removed from watchlist successfully!",
+ "components.TvDetails.watchlistError": "Something went wrong try again.",
+ "components.TvDetails.watchlistSuccess": "{title} added to watchlist successfully!",
"components.TvDetails.watchtrailer": "Watch Trailer",
"components.UserList.accounttype": "Type",
"components.UserList.admin": "Admin",