From 219d0bb328a6df60ef7cbdb62362fb9200c82b55 Mon Sep 17 00:00:00 2001 From: Caley Date: Tue, 18 Apr 2023 22:58:37 -0500 Subject: [PATCH] fix(add_brightness_slider): Adds brightness slider for PBs in network based on PB implementation. --- src/App.css | 22 ++++++++++++++++++++ src/App.js | 59 ++++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 76 insertions(+), 5 deletions(-) diff --git a/src/App.css b/src/App.css index 18f2d5d..bc9e169 100644 --- a/src/App.css +++ b/src/App.css @@ -42,3 +42,25 @@ from { transform: rotate(0deg); } to { transform: rotate(360deg); } } + +.navbrightness { + white-space: nowrap; +} + +.navbrightness label { + font-size: 170%; + margin: 4px 6px; + float: left; +} + +#brightness { + padding: initial; +} + +.navbrightness input { + width: 10em; + display: inline-block; + border: none; + height: 1em; + margin-right: 1em; +} \ No newline at end of file diff --git a/src/App.js b/src/App.js index 71a37c4..e7f3547 100644 --- a/src/App.js +++ b/src/App.js @@ -5,12 +5,14 @@ import _ from 'lodash'; import PatternView from './PatternView' const PLAYLIST_KEY = "firestorm:playlists:0" +const BRIGHTNESS_KEY = "firestorm:brightness:0" class App extends Component { constructor(props) { super(props); this.state = { discoveries: [], + brightness: null, groups: [], // Currently duscovered patterns and their controllers runningPatternName: null, playlist: [], // Browser-persisted single playlist singleton @@ -21,8 +23,9 @@ class App extends Component { cloneInProgress: false, showDevControls: false } - // The playlist is the only thing currently persisted and it is per-broswer this.state.playlist = JSON.parse(localStorage.getItem(PLAYLIST_KEY)) || [] + this.state.brightness = localStorage.getItem(BRIGHTNESS_KEY) || 1 + if (this.state.playlist.length) { this.state.playlistDefaultInterval = _(this.state.playlist).last().duration @@ -109,6 +112,32 @@ class App extends Component { }) }) } + delayedSaveBrightness = _.debounce(async (resolve, payload) => { + resolve(fetch('./command', payload)); + this.storeBrightness(); + }, 1000) + + changeBrightness = (event) => { + event.preventDefault() + return new Promise((resolve) => { + this.setState({brightness: event.target.value}, () => { + const payload = { + method: 'POST', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + command: { + brightness: parseFloat(this.state.brightness) + }, + ids: _.map(this.state.discoveries, 'id') + }) + } + this.delayedSaveBrightness(resolve, payload) + }) + }) + } _handlePatternClick = async (event, pattern) => { event.preventDefault() @@ -118,7 +147,9 @@ class App extends Component { storePlaylist = () => { localStorage.setItem(PLAYLIST_KEY, JSON.stringify(this.state.playlist)) } - + storeBrightness = () => { + localStorage.setItem(BRIGHTNESS_KEY, this.state.brightness) + } _handleDurationChange = async (event, pattern, newDuration) => { event.preventDefault() const newValidDuration = parseFloat(newDuration) || 0 @@ -329,9 +360,27 @@ class App extends Component {
-

Controllers - -

+
+

Controllers + +

+
+ +
+
    {this.state.discoveries.map(d => { const dName = d.name