Skip to content

Commit

Permalink
breadamp-ui: add HTTP POST calls (#34)
Browse files Browse the repository at this point in the history
Controls the MIDI light show via HTTP calls.
  • Loading branch information
Terkwood authored May 29, 2020
1 parent 8a501f9 commit 15a5cb3
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 270 deletions.
1 change: 1 addition & 0 deletions breadamp-ui/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules
/build
/*.log
/.vscode
size-plugin.json
14 changes: 11 additions & 3 deletions breadamp-ui/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
# breadamp-ui

This is a user interface which can control the MIDI light show.

## CLI Commands

```bash
# install dependencies
npm install
Most importantly, for now:

```sh
# serve with hot reload at localhost:8080
preact watch
```

Also:

```bash
# install dependencies
npm install

# build for production with minification
npm run build
Expand Down
2 changes: 1 addition & 1 deletion breadamp-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "breadamp-ui",
"version": "0.0.0",
"version": "0.1.0",
"license": "MIT",
"scripts": {
"build": "preact build",
Expand Down
264 changes: 0 additions & 264 deletions breadamp-ui/size-plugin.json

This file was deleted.

19 changes: 17 additions & 2 deletions breadamp-ui/src/routes/home/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
import { useState } from "preact/hooks";
import "98.css";

const HOST = "http://192.168.1.100:3030";

const post = async (command) =>
fetch(`${HOST}/${command}`, {
method: "POST",
mode: "no-cors",
});

const Home = () => {
const [msg, setMsg] = useState("stopped");
const [isPlaying, setIsPlaying] = useState(false);
const prevTrack = () => setMsg("prev");
const nextTrack = () => setMsg("next");
const prevTrack = () => {
setMsg("prev");
return post("prev");
};
const nextTrack = () => {
setMsg("next");
return post("next");
};
return (
<div className="window-body">
<p style={{ textAlign: "center" }}>{msg}</p>
Expand All @@ -15,6 +29,7 @@ const Home = () => {
onClick={() => {
setIsPlaying(!isPlaying);
setMsg(!isPlaying ? "playing" : "stopped");
return post(!isPlaying ? "play" : "stop");
}}
>
{isPlaying ? "⏹️" : "▶️"}
Expand Down

0 comments on commit 15a5cb3

Please sign in to comment.