@@ -5,12 +5,14 @@ import _ from 'lodash';
55import PatternView from './PatternView'
66
77const PLAYLIST_KEY = "firestorm:playlists:0"
8+ const BRIGHTNESS_KEY = "firestorm:brightness:0"
89
910class App extends Component {
1011 constructor ( props ) {
1112 super ( props ) ;
1213 this . state = {
1314 discoveries : [ ] ,
15+ brightness : null ,
1416 groups : [ ] , // Currently duscovered patterns and their controllers
1517 runningPatternName : null ,
1618 playlist : [ ] , // Browser-persisted single playlist singleton
@@ -21,8 +23,9 @@ class App extends Component {
2123 cloneInProgress : false ,
2224 showDevControls : false
2325 }
24- // The playlist is the only thing currently persisted and it is per-broswer
2526 this . state . playlist = JSON . parse ( localStorage . getItem ( PLAYLIST_KEY ) ) || [ ]
27+ this . state . brightness = localStorage . getItem ( BRIGHTNESS_KEY ) || 1
28+
2629
2730 if ( this . state . playlist . length ) {
2831 this . state . playlistDefaultInterval = _ ( this . state . playlist ) . last ( ) . duration
@@ -109,6 +112,32 @@ class App extends Component {
109112 } )
110113 } )
111114 }
115+ delayedSaveBrightness = _ . debounce ( async ( resolve , payload ) => {
116+ resolve ( fetch ( './command' , payload ) ) ;
117+ this . storeBrightness ( ) ;
118+ } , 1000 )
119+
120+ changeBrightness = ( event ) => {
121+ event . preventDefault ( )
122+ return new Promise ( ( resolve ) => {
123+ this . setState ( { brightness : event . target . value } , ( ) => {
124+ const payload = {
125+ method : 'POST' ,
126+ headers : {
127+ 'Accept' : 'application/json' ,
128+ 'Content-Type' : 'application/json'
129+ } ,
130+ body : JSON . stringify ( {
131+ command : {
132+ brightness : parseFloat ( this . state . brightness )
133+ } ,
134+ ids : _ . map ( this . state . discoveries , 'id' )
135+ } )
136+ }
137+ this . delayedSaveBrightness ( resolve , payload )
138+ } )
139+ } )
140+ }
112141
113142 _handlePatternClick = async ( event , pattern ) => {
114143 event . preventDefault ( )
@@ -118,7 +147,9 @@ class App extends Component {
118147 storePlaylist = ( ) => {
119148 localStorage . setItem ( PLAYLIST_KEY , JSON . stringify ( this . state . playlist ) )
120149 }
121-
150+ storeBrightness = ( ) => {
151+ localStorage . setItem ( BRIGHTNESS_KEY , this . state . brightness )
152+ }
122153 _handleDurationChange = async ( event , pattern , newDuration ) => {
123154 event . preventDefault ( )
124155 const newValidDuration = parseFloat ( newDuration ) || 0
@@ -329,9 +360,27 @@ class App extends Component {
329360 < div className = "row" >
330361 < div className = "col-lg-12" >
331362
332- < h3 > Controllers
333- < button className = "btn btn-primary " onClick = { this . handleReload } style = { { marginLeft :"1em" } } > ↻</ button >
334- </ h3 >
363+ < div className = "row no-gutters" >
364+ < h3 > Controllers
365+ < button className = "btn btn-primary " onClick = { this . handleReload } style = { { marginLeft :"1em" } } > ↻</ button >
366+ </ h3 >
367+ < div className = "navbrightness no-learning-ui row no-gutters pull-right" >
368+ < label >
369+ < span role = "img" aria-label = "light bulb emoji for pixelblaze brightness" > 💡</ span >
370+ < input
371+ id = "brightness"
372+ type = "range"
373+ className = "form-control"
374+ onChange = { this . changeBrightness }
375+ min = "0"
376+ max = "1"
377+ step = ".005"
378+ title = { `Brightness ${ Math . round ( this . state . brightness * 100 ) } %` }
379+ value = { this . state . brightness }
380+ />
381+ </ label >
382+ </ div >
383+ </ div >
335384 < ul className = "list-group col-lg-8" id = "list" >
336385 { this . state . discoveries . map ( d => {
337386 const dName = d . name
0 commit comments