Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: factor out showLoadSpace listener #127

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions public/app/listeners/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ const saveSpace = require('./saveSpace');
const getSpace = require('./getSpace');
const getSpaces = require('./getSpaces');
const deleteSpace = require('./deleteSpace');
const exportSpace = require('./exportSpace');
const showSyncSpacePrompt = require('./showSyncSpacePrompt');
const syncSpace = require('./syncSpace');
const exportSpace = require('./exportSpace');
const getGeolocationEnabled = require('./getGeolocationEnabled');
const setGeolocationEnabled = require('./setGeolocationEnabled');
const showLoadSpacePrompt = require('./showLoadSpacePrompt');

module.exports = {
loadSpace,
Expand All @@ -18,6 +17,5 @@ module.exports = {
syncSpace,
deleteSpace,
exportSpace,
getGeolocationEnabled,
setGeolocationEnabled,
showLoadSpacePrompt,
};
11 changes: 11 additions & 0 deletions public/app/listeners/showLoadSpacePrompt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// eslint-disable-next-line import/no-extraneous-dependencies
const { dialog } = require('electron');
const { RESPOND_LOAD_SPACE_PROMPT_CHANNEL } = require('../config/channels');

const showLoadSpacePrompt = mainWindow => (event, options) => {
dialog.showOpenDialog(null, options, filePaths => {
mainWindow.webContents.send(RESPOND_LOAD_SPACE_PROMPT_CHANNEL, filePaths);
});
};

module.exports = showLoadSpacePrompt;
9 changes: 3 additions & 6 deletions public/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ const {
SHOW_DELETE_SPACE_PROMPT_CHANNEL,
SHOW_EXPORT_SPACE_PROMPT_CHANNEL,
SHOW_LOAD_SPACE_PROMPT_CHANNEL,
RESPOND_LOAD_SPACE_PROMPT_CHANNEL,
SAVE_SPACE_CHANNEL,
GET_USER_FOLDER_CHANNEL,
GET_LANGUAGE_CHANNEL,
Expand Down Expand Up @@ -66,6 +65,7 @@ const {
getSpace,
deleteSpace,
exportSpace,
showLoadSpace,
getGeolocationEnabled,
setGeolocationEnabled,
} = require('./app/listeners');
Expand Down Expand Up @@ -181,6 +181,7 @@ const standardFileSubmenu = [
// automatically show info from package.json
package_json_dir: path.join(__dirname, '../'),
bug_link_text: 'Report a Bug/Issue',

// we cannot use homepage from package.json as
// create-react-app uses it to build the frontend
homepage: 'https://graasp.eu/',
Expand Down Expand Up @@ -308,11 +309,7 @@ app.on('ready', async () => {
ipcMain.on(EXPORT_SPACE_CHANNEL, exportSpace(mainWindow, db));

// prompt when loading a space
ipcMain.on(SHOW_LOAD_SPACE_PROMPT_CHANNEL, (event, options) => {
dialog.showOpenDialog(null, options, filePaths => {
mainWindow.webContents.send(RESPOND_LOAD_SPACE_PROMPT_CHANNEL, filePaths);
});
});
ipcMain.on(SHOW_LOAD_SPACE_PROMPT_CHANNEL, showLoadSpace(mainWindow, db));

// prompt when exporting a space
ipcMain.on(SHOW_EXPORT_SPACE_PROMPT_CHANNEL, (event, spaceTitle) => {
Expand Down