diff --git a/src/app/(default)/track/[id]/[[...slug]]/page.tsx b/src/app/(default)/track/[id]/[[...slug]]/page.tsx
index 13c6c45..b34f531 100644
--- a/src/app/(default)/track/[id]/[[...slug]]/page.tsx
+++ b/src/app/(default)/track/[id]/[[...slug]]/page.tsx
@@ -61,7 +61,11 @@ export default async function TrackPage({ params: paramsFromProps }: Props) {
>
}
>
-
+
diff --git a/src/app/(default)/tv/[id]/[[...slug]]/page.tsx b/src/app/(default)/tv/[id]/[[...slug]]/page.tsx
index e1e367c..3233f6f 100644
--- a/src/app/(default)/tv/[id]/[[...slug]]/page.tsx
+++ b/src/app/(default)/tv/[id]/[[...slug]]/page.tsx
@@ -157,11 +157,11 @@ export default async function TvSeriesDetailsPage({
}
+ fallback={
}
>
-
+
-
+
diff --git a/src/components/Buttons/ActionButtons.tsx b/src/components/Buttons/ActionButtons.tsx
index a6e6141..5ff7533 100644
--- a/src/components/Buttons/ActionButtons.tsx
+++ b/src/components/Buttons/ActionButtons.tsx
@@ -14,16 +14,20 @@ import {
} from '@/lib/tmdb';
import { type TvSeries } from '@/types/tv-series';
+import ActionButtonsProvider from './ActionButtonsProvider';
import AddButton from './AddButton';
+import ContextMenuButton from './ContextMenuButton';
import LikeButton from './LikeButton';
import WatchButton from './WatchButton';
export default async function ActionButtons({
id,
showWatchButton = true,
+ showContextMenuButton = true,
}: Readonly<{
id: number | string;
showWatchButton?: boolean;
+ showContextMenuButton?: boolean;
}>) {
const tvSeries = (await cachedTvSeries(id)) as TvSeries;
const shouldShowWatchButton =
@@ -111,19 +115,28 @@ export default async function ActionButtons({
const isWatchlisted = await isInWatchlist(payload);
return (
- <>
+
{shouldShowWatchButton && }
-
-
- >
+
+
+ {showContextMenuButton && (
+
+ )}
+
);
}
return (
- <>
+
{shouldShowWatchButton && }
- >
+ {showContextMenuButton && (
+
+ )}
+
);
}
diff --git a/src/components/Buttons/ActionButtonsProvider.tsx b/src/components/Buttons/ActionButtonsProvider.tsx
new file mode 100644
index 0000000..3f521b4
--- /dev/null
+++ b/src/components/Buttons/ActionButtonsProvider.tsx
@@ -0,0 +1,48 @@
+'use client';
+
+import {
+ createContext,
+ useContext,
+ useState,
+ type PropsWithChildren,
+} from 'react';
+
+type State = Readonly<{
+ isFavorited: boolean;
+ isWatchlisted: boolean;
+}>;
+
+const ActionButtonsContext = createContext<
+ [State, (action: State | ((prevState: State) => State)) => void] | null
+>(null);
+
+export const ActionButtonsProvider = ({
+ children,
+ isFavorited,
+ isWatchlisted,
+}: PropsWithChildren & State) => {
+ const state = useState({
+ isFavorited,
+ isWatchlisted,
+ });
+
+ return (
+
+ {children}
+
+ );
+};
+
+export const useActionButtons = () => {
+ const context = useContext(ActionButtonsContext);
+
+ if (!context) {
+ throw new Error(
+ `useActionButtons must be used within `,
+ );
+ }
+
+ return context;
+};
+
+export default ActionButtonsProvider;
diff --git a/src/components/Buttons/AddButton.tsx b/src/components/Buttons/AddButton.tsx
index 4211a3b..97657ff 100644
--- a/src/components/Buttons/AddButton.tsx
+++ b/src/components/Buttons/AddButton.tsx
@@ -1,23 +1,25 @@
'use client';
-import { useCallback, useState, useTransition } from 'react';
+import { useCallback, useTransition } from 'react';
import { motion } from 'framer-motion';
+import { useActionButtons } from './ActionButtonsProvider';
import CircleButton from './CircleButton';
export default function AddButton({
- isActive: isActiveFromProps = false,
action,
}: Readonly<{
- isActive?: boolean;
action: (value: boolean, listType: 'favorites' | 'watchlist') => void;
}>) {
- const [isActive, setIsActive] = useState(isActiveFromProps);
+ const [{ isWatchlisted }, setState] = useActionButtons();
const [isPending, startTransition] = useTransition();
const handleOnClick = useCallback(
(value: boolean) => {
- setIsActive(value);
+ setState((prevState) => ({
+ ...prevState,
+ isWatchlisted: value,
+ }));
startTransition(async () => {
try {
await action(value, 'watchlist');
@@ -26,21 +28,21 @@ export default function AddButton({
}
});
},
- [action],
+ [action, setState],
);
return (