From 7ccdf6719516bbdbafa3db16c6570da9a119b1c7 Mon Sep 17 00:00:00 2001 From: felistachio Date: Sat, 20 Sep 2025 17:15:35 -0700 Subject: [PATCH 1/5] Set default tab to chapters if there are no segments --- src/popup/SegmentListComponent.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/popup/SegmentListComponent.tsx b/src/popup/SegmentListComponent.tsx index 8ea207e3..ce4559d1 100644 --- a/src/popup/SegmentListComponent.tsx +++ b/src/popup/SegmentListComponent.tsx @@ -47,8 +47,13 @@ export const SegmentListComponent = (props: SegmentListComponentProps) => { }, []); React.useEffect(() => { - setTab(SegmentListTab.Segments); - }, [props.videoID]); + const hasNonChapter = props.segments.find(seg => seg.actionType !== ActionType.Chapter) + if (!hasNonChapter && props.segments.length > 0) { + setTab(SegmentListTab.Chapter); + } else { + setTab(SegmentListTab.Segments); + } + }, [props.videoID, props.segments]); const tabFilter = (segment: SponsorTime) => { if (tab === SegmentListTab.Chapter) { From 9e501a5f667b93bcd42d0059d42b26ce3f599d18 Mon Sep 17 00:00:00 2001 From: felistachio Date: Sat, 20 Sep 2025 17:27:46 -0700 Subject: [PATCH 2/5] refactor --- src/popup/SegmentListComponent.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/popup/SegmentListComponent.tsx b/src/popup/SegmentListComponent.tsx index ce4559d1..6e0f62c5 100644 --- a/src/popup/SegmentListComponent.tsx +++ b/src/popup/SegmentListComponent.tsx @@ -47,11 +47,11 @@ export const SegmentListComponent = (props: SegmentListComponentProps) => { }, []); React.useEffect(() => { - const hasNonChapter = props.segments.find(seg => seg.actionType !== ActionType.Chapter) - if (!hasNonChapter && props.segments.length > 0) { - setTab(SegmentListTab.Chapter); - } else { + const hasSegments = props.segments.find(seg => seg.actionType !== ActionType.Chapter) + if (hasSegments) { setTab(SegmentListTab.Segments); + } else { + setTab(SegmentListTab.Chapter); } }, [props.videoID, props.segments]); From aa04ed7bf4262d03fa3f19a788d8bc2f7dea6533 Mon Sep 17 00:00:00 2001 From: felistachio Date: Sat, 20 Sep 2025 20:48:23 -0700 Subject: [PATCH 3/5] Fix: prevent auto-switch tab on refresh --- src/popup/SegmentListComponent.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/popup/SegmentListComponent.tsx b/src/popup/SegmentListComponent.tsx index 6e0f62c5..35bf9e7e 100644 --- a/src/popup/SegmentListComponent.tsx +++ b/src/popup/SegmentListComponent.tsx @@ -48,9 +48,7 @@ export const SegmentListComponent = (props: SegmentListComponentProps) => { React.useEffect(() => { const hasSegments = props.segments.find(seg => seg.actionType !== ActionType.Chapter) - if (hasSegments) { - setTab(SegmentListTab.Segments); - } else { + if (!hasSegments && props.segments.length > 0) { setTab(SegmentListTab.Chapter); } }, [props.videoID, props.segments]); From 1b2c3f5dbf6974d9cda873e29ba78d343934fbd7 Mon Sep 17 00:00:00 2001 From: felistachio Date: Sun, 21 Sep 2025 13:19:22 -0700 Subject: [PATCH 4/5] Hide also the tab buttons if there are only chapters and small refactor --- src/popup/SegmentListComponent.tsx | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/popup/SegmentListComponent.tsx b/src/popup/SegmentListComponent.tsx index 35bf9e7e..31c530b5 100644 --- a/src/popup/SegmentListComponent.tsx +++ b/src/popup/SegmentListComponent.tsx @@ -32,6 +32,14 @@ interface SegmentWithNesting extends SponsorTime { innerChapters?: (SegmentWithNesting|SponsorTime)[]; } +function isSegment(segment) { + return segment.actionType !== ActionType.Chapter; +} + +function isChapter(segment) { + return segment.actionType === ActionType.Chapter; +} + export const SegmentListComponent = (props: SegmentListComponentProps) => { const [tab, setTab] = React.useState(SegmentListTab.Segments); const [isVip, setIsVip] = React.useState(Config.config?.isVip ?? false); @@ -46,18 +54,25 @@ export const SegmentListComponent = (props: SegmentListComponentProps) => { } }, []); + const [hasSegments, hasChapters] = React.useMemo(() => { + const hasSegments = Boolean(props.segments.find(isSegment)) + const hasChapters = Boolean(props.segments.find(isChapter)) + return [hasSegments, hasChapters]; + }, [props.segments]); + React.useEffect(() => { - const hasSegments = props.segments.find(seg => seg.actionType !== ActionType.Chapter) - if (!hasSegments && props.segments.length > 0) { + if (hasSegments){ + setTab(SegmentListTab.Segments); + } else { setTab(SegmentListTab.Chapter); } - }, [props.videoID, props.segments]); + }, [props.videoID, hasSegments]); const tabFilter = (segment: SponsorTime) => { if (tab === SegmentListTab.Chapter) { - return segment.actionType === ActionType.Chapter; + return isChapter(segment); } else { - return segment.actionType !== ActionType.Chapter; + return isSegment(segment); } }; @@ -99,7 +114,7 @@ export const SegmentListComponent = (props: SegmentListComponentProps) => { return (
-
s.actionType === ActionType.Chapter) ? "" : "hidden"}> +
{ setTab(SegmentListTab.Segments); }}> From 444b90cac228fb53463326edeab5c7b3fbcee65d Mon Sep 17 00:00:00 2001 From: felistachio Date: Sun, 21 Sep 2025 13:26:23 -0700 Subject: [PATCH 5/5] simplify tabFilter --- src/popup/SegmentListComponent.tsx | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/popup/SegmentListComponent.tsx b/src/popup/SegmentListComponent.tsx index 31c530b5..4275eef6 100644 --- a/src/popup/SegmentListComponent.tsx +++ b/src/popup/SegmentListComponent.tsx @@ -68,14 +68,6 @@ export const SegmentListComponent = (props: SegmentListComponentProps) => { } }, [props.videoID, hasSegments]); - const tabFilter = (segment: SponsorTime) => { - if (tab === SegmentListTab.Chapter) { - return isChapter(segment); - } else { - return isSegment(segment); - } - }; - const segmentsWithNesting = React.useMemo(() => { const result: SegmentWithNesting[] = []; let nbTrailingNonChapters = 0; @@ -141,7 +133,7 @@ export const SegmentListComponent = (props: SegmentListComponentProps) => { isVip={isVip} loopedChapter={props.loopedChapter} // UUID instead of boolean so it can be passed down to nested chapters - tabFilter={tabFilter} + tabFilter={tab === SegmentListTab.Chapter ? isChapter : isSegment} sendMessage={props.sendMessage} /> ))