@@ -10,6 +10,8 @@ import {TimeDuration} from "./TimeDuration";
1010import { SORT_BY , SORT_DIRECTION , SortableField } from "./SortableField" ;
1111import { revokeToken } from "../session/SessionActions" ;
1212import Moment from "moment" ;
13+ import profileImage from '../profile.svg' ;
14+ import { setPreference } from "../app/AppActions" ;
1315
1416/**
1517 * Stream list view (the main screen of the app)
@@ -22,13 +24,16 @@ function StreamList() {
2224 // todo - consider persisting local preference state to the app state
2325 const [ sortBy , setSortBy ] = useState ( SORT_BY . VIEWER_COUNT ) ; // default api sort
2426 const [ sortDir , setSortDir ] = useState ( SORT_DIRECTION . DESC ) ;
25- const [ showTitles , setShowTitles ] = useState ( true ) ;
26- const [ showTags , setShowTags ] = useState ( true ) ;
27+ const { showTitles, showTags, showProfileImg } = useSelector ( state => state . app . preferences ) ;
28+ // const [showTitles, setShowTitles] = useState(true);
29+ // const [showTags, setShowTags] = useState(true);
30+ // const [showProfileImg, setShowProfileImg] = useState(true);
2731 const [ selectedStreamId , setSelectedStream ] = useState ( null ) ;
2832 const [ showModal , setShowModal ] = useState ( null ) ;
2933
3034 const streams = useSelector ( state => state . streams ) ;
31- const login = useSelector ( state => state . session . data . login ) ;
35+ const { user_id, login } = useSelector ( state => state . session . data ) ;
36+ const userCache = useSelector ( state => state . users . cache ) ;
3237
3338 const { isFetching, lastError, data, raid, lastUpdated } = streams ;
3439 const { isFetching : isRaidFetching , /*isCancelled, lastError: raidLastError,*/ lastUpdated : raidStartedAt } = raid ;
@@ -62,12 +67,16 @@ function StreamList() {
6267 } , [ setSortBy , setSortDir ] ) ;
6368
6469 const handleToggleTitle = useCallback ( ( e ) => {
65- setShowTitles ( e . target . checked ) ;
66- } , [ setShowTitles ] ) ;
70+ dispatch ( setPreference ( 'showTitles' , e . target . checked ) ) ;
71+ } , [ dispatch ] ) ;
6772
6873 const handleToggleTags = useCallback ( ( e ) => {
69- setShowTags ( e . target . checked ) ;
70- } , [ setShowTags ] ) ;
74+ dispatch ( setPreference ( 'showTags' , e . target . checked ) ) ;
75+ } , [ dispatch ] ) ;
76+
77+ const handleToggleProfileImg = useCallback ( ( e ) => {
78+ dispatch ( setPreference ( 'showProfileImg' , e . target . checked ) ) ;
79+ } , [ dispatch ] ) ;
7180
7281 const handleRefresh = useCallback ( ( ) => {
7382 dispatch ( fetchFollowedStreams ( ) ) ;
@@ -143,7 +152,7 @@ function StreamList() {
143152 < Navbar . Brand > DirtyRaid™</ Navbar . Brand >
144153 < Navbar . Toggle />
145154 < Navbar . Collapse className = "justify-content-end" >
146- < NavDropdown title = { < > < img src = { twitchLogo } alt = "" /> { login } </ > } id = "user-dropdown" align = "end" >
155+ < NavDropdown title = { < > < img src = { twitchLogo } alt = "" /> { userCache [ user_id ] ?. display_name || login } </ > } id = "user-dropdown" align = "end" >
147156 < NavDropdown . Item onClick = { handleSignOut } > Sign out</ NavDropdown . Item >
148157 </ NavDropdown >
149158 < Navbar . Text >
@@ -162,10 +171,13 @@ function StreamList() {
162171 < label > Display Options:</ label >
163172 < div >
164173 < div >
165- < Form . Check type = "switch" id = "show-title" label = "Show titles" checked = { showTitles } onChange = { handleToggleTitle } />
174+ < Form . Check type = "switch" id = "show-title" label = "Titles" checked = { showTitles } onChange = { handleToggleTitle } />
175+ </ div >
176+ < div >
177+ < Form . Check type = "switch" id = "show-tags" label = "Tags" checked = { showTags } onChange = { handleToggleTags } />
166178 </ div >
167179 < div >
168- < Form . Check type = "switch" id = "show-tags" label = "Show tags " checked = { showTags } onChange = { handleToggleTags } />
180+ < Form . Check type = "switch" id = "show-tags" label = "Pic " checked = { showProfileImg } onChange = { handleToggleProfileImg } />
169181 </ div >
170182 < div className = "refresh text-end flex-grow-1" >
171183 < Button disabled = { isFetching } onClick = { handleRefresh } > < i className = "bi bi-arrow-clockwise" /> </ Button >
@@ -184,26 +196,36 @@ function StreamList() {
184196 < div className = "stream-list" >
185197 {
186198 streamList . map ( ( stream , i ) => {
199+ const profile = userCache [ stream . user_id ] ;
187200 return (
188201 < div className = "stream" key = { i } data-id = { stream . id } onClick = { handleStreamClick } >
189-
190- < Row className = "whodis" >
191- < Col >
192- < div className = "d-flex justify-content-between" >
193- < div className = "flex-grow-1 user-name" > < span > { stream . user_name } </ span > </ div >
194- < div className = "flex-grow-0 participation" >
195- < span className = "viewers" > < i className = "bi bi-eye-fill" /> {
196- CondensedFormatter ( stream . viewer_count , 0 ) } </ span >
197- < TimeDuration time = { stream . started_at } />
198- </ div >
202+ < div className = "info-container" >
203+ { showProfileImg && (
204+ < div className = "profile-container" >
205+ < img src = { profile ?. profile_image_url || profileImage } alt = "" />
199206 </ div >
200- </ Col >
201- </ Row >
202- { showTitles && (
203- < Row >
204- < Col className = "title" > { stream . title } </ Col >
205- </ Row >
206- ) }
207+ ) }
208+ < div className = "stream-info" >
209+ < Row className = "whodis" >
210+ < Col >
211+ < div className = "d-flex justify-content-between" >
212+ < div className = "flex-grow-1 user-name" > < span > { profile && profile . broadcaster_type === 'partner' &&
213+ < i className = "bi bi-patch-check-fill partner" /> } { stream . user_name } </ span > </ div >
214+ < div className = "flex-grow-0 participation" >
215+ < span className = "viewers" > < i className = "bi bi-eye-fill" /> {
216+ CondensedFormatter ( stream . viewer_count , 0 ) } </ span >
217+ < TimeDuration time = { stream . started_at } />
218+ </ div >
219+ </ div >
220+ </ Col >
221+ </ Row >
222+ { showTitles && (
223+ < Row >
224+ < Col className = "title" > { stream . title } </ Col >
225+ </ Row >
226+ ) }
227+ </ div >
228+ </ div >
207229 { showTags && (
208230 < Row >
209231 < Col className = "tags" >
@@ -225,16 +247,19 @@ function StreamList() {
225247 < Modal show = { showModal } onHide = { handleCloseModal } size = "lg" centered className = "stream-modal" >
226248 < Modal . Header closeButton >
227249 < Modal . Title id = "stuffs" >
250+ { userCache [ selectedStream ?. user_id ] && userCache [ selectedStream ?. user_id ] . broadcaster_type === 'partner' &&
251+ < i className = "bi bi-patch-check-fill partner" /> }
228252 { selectedStream ?. user_name || 'Streamer Offline!' }
229253 </ Modal . Title >
230254 </ Modal . Header >
231255 < Modal . Body >
232256 { selectedStream ? (
233- < > < Row >
234- < Col >
235- < img src = { selectedStream . thumbnail_url . replace ( / { w i d t h } x { height} / , '400x225' ) + '?nonce=' + lastUpdated } alt = "" />
236- </ Col >
237- </ Row >
257+ < >
258+ < Row >
259+ < Col >
260+ < img src = { selectedStream . thumbnail_url . replace ( / { w i d t h } x { height} / , '400x225' ) + '?nonce=' + lastUpdated } alt = "" />
261+ </ Col >
262+ </ Row >
238263 < Row >
239264 < Col className = "title" > { selectedStream . title } </ Col >
240265 </ Row >
0 commit comments