Skip to content

Commit bf4eb0a

Browse files
Shanon LeeShanon Lee
authored andcommitted
Fix functionality to clear mockup image. Functional
1 parent 2eee3f6 commit bf4eb0a

File tree

4 files changed

+37
-13
lines changed

4 files changed

+37
-13
lines changed

src-electron/electron-main.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ ipcMain.handle("uploadImage", async (event, arg) => {
6363
return result;
6464
})
6565

66+
// Handle dialogs for clearing a mockup image
67+
ipcMain.handle("clearImage", async (event, arg) => {
68+
const result = await dialog.showMessageBox(arg);
69+
return result;
70+
})
71+
6672

6773
// ************** Slack OAuth functions **********************
6874
// Sends request to Slack for User's information,

src/components/home_sidebar_items/UploadImage.vue

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,23 @@ export default {
6767
},
6868
// removes mockup image
6969
removeImage () {
70-
const res = clearImageDialog()
71-
// console.log('REMOVEIMAGE: remove is ', res )
72-
if (res === 0) {
73-
this.clearImage({ route: this.activeRoute })
74-
this.source = this.imagePath[this.activeRoute]
75-
}
70+
const responsePromise = clearImageDialog()
71+
72+
responsePromise
73+
.then(res => {
74+
// res will have format: { response: 0, checkboxChecked: false }
75+
// res.response will be 0 if user chose 'Yes'
76+
// res.response will be 1 if user chose 'Cancel'
77+
if (res.response === 0) {
78+
this.clearImage({ route: this.activeRoute })
79+
this.source = this.imagePath[this.activeRoute]
80+
}
81+
})
82+
.catch(err => {
83+
console.log(err)
84+
})
7685
},
86+
7787
// imports image on browser
7888
// currently images aren't able to be stored on browser
7989
async importMockupBrowser () {

src/utils/clearImage.util.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
1-
const { dialog } = require('electron').remote
2-
1+
// const { dialog } = require('electron').remote
2+
const { ipcRenderer } = window;
33
/**
44
* Fires the Electron dialog box to show an alert to confirm clear image
55
*/
66

7-
const clearImageDialog = () => {
7+
const clearImageDialog = async () => {
88
const options = {
99
buttons: ['Yes', 'Cancel'],
1010
message: 'Do you want to clear image?'
1111
}
12-
return dialog.showMessageBox(options)
12+
// return dialog.showMessageBox(options)
13+
const helper = await ipcRenderer.invoke('clearImage', options)
14+
.then(res => {
15+
console.log('Res from clear image util: ')
16+
console.log(res)
17+
return res;
18+
})
19+
.catch(err => console.log(err))
20+
21+
return helper;
1322
}
1423

1524
export default clearImageDialog

src/utils/uploadImage.util.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,16 @@ const options = {
2121

2222
// Used in uploadImage.vue
2323
const uploadImage = async () => {
24-
const x = await ipcRenderer.invoke('uploadImage', options)
24+
const helper = await ipcRenderer.invoke('uploadImage', options)
2525
.then(res => {
26-
console.log('upload image util: ' + res.filePaths[0]);
2726
return res.filePaths[0]
2827
})
2928
.catch(err => {
3029
console.log(err);
3130
return err;
3231
})
3332

34-
return x;
33+
return helper;
3534
}
3635

3736
export default uploadImage

0 commit comments

Comments
 (0)