Skip to content

Commit e1e6660

Browse files
committed
Handle popup staying open for videoID changes
1 parent 05fa9ff commit e1e6660

1 file changed

Lines changed: 21 additions & 9 deletions

File tree

src/popup/PopupComponent.tsx

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ interface LoadSegmentsProps extends SegmentsLoadedProps {
5050
interface SkipProfileRadioButtonsProps {
5151
selected: SkipProfileAction;
5252
setSelected: (s: SkipProfileAction, updateConfig: boolean) => void;
53-
5453
disabled: boolean;
54+
configID: ConfigurationID | null;
55+
videoID: string;
5556
}
5657

5758
interface SkipOptionActionComponentProps {
@@ -446,6 +447,10 @@ function SkipProfileButton(props: {videoID: string; setShowForceChannelCheckWarn
446447
const [menuOpen, setMenuOpen] = React.useState(false);
447448
const skipProfileSet = getSkipProfileIDForChannel() !== null;
448449

450+
React.useEffect(() => {
451+
setMenuOpen(false);
452+
}, [props.videoID]);
453+
449454
return (
450455
<>
451456
<label id="skipProfileButton"
@@ -476,7 +481,7 @@ function SkipProfileButton(props: {videoID: string; setShowForceChannelCheckWarn
476481

477482
{
478483
props.videoID &&
479-
<SkipProfileMenu open={menuOpen} />
484+
<SkipProfileMenu open={menuOpen} videoID={props.videoID} />
480485
}
481486
</>
482487
);
@@ -496,7 +501,7 @@ const skipProfileOptions: SkipProfileOption[] = [{
496501
active: () => getSkipProfileIDForChannel() !== null
497502
}];
498503

499-
function SkipProfileMenu(props: {open: boolean}): JSX.Element {
504+
function SkipProfileMenu(props: {open: boolean; videoID: string}): JSX.Element {
500505
const [configID, setConfigID] = React.useState<ConfigurationID | null>(null);
501506
const [selectedSkipProfileAction, setSelectedSkipProfileAction] = React.useState<SkipProfileAction>(null);
502507
const [allSkipProfiles, setAllSkipProfiles] = React.useState(Object.entries(Config.local!.skipProfiles));
@@ -511,10 +516,10 @@ function SkipProfileMenu(props: {open: boolean}): JSX.Element {
511516
alert(chrome.i18n.getMessage("channelDataNotFound") + " https://github.com/ajayyy/SponsorBlock/issues/753");
512517
}
513518
}
514-
515-
setConfigID(getSkipProfileID());
516519
}
517-
}, [props.open]);
520+
521+
setConfigID(getSkipProfileID());
522+
}, [props.open, props.videoID]);
518523

519524
React.useEffect(() => {
520525
Config.configLocalListeners.push(() => {
@@ -582,6 +587,8 @@ function SkipProfileMenu(props: {open: boolean}): JSX.Element {
582587
setSelectedSkipProfileAction(s);
583588
}}
584589
disabled={configID === null}
590+
configID={configID}
591+
videoID={props.videoID}
585592
/>
586593
</div>
587594
</div>
@@ -592,15 +599,20 @@ function SkipProfileRadioButtons(props: SkipProfileRadioButtonsProps): JSX.Eleme
592599
const result: JSX.Element[] = [];
593600

594601
React.useEffect(() => {
595-
if (props.selected === null) {
602+
if (props.configID === null) {
603+
props.setSelected(null, false);
604+
} else {
596605
for (const option of skipProfileOptions) {
597606
if (option.active()) {
598-
props.setSelected(option.name, false);
607+
if (props.selected !== option.name) {
608+
props.setSelected(option.name, false);
609+
}
610+
599611
return;
600612
}
601613
}
602614
}
603-
}, [props.selected]);
615+
}, [props.configID, props.videoID]);
604616

605617
let alreadySelected = false;
606618
for (const option of skipProfileOptions) {

0 commit comments

Comments
 (0)