Skip to content

Commit

Permalink
Move toggle info button logic into component
Browse files Browse the repository at this point in the history
  • Loading branch information
hanydd committed Sep 9, 2024
1 parent ed26da0 commit 11ae144
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
23 changes: 16 additions & 7 deletions src/components/playerButtons/InfoButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,29 @@ import Config from "../../config";
import PlayerButtonComponent from "./PlayerButtonComponent";

interface InfoButtonProps {
popupOpen: boolean;
infoCallback: () => void;
}

const InfoButtonComponent = forwardRef<HTMLButtonElement, InfoButtonProps>(function (
{ popupOpen = false, infoCallback },
ref
) {
const InfoButtonComponent = forwardRef<HTMLButtonElement, InfoButtonProps>(function ({ infoCallback }, ref) {
const [popupOpen, setPopupOpen] = React.useState(false);

React.useEffect(() => {
const handleShowInfoButton = () => setPopupOpen(false);
window.addEventListener("closePopupMenu", handleShowInfoButton);
return () => window.removeEventListener("closePopupMenu", handleShowInfoButton);
}, []);

function initialShowInfoButton() {
return !Config.config.hideInfoButtonPlayerControls && !document.URL.includes("/embed/");
}

function showInfoButton() {
return initialShowInfoButton();
return !popupOpen && initialShowInfoButton();
}

function handleInfoBUttonClick() {
setPopupOpen(true);
infoCallback();
}

return (
Expand All @@ -28,7 +37,7 @@ const InfoButtonComponent = forwardRef<HTMLButtonElement, InfoButtonProps>(funct
imageName="PlayerInfoIconSponsorBlocker.svg"
isDraggable={false}
show={showInfoButton()}
onClick={infoCallback}
onClick={handleInfoBUttonClick}
></PlayerButtonComponent>
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function PlayerButtonGroupComponent({

return (
<ConfigProvider theme={{ token: { colorPrimary: "#00aeec" }, algorithm: theme.darkAlgorithm }}>
<InfoButtonComponent popupOpen={false} infoCallback={infoCallback}></InfoButtonComponent>
<InfoButtonComponent infoCallback={infoCallback}></InfoButtonComponent>

{/* <PlayerButtonComponent
baseID="info"
Expand Down
9 changes: 2 additions & 7 deletions src/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2095,9 +2095,6 @@ function openInfoMenu() {

popupInitialised = false;

//hide info button
if (playerButtons.info) playerButtons.info.button.style.display = "none";

const popup = document.createElement("div");
popup.id = "sponsorBlockPopupContainer";

Expand Down Expand Up @@ -2134,10 +2131,8 @@ function closeInfoMenu() {

popup.remove();

// Show info button if it's not an embed
if (!document.URL.includes("/embed/") && playerButtons.info) {
playerButtons.info.button.style.display = "unset";
}
// show info button again
window.dispatchEvent(new Event("closePopupMenu"));
}

function clearSponsorTimes() {
Expand Down

0 comments on commit 11ae144

Please sign in to comment.