@@ -32,6 +32,14 @@ interface SegmentWithNesting extends SponsorTime {
3232 innerChapters ?: ( SegmentWithNesting | SponsorTime ) [ ] ;
3333}
3434
35+ function isSegment ( segment ) {
36+ return segment . actionType !== ActionType . Chapter ;
37+ }
38+
39+ function isChapter ( segment ) {
40+ return segment . actionType === ActionType . Chapter ;
41+ }
42+
3543export const SegmentListComponent = ( props : SegmentListComponentProps ) => {
3644 const [ tab , setTab ] = React . useState ( SegmentListTab . Segments ) ;
3745 const [ isVip , setIsVip ] = React . useState ( Config . config ?. isVip ?? false ) ;
@@ -46,18 +54,25 @@ export const SegmentListComponent = (props: SegmentListComponentProps) => {
4654 }
4755 } , [ ] ) ;
4856
57+ const [ hasSegments , hasChapters ] = React . useMemo ( ( ) => {
58+ const hasSegments = Boolean ( props . segments . find ( isSegment ) )
59+ const hasChapters = Boolean ( props . segments . find ( isChapter ) )
60+ return [ hasSegments , hasChapters ] ;
61+ } , [ props . segments ] ) ;
62+
4963 React . useEffect ( ( ) => {
50- const hasSegments = props . segments . find ( seg => seg . actionType !== ActionType . Chapter )
51- if ( ! hasSegments && props . segments . length > 0 ) {
64+ if ( hasSegments ) {
65+ setTab ( SegmentListTab . Segments ) ;
66+ } else {
5267 setTab ( SegmentListTab . Chapter ) ;
5368 }
54- } , [ props . videoID , props . segments ] ) ;
69+ } , [ props . videoID , hasSegments ] ) ;
5570
5671 const tabFilter = ( segment : SponsorTime ) => {
5772 if ( tab === SegmentListTab . Chapter ) {
58- return segment . actionType === ActionType . Chapter ;
73+ return isChapter ( segment ) ;
5974 } else {
60- return segment . actionType !== ActionType . Chapter ;
75+ return isSegment ( segment ) ;
6176 }
6277 } ;
6378
@@ -99,7 +114,7 @@ export const SegmentListComponent = (props: SegmentListComponentProps) => {
99114
100115 return (
101116 < div id = "issueReporterContainer" >
102- < div id = "issueReporterTabs" className = { props . segments && props . segments . find ( s => s . actionType === ActionType . Chapter ) ? "" : "hidden" } >
117+ < div id = "issueReporterTabs" className = { hasSegments && hasChapters ? "" : "hidden" } >
103118 < span id = "issueReporterTabSegments" className = { tab === SegmentListTab . Segments ? "sbSelected" : "" } onClick = { ( ) => {
104119 setTab ( SegmentListTab . Segments ) ;
105120 } } >
0 commit comments