Skip to content

Commit a1b2eb5

Browse files
author
Alejandro Marques
committed
Change images
1 parent c0fb490 commit a1b2eb5

File tree

2 files changed

+88
-10
lines changed

2 files changed

+88
-10
lines changed

src/views/ViewA.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ const test = BrowserWindow.getAllWindows()[0];
4747
const path = require('path');
4848
const url = require('url');
4949

50+
const ipc = window.require('electron').remote.ipcMain;
51+
5052
const noIMG = require('./assets/img/NO-IMAGE.jpg');
5153

5254
class ViewA extends React.Component {
@@ -74,19 +76,26 @@ class ViewA extends React.Component {
7476
}
7577
this.setState({workSpaces: workspacesStore});
7678
}
77-
//console.log(workspacesStore);
7879
if(typeof(imagesStore)!=='undefined'){
7980
this.setState({ images: imagesStore})
8081
}
8182
}
82-
/*
83+
8384
componentDidMount = () => {
84-
console.log('workspaces',this.state.workSpaces);
85-
if(typeof(this.first(this.state.workSpaces))!== undefined){
86-
this.openWorkSpace(this.first(this.state.workSpaces));
87-
}
85+
ipc.on('update-image', (event, arg) => {
86+
var images = store.get('images');
87+
this.setState({images: images})
88+
console.log(arg[1]);
89+
console.log(arg[0]);
90+
console.log(arg);
91+
})
92+
93+
}
94+
95+
componentWillUnmount = () => {
96+
ipc.removeAllListeners();
8897
}
89-
*/
98+
9099
/* Get 1st JSON object */
91100
first = (state) => {
92101
var i=0;

src/views/ViewB.js

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ import ArrowForwardIcon from '@material-ui/icons/ArrowForward';
1717
import AutorenewIcon from '@material-ui/icons/Autorenew';
1818
import VerticalSplitIcon from '@material-ui/icons/VerticalSplit';
1919
/* NAVBAR */
20+
/** DIALOG **/
21+
import Dialog from '@material-ui/core/Dialog';
22+
import DialogActions from '@material-ui/core/DialogActions';
23+
import DialogContent from '@material-ui/core/DialogContent';
24+
import DialogTitle from '@material-ui/core/DialogTitle';
25+
import Button from '@material-ui/core/Button';
26+
/** DIALOG **/
2027
const { remote } = window.require('electron');
2128
/* STORE */
2229
const Store = window.require('electron-store');
@@ -26,15 +33,19 @@ const store = new Store();
2633
window.React = React;
2734
const { BrowserWindow, BrowserView } = window.require('electron').remote;
2835

36+
const ipc = window.require('electron').ipcRenderer;
37+
2938
export default class ViewB extends React.Component {
3039

3140
constructor(props) {
3241
super(props);
3342
this.state = {
3443
anchorEl: null,
35-
session : props.session,
44+
session : props.session,
45+
workspaceImage: '',
46+
open: false,
3647
tabs:[
37-
(<Tab key={'tab0'} title={'Fixed - ' + props.session} unclosable={true}>
48+
(<Tab key={'tab0'} title={'Fixed - ' + props.session} >
3849
<AppBar position="static" className="AppBar">
3950
<Toolbar className="Toolbar">
4051
<IconButton onClick={()=>{this.goBack('tab0')}}>
@@ -237,6 +248,47 @@ export default class ViewB extends React.Component {
237248

238249
/* APPBAR */
239250

251+
/* CHANGE IMAGE */
252+
changeImage = async () => {
253+
var b64;
254+
if(this.state.workspaceImage !== ''){
255+
b64 = await this.getBase64(this.state.workspaceImage);
256+
}else{
257+
b64 = '';
258+
}
259+
var images = store.get('images');
260+
if(b64){
261+
images[this.state.session] = b64;
262+
await store.set('images', images);
263+
ipc.send('update-image', [this.state.session]);
264+
}
265+
this.handleCloseImg();
266+
this.handleClose();
267+
}
268+
269+
getBase64 = async (file) => {
270+
return new Promise((resolve,reject) => {
271+
const reader = new FileReader();
272+
reader.onload = () => resolve(reader.result);
273+
reader.onerror = error => reject('');
274+
reader.readAsDataURL(file);
275+
});
276+
}
277+
278+
fileChangedHandler = (event) => {
279+
const file = event.target.files[0];
280+
this.setState({workspaceImage: file});
281+
}
282+
283+
handleOpen = () => {
284+
this.setState({open: true});
285+
}
286+
287+
handleCloseImg = () => {
288+
this.setState({open: false, workspaceImage:''});
289+
}
290+
/* CHANGE IMAGE */
291+
240292
render() {
241293
const { anchorEl } = this.state;
242294

@@ -308,9 +360,26 @@ export default class ViewB extends React.Component {
308360
open={Boolean(anchorEl)}
309361
onClose={this.handleClose}
310362
>
311-
<MenuItem onClick={() => { this.loadImage('../icon-devo.png')}}>Change workspace image</MenuItem>
363+
<MenuItem onClick={() => { this.handleOpen()}}>Change workspace image</MenuItem>
312364
<MenuItem onClick={() => {this._deteteWorkspace()}}>Delete workspace</MenuItem>
313365
</Menu>
366+
<Dialog open={this.state.open} onClose={() => this.handleCloseImg()} aria-labelledby="form-dialog-title">
367+
<DialogTitle id="form-dialog-title">Change workspace image</DialogTitle>
368+
<DialogContent>
369+
<Button variant="contained" component="label">
370+
Select image
371+
<input type="file" accept="image/*" style={{ display: "none" }} onChange={this.fileChangedHandler}/>
372+
</Button>
373+
</DialogContent>
374+
<DialogActions>
375+
<Button onClick={() => this.handleCloseImg()} color="secondary">
376+
Cancel
377+
</Button>
378+
<Button onClick={() => this.changeImage()} color="primary">
379+
Change
380+
</Button>
381+
</DialogActions>
382+
</Dialog>
314383
</div>
315384

316385
)

0 commit comments

Comments
 (0)