@@ -2,17 +2,33 @@ import React, { Component } from "react";
2
2
import { AppFooter , AppHeader } from "../App" ;
3
3
import { ChannelPlayer } from "../../components/ChannelPlayer" ;
4
4
import { Link , Redirect } from "react-router-dom" ;
5
+ import { ChannelPlayerNavigatingInstruction } from "../../components/ChannelPlayerNavigatingInstruction" ;
5
6
import "./index.scss" ;
6
7
7
8
export class ChannelViewer extends Component {
8
9
constructor ( props ) {
9
10
super ( props ) ;
10
11
this . state = {
11
- data : this . props . location . state . audioData ,
12
+ data :
13
+ this . props . location . state && this . props . location . state . audioData
14
+ ? this . props . location . state . audioData
15
+ : null ,
12
16
playAll : false ,
13
17
pauseAll : false ,
14
18
playNext : false ,
15
- tapeId : this . props . location . state . tapeId ,
19
+ tapeId :
20
+ this . props . location . state && this . props . location . state . tapeId
21
+ ? this . props . location . state . tapeId
22
+ : null ,
23
+ showInstruction : false ,
24
+ minBlock :
25
+ this . props . location && this . props . location . state
26
+ ? this . props . location . state . minBlock
27
+ : null ,
28
+ maxBlock :
29
+ this . props . location && this . props . location . state
30
+ ? this . props . location . state . maxBlock
31
+ : null ,
16
32
} ;
17
33
}
18
34
@@ -80,6 +96,13 @@ export class ChannelViewer extends Component {
80
96
playNextOrPreviousActivate : true ,
81
97
} ) ;
82
98
}
99
+ handleCloseInstruction = ( ) => {
100
+ this . setState ( { showInstruction : false } ) ;
101
+ } ;
102
+
103
+ handleDisplayInstruction = ( ) => {
104
+ this . setState ( { showInstruction : true } ) ;
105
+ } ;
83
106
84
107
handlePlayNext ( ) {
85
108
const nextAudioBlockNuggetIndex = this . getNextBlockAndNuggetIndex ( ) ;
@@ -101,8 +124,23 @@ export class ChannelViewer extends Component {
101
124
this . setState ( { playAll : false , pauseAll : false } ) ;
102
125
}
103
126
127
+ isFirstVisit ( ) {
128
+ return localStorage . getItem ( "alreadyVisitedChannelPlayerPage" ) === "true" ;
129
+ }
130
+
104
131
componentDidMount ( ) {
105
132
this . removeBrowserHistoryState ( ) ;
133
+
134
+ let visited = this . isFirstVisit ( ) ;
135
+
136
+ // Do not view popup if this isn't the first time
137
+ if ( visited ) {
138
+ this . setState ( { showInstruction : false } ) ;
139
+ } else {
140
+ // This is the first time
141
+ localStorage . setItem ( "alreadyVisitedChannelPlayerPage" , true ) ;
142
+ this . setState ( { showInstruction : true } ) ;
143
+ }
106
144
}
107
145
108
146
removeBrowserHistoryState ( ) {
@@ -134,6 +172,8 @@ export class ChannelViewer extends Component {
134
172
const currentBlockIndex = this . state . currentBlockIndex ;
135
173
const currentNuggetIndex = this . state . currentNuggetIndex ;
136
174
const tapeId = this . state . tapeId ;
175
+ const minBlock = this . state . minBlock ;
176
+ const maxBlock = this . state . maxBlock ;
137
177
return (
138
178
< >
139
179
< AppHeader />
@@ -149,6 +189,8 @@ export class ChannelViewer extends Component {
149
189
blockIndex : nextBlockIndex ,
150
190
nuggetIndex : nextNuggetIndex ,
151
191
tapeId : tapeId ,
192
+ minBlock : minBlock ,
193
+ maxBlock : maxBlock
152
194
} ,
153
195
} ,
154
196
} }
@@ -170,10 +212,16 @@ export class ChannelViewer extends Component {
170
212
171
213
{ data && Object . keys ( data ) . length > 0 ? (
172
214
< >
215
+ < ChannelPlayerNavigatingInstruction
216
+ handleClosePopup = { this . handleCloseInstruction }
217
+ showInstruction = { this . state . showInstruction }
218
+ />
173
219
< div className = "d-flex justify-content-center mb-4" >
174
220
< button
175
221
type = "button"
176
- disabled = { currentBlockIndex == 1 && currentNuggetIndex == 1 }
222
+ disabled = {
223
+ currentBlockIndex == minBlock && currentNuggetIndex == 1
224
+ }
177
225
className = "btn btn-warning mr-3 audio-controller-text"
178
226
onClick = { this . handlePlayPrevious . bind ( this ) }
179
227
>
@@ -195,7 +243,9 @@ export class ChannelViewer extends Component {
195
243
</ button >
196
244
< button
197
245
type = "button"
198
- disabled = { currentBlockIndex == 6 && currentNuggetIndex == 6 }
246
+ disabled = {
247
+ currentBlockIndex == maxBlock && currentNuggetIndex == 6
248
+ }
199
249
className = "btn btn-warning audio-controller-text"
200
250
onClick = { this . handlePlayNext . bind ( this ) }
201
251
>
@@ -217,12 +267,22 @@ export class ChannelViewer extends Component {
217
267
) ;
218
268
} ) }
219
269
</ div >
270
+ < div className = "ml-2" >
271
+ < button
272
+ type = "button"
273
+ className = "btn btn-secondary mt-5"
274
+ onClick = { this . handleDisplayInstruction }
275
+ >
276
+ Instructions for navigating audio player page
277
+ </ button >
278
+ </ div >
220
279
</ >
221
280
) : (
222
281
< h4 className = "container text-center" >
223
282
Error loading channels, please select different channels
224
283
</ h4 >
225
284
) }
285
+
226
286
< AppFooter />
227
287
</ >
228
288
) ;
0 commit comments