11import type { Theme } from "@mui/material" ;
22import {
33 Box ,
4+ Button ,
45 Card ,
56 CardActionArea ,
67 CardContent ,
@@ -9,13 +10,12 @@ import {
910 Typography ,
1011} from "@mui/material" ;
1112import { useMediaQuery } from "@mui/material" ;
12- import { MutableRefObject , useCallback } from "react" ;
13+ import { MutableRefObject } from "react" ;
1314
15+ import { useNowPlaying } from "@/context/NowPlayingContext" ;
1416import { Feed } from "@/graphql/generated" ;
1517import { Candidate } from "@/types/DataTypes" ;
1618
17- import { CandidateCardAIPlayer } from "./Player/CandidateCardAIPlayer" ;
18- import { CandidateCardPlayer } from "./Player/CandidateCardPlayer" ;
1919import { VideoJSPlayer } from "./Player/VideoJS" ;
2020
2121const tagRegex = [
@@ -40,9 +40,11 @@ export default function CandidateCard(props: {
4040 // changeListState?: (value: number, status: string) => void;
4141 // command?: string;
4242 players : MutableRefObject < { [ index : number ] : VideoJSPlayer } > ;
43- playNext : boolean ;
43+ // playNext: boolean;
4444 feeds : Feed [ ] ;
4545} ) {
46+ const { nowPlaying, setNowPlaying, masterPlayerRef, masterPlayerStatus } =
47+ useNowPlaying ( ) ;
4648 const lgUp = useMediaQuery ( ( theme : Theme ) => theme . breakpoints . up ( "lg" ) ) ;
4749
4850 const { descriptions } = props . candidate ;
@@ -63,49 +65,65 @@ export default function CandidateCard(props: {
6365 const lastTimestamp = lastCandidate . timestamp ;
6466 const firstTimestampString = firstCandidate . timestampString ;
6567 const lastTimestampString = lastCandidate . timestampString ;
66- const feed =
67- props . feeds . find ( ( feed ) => feed . id === firstCandidate . feedId ) ||
68- props . feeds . find ( ( feed ) => feed . id === lastCandidate . feedId ) ;
68+ // const feed =
69+ // props.feeds.find((feed) => feed.id === firstCandidate.feedId) ||
70+ // props.feeds.find((feed) => feed.id === lastCandidate.feedId);
6971
70- const humanReports = candidateArray . filter (
71- ( d ) => d . playlistTimestamp !== undefined && d . playerOffset !== undefined ,
72- ) ;
72+ // const humanReports = candidateArray.filter(
73+ // (d) => d.playlistTimestamp !== undefined && d.playerOffset !== undefined,
74+ // );
7375
74- const startPlaylistTimestamp = Math . min (
75- ...humanReports . map ( ( d ) => + d . playlistTimestamp ) ,
76- ) ;
76+ // const startPlaylistTimestamp = Math.min(
77+ // ...humanReports.map((d) => +d.playlistTimestamp),
78+ // );
7779
78- const offsetPadding = 15 ;
79- const minOffset = Math . min ( ...humanReports . map ( ( d ) => + d . playerOffset ) ) ;
80+ // const offsetPadding = 15;
81+ // const minOffset = Math.min(...humanReports.map((d) => +d.playerOffset));
8082
81- // const maxOffset = Math.max(...candidateArray.map((d) => +d.playerOffset));
82- // instead, ensure that the last offset is still in the same playlist -- future iteration may pull a second playlist if needed
83- const firstPlaylist = humanReports . filter (
84- ( d ) => + d . playlistTimestamp === startPlaylistTimestamp ,
85- ) ;
83+ // // const maxOffset = Math.max(...candidateArray.map((d) => +d.playerOffset));
84+ // // instead, ensure that the last offset is still in the same playlist -- future iteration may pull a second playlist if needed
85+ // const firstPlaylist = humanReports.filter(
86+ // (d) => +d.playlistTimestamp === startPlaylistTimestamp,
87+ // );
8688
87- const maxOffset = Math . max ( ...firstPlaylist . map ( ( d ) => + d . playerOffset ) ) ;
88- const startOffset = Math . max ( 0 , minOffset - offsetPadding ) ;
89- const endOffset = maxOffset + offsetPadding ;
90-
91- const onPlay = useCallback ( ( ) => {
92- Object . entries ( props . players . current ) . forEach ( ( [ key , player ] ) => {
93- if ( + key !== props . index ) {
94- player . pause ( ) ;
95- }
96- } ) ;
97- } , [ props . index , props . players ] ) ;
98-
99- const onPlayerEnd = useCallback ( ( ) => {
100- if ( props . playNext ) props . players . current [ props . index + 1 ] ?. play ( ) ;
101- } , [ props . playNext , props . index , props . players ] ) ;
102-
103- const onPlayerInit = useCallback (
104- ( player : VideoJSPlayer ) => {
105- props . players . current [ props . index ] = player ;
106- } ,
107- [ props . index , props . players ] ,
108- ) ;
89+ // const maxOffset = Math.max(...firstPlaylist.map((d) => +d.playerOffset));
90+ // const startOffset = Math.max(0, minOffset - offsetPadding);
91+ // const endOffset = maxOffset + offsetPadding;
92+
93+ // const onPlay = useCallback(() => {
94+ // Object.entries(props.players.current).forEach(([key, player]) => {
95+ // if (+key !== props.index) {
96+ // player.pause();
97+ // }
98+ // });
99+ // }, [props.index, props.players]);
100+
101+ // const onPlayerEnd = useCallback(() => {
102+ // if (props.playNext) props.players.current[props.index + 1]?.play();
103+ // }, [props.playNext, props.index, props.players]);
104+
105+ // const onPlayerInit = useCallback(
106+ // (player: VideoJSPlayer) => {
107+ // props.players.current[props.index] = player;
108+ // },
109+ // [props.index, props.players],
110+ // );
111+
112+ const handlePlay = ( candidate : Candidate ) => {
113+ console . log ( "clicked, candidate is" , JSON . stringify ( candidate ) ) ;
114+ setNowPlaying ( candidate ) ;
115+ masterPlayerRef ?. current ?. play ( ) ;
116+ } ;
117+
118+ const handlePause = ( ) => {
119+ masterPlayerRef ?. current ?. pause ( ) ;
120+ } ;
121+
122+ // useEffect(() => {
123+ // console.log("nowPlaying is ", JSON.stringify(nowPlaying));
124+ // console.log("candidate is ", JSON.stringify(candidate));
125+ // console.log("candidate === nowPlaying: ", candidate === nowPlaying);
126+ // }, [nowPlaying, candidate]);
109127
110128 return (
111129 < Card
@@ -127,8 +145,15 @@ export default function CandidateCard(props: {
127145 minWidth : lgUp ? 250 : 0 ,
128146 } }
129147 >
130- { feed && candidate . array [ 0 ] . playlistTimestamp ? (
131- < CandidateCardPlayer
148+ { candidate !== nowPlaying ? (
149+ < Button onClick = { ( ) => handlePlay ( candidate ) } > Play</ Button >
150+ ) : masterPlayerStatus === "paused" ? (
151+ < Button onClick = { ( ) => handlePlay ( candidate ) } > Play</ Button >
152+ ) : (
153+ < Button onClick = { ( ) => handlePause ( ) } > Pause</ Button >
154+ ) } { " " }
155+ { /* {feed && candidate.array[0].playlistTimestamp ? (
156+ <PlaybarPlayer
132157 feed={feed}
133158 timestamp={startPlaylistTimestamp}
134159 startOffset={startOffset}
@@ -140,7 +165,7 @@ export default function CandidateCard(props: {
140165 />
141166 ) : candidate.array[0].audioUri ? (
142167 <>
143- < CandidateCardAIPlayer
168+ <PlaybarAIPlayer
144169 audioUri={candidate.array[0].audioUri}
145170 // index={props.index}
146171 onPlayerInit={onPlayerInit}
@@ -157,7 +182,7 @@ export default function CandidateCard(props: {
157182 startPlaylistTimestamp +
158183 " feed: " +
159184 feed
160- ) }
185+ )} */ }
161186 </ Box >
162187 < Link
163188 // href needs a slash before so it isn't relative to folder path
0 commit comments