diff --git a/src/renderer/features/context-menu/context-menu-provider.tsx b/src/renderer/features/context-menu/context-menu-provider.tsx index 39732b44..29723e11 100644 --- a/src/renderer/features/context-menu/context-menu-provider.tsx +++ b/src/renderer/features/context-menu/context-menu-provider.tsx @@ -103,19 +103,7 @@ export const ContextMenuProvider = ({ children }: ContextMenuProviderProps) => { const { t } = useTranslation(); const [opened, setOpened] = useState(false); - const [contextMenuRef, setContextMenuRef] = useState(null); - const [ratingsRef, setRatingsRef] = useState(null); - const [rating, setRating] = useState(0); - - useEffect(() => { - setRating(0); - }, [opened]); - - const clickOutsideRef = useClickOutside( - () => setOpened(false), - ['mousedown', 'touchstart'], - [contextMenuRef, ratingsRef], - ); + const clickOutsideRef = useClickOutside(() => setOpened(false), ['mousedown', 'touchstart']); const viewport = useViewportSize(); const server = useCurrentServer(); @@ -132,6 +120,24 @@ export const ContextMenuProvider = ({ children }: ContextMenuProviderProps) => { yPos: 0, }); + const [rating, setRating] = useState(0); + + useEffect(() => { + if (opened && ctx.data.length > 0) { + if (ctx.data.length === 1) { + setRating(ctx.data[0].userRating ?? 0); + } else { + const firstRating = ctx.data[0].userRating ?? 0; + const allSameRating = ctx.data.every( + (item) => (item.userRating ?? 0) === firstRating, + ); + setRating(allSameRating ? firstRating : 0); + } + } else { + setRating(0); + } + }, [ctx.data, opened]); + const handlePlayQueueAdd = usePlayQueueAdd(); const navigate = useNavigate(); @@ -882,7 +888,7 @@ export const ContextMenuProvider = ({ children }: ContextMenuProviderProps) => { leftIcon: , onClick: () => {}, rightIcon: ( - + { handleUpdateRating(e); @@ -950,7 +956,7 @@ export const ContextMenuProvider = ({ children }: ContextMenuProviderProps) => { {opened && ( - + {ctx.menuItems?.map((item) => { return (