save board model to localstorage

This commit is contained in:
fbruc03 2022-11-15 16:11:35 +01:00
parent e00617ac78
commit 6fcaff9cc3
3 changed files with 71 additions and 70 deletions

View File

@ -1,10 +1,11 @@
import { import {
BOARD, BOARD,
} from "./types"; } from "./types";
export const setBoard = (board) => (dispatch) => { export const setBoard = (board) => (dispatch) => {
window.localStorage.setItem("board", board);
dispatch({ dispatch({
type: BOARD, type: BOARD,
payload: board, payload: board,
}); });
}; };

View File

@ -30,39 +30,39 @@ class DeviceSeclection extends Component {
super(props); super(props);
this.state = { this.state = {
open: true, open: true,
selectedBoard : "", selectedBoard: "",
saveSettings: false, saveSettings: false,
}; };
} }
toggleDialog = () => { toggleDialog = () => {
this.props.setBoard(this.state.selectedBoard) this.props.setBoard(this.state.selectedBoard)
}; };
onChange = (e) => { onChange = (e) => {
if (e.target.checked) { if (e.target.checked) {
this.setState({ saveSettings: true}); this.setState({ saveSettings: true });
} else { } else {
this.setState({ saveSettings: false}); this.setState({ saveSettings: false });
} }
}; };
onclick = (e, value) => { onclick = (e, value) => {
console.log(e, value) console.log(e, value)
const root = document.querySelector(':root'); const root = document.querySelector(':root');
root.style.setProperty('--url', `url(${value === "mcu" ? mcu_opacity : mini_opacity })`); root.style.setProperty('--url', `url(${value === "mcu" ? mcu_opacity : mini_opacity})`);
this.setState({selectedBoard: value}) this.setState({ selectedBoard: value })
this.props.setBoard(value) this.props.setBoard(value)
this.setState({ open: !this.state }); this.setState({ open: !this.state });
}; };
render() { render() {
const board = this.props.selectedBoard;
if (board) {
return null;
}
else {
return ( return (
<Dialog <Dialog
style={{ zIndex: 9999999 }} style={{ zIndex: 9999999 }}
@ -72,25 +72,24 @@ class DeviceSeclection extends Component {
title={Blockly.Msg.deviceselection_head} title={Blockly.Msg.deviceselection_head}
content={""} content={""}
onClick={this.toggleDialog} onClick={this.toggleDialog}
disabled={this.state.selectedBoard===""} disabled={this.state.selectedBoard === ""}
> >
<div> <div>
<Grid container spacing={2} style={{ textAlign : "center" }}> <Grid container spacing={2} style={{ textAlign: "center" }}>
<Grid item xs={6}> <Grid item xs={6}>
<IconButton onClick={(e) => this.onclick(e, "mcu")}> <IconButton onClick={(e) => this.onclick(e, "mcu")}>
<Avatar <Avatar
alt="Sensebox MCU" alt="Sensebox MCU"
src="/media/hardware/senseboxmcu.png" src="/media/hardware/senseboxmcu.png"
style={{ style={{
border: this.state.selectedBoard === "mcu" ? 'medium solid DeepSkyBlue': "0.1px solid lightgray", border: this.state.selectedBoard === "mcu" ? 'medium solid DeepSkyBlue' : "0.1px solid lightgray",
width:"20vw", width: "20vw",
height: "20vw" height: "20vw"
}} }}
/> />
</IconButton> </IconButton>
<p>senseBox MCU</p> <p>senseBox MCU</p>
</Grid> </Grid>
{/* <Grid item xs={4}> {/* <Grid item xs={4}>
<IconButton onClick={(e) => this.onclick(e, "esp")}> <IconButton onClick={(e) => this.onclick(e, "esp")}>
<Avatar <Avatar
@ -111,8 +110,8 @@ class DeviceSeclection extends Component {
alt="Sensebox Mini" alt="Sensebox Mini"
src="/media/hardware/senseboxmcumini.png" src="/media/hardware/senseboxmcumini.png"
style={{ style={{
border: this.state.selectedBoard === "mini" ? 'medium solid DeepSkyBlue': "0.1px solid lightgray", border: this.state.selectedBoard === "mini" ? 'medium solid DeepSkyBlue' : "0.1px solid lightgray",
width:"20vw", width: "20vw",
height: "20vw" height: "20vw"
}} }}
/> />
@ -142,6 +141,7 @@ class DeviceSeclection extends Component {
</Dialog> </Dialog>
); );
} }
}
} }
DeviceSeclection.propTypes = { DeviceSeclection.propTypes = {
@ -155,5 +155,5 @@ const mapStateToProps = (state) => ({
export default connect( export default connect(
mapStateToProps, mapStateToProps,
{setBoard} { setBoard }
)(withStyles(styles, { withTheme: true })(DeviceSeclection)); )(withStyles(styles, { withTheme: true })(DeviceSeclection));

View File

@ -4,7 +4,7 @@ const initialValue = () => {
if (window.localStorage.getItem("board")) { if (window.localStorage.getItem("board")) {
return window.localStorage.getItem("board"); return window.localStorage.getItem("board");
} }
return "bla"; return null;
}; };
const initialState = { const initialState = {