refactor: delete unused from edit workspace

This commit is contained in:
tiddlygit-test 2020-08-18 20:57:55 +08:00
parent 4bf0f686d4
commit 7e8b78fdc7
2 changed files with 1 additions and 59 deletions

View file

@ -12,16 +12,13 @@ import ListItemText from '@material-ui/core/ListItemText';
import ListItemSecondaryAction from '@material-ui/core/ListItemSecondaryAction'; import ListItemSecondaryAction from '@material-ui/core/ListItemSecondaryAction';
import Switch from '@material-ui/core/Switch'; import Switch from '@material-ui/core/Switch';
import Typography from '@material-ui/core/Typography'; import Typography from '@material-ui/core/Typography';
import FormGroup from '@material-ui/core/FormGroup';
import FormControlLabel from '@material-ui/core/FormControlLabel';
import Checkbox from '@material-ui/core/Checkbox';
import connectComponent from '../../helpers/connect-component'; import connectComponent from '../../helpers/connect-component';
import getMailtoUrl from '../../helpers/get-mailto-url'; import getMailtoUrl from '../../helpers/get-mailto-url';
import defaultIcon from '../../images/default-icon.png'; import defaultIcon from '../../images/default-icon.png';
import { getIconFromInternet, save, updateForm } from '../../state/dialog-edit-workspace/actions'; import { save, updateForm } from '../../state/dialog-edit-workspace/actions';
const styles = theme => ({ const styles = theme => ({
root: { root: {
@ -311,7 +308,6 @@ const mapStateToProps = state => ({
}); });
const actionCreators = { const actionCreators = {
getIconFromInternet,
updateForm, updateForm,
save, save,
}; };

View file

@ -1,6 +1,5 @@
import { import {
UPDATE_EDIT_WORKSPACE_DOWNLOADING_ICON,
UPDATE_EDIT_WORKSPACE_FORM, UPDATE_EDIT_WORKSPACE_FORM,
DIALOG_EDIT_WORKSPACE_INIT, DIALOG_EDIT_WORKSPACE_INIT,
} from '../../constants/actions'; } from '../../constants/actions';
@ -31,59 +30,6 @@ export const init = () => ({
type: DIALOG_EDIT_WORKSPACE_INIT, type: DIALOG_EDIT_WORKSPACE_INIT,
}); });
// to be replaced with invoke (electron 7+)
// https://electronjs.org/docs/api/ipc-renderer#ipcrendererinvokechannel-args
export const getWebsiteIconUrlAsync = (url) => new Promise((resolve, reject) => {
try {
const id = Date.now().toString();
const { ipcRenderer } = window.remote;
ipcRenderer.once(id, (e, uurl) => {
resolve(uurl);
});
ipcRenderer.send('request-get-website-icon-url', id, url);
} catch (err) {
reject(err);
}
});
export const getIconFromInternet = (forceOverwrite) => (dispatch, getState) => {
const { form: { picturePath, homeUrl, homeUrlError } } = getState().dialogEditWorkspace;
if ((!forceOverwrite && picturePath) || !homeUrl || homeUrlError) return;
dispatch({
type: UPDATE_EDIT_WORKSPACE_DOWNLOADING_ICON,
downloadingIcon: true,
});
getWebsiteIconUrlAsync(homeUrl)
.then((iconUrl) => {
const { form } = getState().dialogEditWorkspace;
if (form.homeUrl === homeUrl) {
const changes = { internetIcon: iconUrl || form.internetIcon };
if (forceOverwrite) changes.picturePath = null;
dispatch(({
type: UPDATE_EDIT_WORKSPACE_FORM,
changes,
}));
dispatch({
type: UPDATE_EDIT_WORKSPACE_DOWNLOADING_ICON,
downloadingIcon: false,
});
}
if (forceOverwrite && !iconUrl) {
return window.remote.dialog.showMessageBox({
message: 'Unable to find a suitable icon from the Internet.',
buttons: ['OK'],
cancelId: 0,
defaultId: 0,
});
}
return null;
}).catch(console.log); // eslint-disable-line no-console
};
export const updateForm = (changes) => (dispatch) => { export const updateForm = (changes) => (dispatch) => {
dispatch({ dispatch({
type: UPDATE_EDIT_WORKSPACE_FORM, type: UPDATE_EDIT_WORKSPACE_FORM,