From ab41872cff9c621eab3ef2470980997db6967a71 Mon Sep 17 00:00:00 2001 From: tiddlygit-test Date: Fri, 19 Feb 2021 23:00:06 +0800 Subject: [PATCH] refactor: remove useless redux store --- src/i18n.ts | 2 +- src/preload/common/authing-postmessage.ts | 10 ++- src/preload/common/i18n.ts | 2 +- src/renderer.tsx | 15 +--- .../libs/i18n/i18next-electron-fs-backend.ts | 47 +--------- src/services/libs/i18n/preloadBindings.ts | 37 ++++++++ src/services/libs/i18n/types.ts | 10 +++ src/state/dialog-add-workspace/actions.ts | 73 ---------------- src/state/dialog-add-workspace/reducers.ts | 31 ------- src/state/dialog-custom-user-agent/actions.ts | 22 ----- .../dialog-custom-user-agent/reducers.ts | 16 ---- src/state/dialog-edit-workspace/actions.ts | 68 --------------- src/state/dialog-edit-workspace/reducers.ts | 38 -------- src/state/dialog-go-to-url/actions.ts | 35 -------- src/state/dialog-go-to-url/reducers.ts | 18 ---- src/state/dialog-proxy/actions.ts | 68 --------------- src/state/dialog-proxy/reducers.ts | 34 -------- .../dialog-spellcheck-languages/actions.ts | 42 --------- .../dialog-spellcheck-languages/reducers.ts | 19 ---- src/state/find-in-page/actions.ts | 20 ----- src/state/find-in-page/reducers.ts | 33 ------- src/state/general/actions.ts | 39 --------- src/state/general/reducers.ts | 86 ------------------- src/state/index.ts | 3 - src/state/notifications/actions.ts | 11 --- src/state/notifications/reducers.ts | 29 ------- src/state/preferences/actions.ts | 9 -- src/state/preferences/reducers.ts | 16 ---- src/state/system-preferences/actions.ts | 9 -- src/state/system-preferences/reducers.ts | 17 ---- src/state/updater/actions.ts | 6 -- src/state/updater/reducers.ts | 13 --- src/state/workspace-metas/actions.ts | 12 --- src/state/workspace-metas/reducers.ts | 25 ------ src/state/workspaces/actions.ts | 12 --- src/state/workspaces/reducers.ts | 24 ------ 36 files changed, 59 insertions(+), 892 deletions(-) create mode 100644 src/services/libs/i18n/preloadBindings.ts create mode 100644 src/services/libs/i18n/types.ts delete mode 100755 src/state/dialog-add-workspace/actions.ts delete mode 100755 src/state/dialog-add-workspace/reducers.ts delete mode 100644 src/state/dialog-custom-user-agent/actions.ts delete mode 100644 src/state/dialog-custom-user-agent/reducers.ts delete mode 100644 src/state/dialog-edit-workspace/actions.ts delete mode 100644 src/state/dialog-edit-workspace/reducers.ts delete mode 100644 src/state/dialog-go-to-url/actions.ts delete mode 100644 src/state/dialog-go-to-url/reducers.ts delete mode 100644 src/state/dialog-proxy/actions.ts delete mode 100644 src/state/dialog-proxy/reducers.ts delete mode 100644 src/state/dialog-spellcheck-languages/actions.ts delete mode 100644 src/state/dialog-spellcheck-languages/reducers.ts delete mode 100644 src/state/find-in-page/actions.ts delete mode 100644 src/state/find-in-page/reducers.ts delete mode 100644 src/state/general/actions.ts delete mode 100644 src/state/general/reducers.ts delete mode 100644 src/state/index.ts delete mode 100755 src/state/notifications/actions.ts delete mode 100755 src/state/notifications/reducers.ts delete mode 100755 src/state/preferences/actions.ts delete mode 100755 src/state/preferences/reducers.ts delete mode 100755 src/state/system-preferences/actions.ts delete mode 100755 src/state/system-preferences/reducers.ts delete mode 100755 src/state/updater/actions.ts delete mode 100755 src/state/updater/reducers.ts delete mode 100644 src/state/workspace-metas/actions.ts delete mode 100644 src/state/workspace-metas/reducers.ts delete mode 100644 src/state/workspaces/actions.ts delete mode 100644 src/state/workspaces/reducers.ts diff --git a/src/i18n.ts b/src/i18n.ts index e4fabced..e794057d 100644 --- a/src/i18n.ts +++ b/src/i18n.ts @@ -1,9 +1,9 @@ -import isDevelopment from 'electron-is-dev'; import i18n from 'i18next'; import { initReactI18next } from 'react-i18next'; import { Backend as ElectronFsBackend } from './helpers/i18next-electron-fs-backend'; export async function initI18N(): Promise { + const isDevelopment = (await window.service.context.get('isDevelopment')) as boolean; await i18n .use(ElectronFsBackend) .use(initReactI18next) diff --git a/src/preload/common/authing-postmessage.ts b/src/preload/common/authing-postmessage.ts index 9404c5d6..08ca81c1 100644 --- a/src/preload/common/authing-postmessage.ts +++ b/src/preload/common/authing-postmessage.ts @@ -2,17 +2,19 @@ import { remote } from 'electron'; // on production build, if we try to redirect to http://localhost:3000 , we will reach chrome-error://chromewebdata/ , but we can easily get back // this happens when we are redirected by OAuth login -import { CHROME_ERROR_PATH, REACT_PATH } from '@services/constants/paths'; +import { context } from './services'; const CHECK_LOADED_INTERVAL = 500; -function refresh(): void { +async function refresh(): Promise { + const CHROME_ERROR_PATH = (await context.get('CHROME_ERROR_PATH')) as string; + const REACT_PATH = (await context.get('REACT_PATH')) as string; if (window.location.href === CHROME_ERROR_PATH) { void remote.getCurrentWindow().loadURL(REACT_PATH); } else { - setTimeout(refresh, CHECK_LOADED_INTERVAL); + setTimeout(() => void refresh(), CHECK_LOADED_INTERVAL); } } -setTimeout(refresh, CHECK_LOADED_INTERVAL); +setTimeout(() => void refresh(), CHECK_LOADED_INTERVAL); interface IAuthingPostMessageEvent { code?: number; diff --git a/src/preload/common/i18n.ts b/src/preload/common/i18n.ts index b04e3793..6f72ca42 100644 --- a/src/preload/common/i18n.ts +++ b/src/preload/common/i18n.ts @@ -1,5 +1,5 @@ import { contextBridge, ipcRenderer } from 'electron'; -import { preloadBindings } from '@services/libs/i18n/i18next-electron-fs-backend'; +import { preloadBindings } from '@services/libs/i18n/preloadBindings'; const i18n = { i18nextElectronBackend: preloadBindings(ipcRenderer), diff --git a/src/renderer.tsx b/src/renderer.tsx index f71c4074..5a1844f2 100644 --- a/src/renderer.tsx +++ b/src/renderer.tsx @@ -2,7 +2,6 @@ /* eslint-disable promise/always-return */ import React from 'react'; import ReactDOM from 'react-dom'; -import { Provider } from 'react-redux'; import i18n from 'i18next'; import CssBaseline from '@material-ui/core/CssBaseline'; @@ -11,12 +10,6 @@ import { WindowNames, WindowMeta } from '@services/windows/WindowProperties'; import 'typeface-roboto/index.css'; -import store from './state'; -import { init as initDialogCustomUserAgent } from './state/dialog-custom-user-agent/actions'; -import { init as initDialogEditWorkspace } from './state/dialog-edit-workspace/actions'; -import { init as initDialogProxy } from './state/dialog-proxy/actions'; -import { init as initDialogSpellcheckLanguages } from './state/dialog-spellcheck-languages/actions'; - import { initI18N } from './i18n'; import AppWrapper from './components/app-wrapper'; @@ -79,7 +72,6 @@ async function runApp(): Promise { window.electron.webFrame.setVisualZoomLevelLimits(1, 1); if (window.meta.windowName === WindowNames.editWorkspace) { const { workspaceID } = window.meta as WindowMeta[WindowNames.editWorkspace]; - store.dispatch(initDialogEditWorkspace()); const { workspaces } = store.getState(); const workspaceList = Object.values(workspaces); const workspace = workspaces[workspaceID]; @@ -92,13 +84,10 @@ async function runApp(): Promise { }); document.title = workspace.name ? `Edit Workspace ${workspace.order + 1} "${workspace.name}"` : `Edit Workspace ${workspace.order + 1}`; } else if (window.meta.windowName === WindowNames.userAgent) { - store.dispatch(initDialogCustomUserAgent()); document.title = 'Edit Custom User Agent'; } else if (window.meta.windowName === WindowNames.proxy) { - store.dispatch(initDialogProxy()); document.title = 'Proxy Settings'; } else if (window.meta.windowName === WindowNames.spellcheck) { - store.dispatch(initDialogSpellcheckLanguages()); document.title = 'Preferred Spell Checking Languages'; } @@ -115,7 +104,7 @@ async function runApp(): Promise { } ReactDOM.render( - + <> }> @@ -124,7 +113,7 @@ async function runApp(): Promise { - , + , document.querySelector('#app'), ); diff --git a/src/services/libs/i18n/i18next-electron-fs-backend.ts b/src/services/libs/i18n/i18next-electron-fs-backend.ts index 3e6a0689..fd79eea0 100644 --- a/src/services/libs/i18n/i18next-electron-fs-backend.ts +++ b/src/services/libs/i18n/i18next-electron-fs-backend.ts @@ -1,57 +1,14 @@ /* eslint-disable unicorn/prevent-abbreviations */ import fs from 'fs-extra'; import path from 'path'; -import { IpcRenderer, IpcMain, BrowserWindow, IpcMainInvokeEvent, IpcRendererEvent } from 'electron'; +import { IpcMain, BrowserWindow, IpcMainInvokeEvent } from 'electron'; import type { IWindowService } from '@services/windows/interface'; import serviceIdentifier from '@services/serviceIdentifier'; import { container } from '@services/container'; import { LOCALIZATION_FOLDER } from '@services/constants/paths'; import { I18NChannels } from '@/constants/channels'; - -export interface IReadFileRequest { - filename: string; - key: string; -} -export interface IWriteFileRequest { - filename: string; - data: string; - keys: string[]; -} -export interface IReadWriteFileRequest extends IReadFileRequest, IWriteFileRequest {} - -/** This is the code that will go into the preload.js file - * in order to set up the contextBridge api - */ -export const preloadBindings = function ( - ipcRenderer: IpcRenderer, -): { - send: (channel: I18NChannels, readWriteFileArgs: IReadWriteFileRequest) => Promise; - onReceive: (channel: I18NChannels, callback: (readWriteFileArgs: IReadWriteFileRequest) => void) => void; - onLanguageChange: (callback: (language: string) => unknown) => void; -} { - return { - send: async (channel: I18NChannels, readWriteFileArgs: IReadWriteFileRequest): Promise => { - const validChannels = [I18NChannels.readFileRequest, I18NChannels.writeFileRequest]; - if (validChannels.includes(channel)) { - await ipcRenderer.invoke(channel, readWriteFileArgs); - } - }, - onReceive: (channel: I18NChannels, callback: (readWriteFileArgs: IReadWriteFileRequest) => void) => { - const validChannels = [I18NChannels.readFileResponse, I18NChannels.writeFileResponse]; - if (validChannels.includes(channel)) { - // Deliberately strip event as it includes "sender" - ipcRenderer.on(channel, (_event: IpcRendererEvent, arguments_: IReadWriteFileRequest) => callback(arguments_)); - } - }, - onLanguageChange: (callback: (language: string) => unknown) => { - // Deliberately strip event as it includes "sender" - ipcRenderer.on(I18NChannels.changeLanguageRequest, (_event: IpcRendererEvent, language: string) => { - callback(language); - }); - }, - }; -}; +import { IReadFileRequest, IWriteFileRequest } from './types'; /** * This is the code that will go into the main.js file diff --git a/src/services/libs/i18n/preloadBindings.ts b/src/services/libs/i18n/preloadBindings.ts new file mode 100644 index 00000000..7cd2b49b --- /dev/null +++ b/src/services/libs/i18n/preloadBindings.ts @@ -0,0 +1,37 @@ +/* eslint-disable unicorn/prevent-abbreviations */ +import { IpcRenderer, IpcRendererEvent } from 'electron'; +import { I18NChannels } from '@/constants/channels'; +import { IReadWriteFileRequest } from './types'; + +/** This is the code that will go into the preload.js file + * in order to set up the contextBridge api + */ +export const preloadBindings = function ( + ipcRenderer: IpcRenderer, +): { + send: (channel: I18NChannels, readWriteFileArgs: IReadWriteFileRequest) => Promise; + onReceive: (channel: I18NChannels, callback: (readWriteFileArgs: IReadWriteFileRequest) => void) => void; + onLanguageChange: (callback: (language: string) => unknown) => void; +} { + return { + send: async (channel: I18NChannels, readWriteFileArgs: IReadWriteFileRequest): Promise => { + const validChannels = [I18NChannels.readFileRequest, I18NChannels.writeFileRequest]; + if (validChannels.includes(channel)) { + await ipcRenderer.invoke(channel, readWriteFileArgs); + } + }, + onReceive: (channel: I18NChannels, callback: (readWriteFileArgs: IReadWriteFileRequest) => void) => { + const validChannels = [I18NChannels.readFileResponse, I18NChannels.writeFileResponse]; + if (validChannels.includes(channel)) { + // Deliberately strip event as it includes "sender" + ipcRenderer.on(channel, (_event: IpcRendererEvent, arguments_: IReadWriteFileRequest) => callback(arguments_)); + } + }, + onLanguageChange: (callback: (language: string) => unknown) => { + // Deliberately strip event as it includes "sender" + ipcRenderer.on(I18NChannels.changeLanguageRequest, (_event: IpcRendererEvent, language: string) => { + callback(language); + }); + }, + }; +}; diff --git a/src/services/libs/i18n/types.ts b/src/services/libs/i18n/types.ts new file mode 100644 index 00000000..a3926632 --- /dev/null +++ b/src/services/libs/i18n/types.ts @@ -0,0 +1,10 @@ +export interface IReadFileRequest { + filename: string; + key: string; +} +export interface IWriteFileRequest { + filename: string; + data: string; + keys: string[]; +} +export interface IReadWriteFileRequest extends IReadFileRequest, IWriteFileRequest {} diff --git a/src/state/dialog-add-workspace/actions.ts b/src/state/dialog-add-workspace/actions.ts deleted file mode 100755 index 8e0c318f..00000000 --- a/src/state/dialog-add-workspace/actions.ts +++ /dev/null @@ -1,73 +0,0 @@ -/* eslint-disable consistent-return */ -/* eslint-disable unicorn/no-null */ -/* eslint-disable unicorn/consistent-function-scoping */ -import type { Dispatch } from 'redux'; -import { ADD_WORKSPACE_CREATE_WIKI_MESSAGE, ADD_WORKSPACE_UPDATE_FORM } from '../../constants/actions'; - -import validate from '../../helpers/validate'; -import isUrl from '../../helpers/is-url'; -import hasErrors from '../../helpers/has-errors'; - -import i18n from 'i18next'; - -export const setWikiCreationMessage = (message: string) => ({ - type: ADD_WORKSPACE_CREATE_WIKI_MESSAGE, - value: message, -}); - -const getValidationRules = () => ({ - name: { - fieldName: 'Name', - required: true, - }, - homeUrl: { - fieldName: 'Home URL', - required: true, - url: true, - }, -}); - -export const updateForm = (changes: any) => (dispatch: Dispatch, getState: any) => { - const oldHomeUrl = getState().dialogAddWorkspace.form.homeUrl; - - dispatch({ - type: ADD_WORKSPACE_UPDATE_FORM, - changes: validate(changes, getValidationRules()), - }); - - if (getState().dialogAddWorkspace.form.homeUrl === oldHomeUrl) return; // url didn't change - if (changes.internetIcon === null) return; // user explictly want to get rid of icon -}; - -export const save = () => async (dispatch: any, getState: any) => { - const { form } = getState().dialogAddWorkspace; - - dispatch(setWikiCreationMessage(i18n.t('AddWorkspace.StartUpdatingWorkspace'))); - const validatedChanges = validate(form, getValidationRules()); - if (hasErrors(validatedChanges)) { - return dispatch(updateForm(validatedChanges)); - } - - const url = form.homeUrl.trim(); - const homeUrl = isUrl(url) ? url : `http://${url}`; - - // FIXME: maybe use createWorkspace instead? - await window.service.workspaceView.createWorkspaceView({ - name: form.name, - isSubWiki: form.isSubWiki, - mainWikiToLink: form.mainWikiToLink, - port: form.port, - homeUrl, - gitUrl: form.gitUrl, - picturePath: form.internetIcon || form.picturePath, - transparentBackground: Boolean(form.transparentBackground), - tagName: form.tagName, - }); - await window.service.menu.buildMenu(); - if (!form.isSubWiki) { - dispatch(setWikiCreationMessage(i18n.t('AddWorkspace.WorkspaceUpdated'))); - // and wiki will be closed after wiki server started, close logic is inside wiki-worker-manager.js - } else { - window.remote.closeCurrentWindow(); - } -}; diff --git a/src/state/dialog-add-workspace/reducers.ts b/src/state/dialog-add-workspace/reducers.ts deleted file mode 100755 index 95c919f9..00000000 --- a/src/state/dialog-add-workspace/reducers.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { combineReducers } from 'redux'; - -import { ADD_WORKSPACE_CREATE_WIKI_MESSAGE, ADD_WORKSPACE_UPDATE_FORM } from '../../constants/actions'; - -const wikiCreationMessage = (state = '', action: any) => { - switch (action.type) { - case ADD_WORKSPACE_CREATE_WIKI_MESSAGE: - return action.value; - default: - return state; - } -}; - -const defaultForm = { - name: '', - homeUrl: '', - picturePath: null, -}; -const form = (state = defaultForm, action: any) => { - switch (action.type) { - case ADD_WORKSPACE_UPDATE_FORM: - return { ...state, ...action.changes }; - default: - return state; - } -}; - -export default combineReducers({ - wikiCreationMessage, - form, -}); diff --git a/src/state/dialog-custom-user-agent/actions.ts b/src/state/dialog-custom-user-agent/actions.ts deleted file mode 100644 index d9bae1eb..00000000 --- a/src/state/dialog-custom-user-agent/actions.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { UPDATE_CUSTOM_USER_AGENT_FORM, DIALOG_CUSTOM_USER_AGENT_INIT } from '../../constants/actions'; - -export const init = () => ({ - type: DIALOG_CUSTOM_USER_AGENT_INIT, -}); - -export const updateForm = (changes: any) => (dispatch: any) => - dispatch({ - type: UPDATE_CUSTOM_USER_AGENT_FORM, - changes, - }); - -export const save = () => async (dispatch: any, getState: any) => { - const { form } = getState().dialogCustomUserAgent; - - if ((await window.service.preference.get('customUserAgent')) !== form.code) { - await window.service.preference.set('customUserAgent', form.code); - await window.service.window.requestShowRequireRestartDialog(); - } - - window.remote.closeCurrentWindow(); -}; diff --git a/src/state/dialog-custom-user-agent/reducers.ts b/src/state/dialog-custom-user-agent/reducers.ts deleted file mode 100644 index 1fcab492..00000000 --- a/src/state/dialog-custom-user-agent/reducers.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { combineReducers } from 'redux'; - -import { UPDATE_CUSTOM_USER_AGENT_FORM, DIALOG_CUSTOM_USER_AGENT_INIT } from '../../constants/actions'; - -const form = (state = {}, action: any) => { - switch (action.type) { - case DIALOG_CUSTOM_USER_AGENT_INIT: - return { code: await window.service.preference.get('customUserAgent') }; - case UPDATE_CUSTOM_USER_AGENT_FORM: - return { ...state, ...action.changes }; - default: - return state; - } -}; - -export default combineReducers({ form }); diff --git a/src/state/dialog-edit-workspace/actions.ts b/src/state/dialog-edit-workspace/actions.ts deleted file mode 100644 index f2be4e1f..00000000 --- a/src/state/dialog-edit-workspace/actions.ts +++ /dev/null @@ -1,68 +0,0 @@ -import { UPDATE_EDIT_WORKSPACE_FORM, DIALOG_EDIT_WORKSPACE_INIT } from '../../constants/actions'; - -import hasErrors from '../../helpers/has-errors'; -import isUrl from '../../helpers/is-url'; -import validate from '../../helpers/validate'; - -const getValidationRules = () => ({ - name: { - fieldName: 'Name', - required: true, - }, - port: { - fieldName: 'Port', - required: true, - }, - homeUrl: { - fieldName: 'Home URL', - required: true, - lessStrictUrl: true, - }, -}); - -export const init = () => ({ - type: DIALOG_EDIT_WORKSPACE_INIT, -}); - -export const updateForm = (changes: any) => (dispatch: any) => { - dispatch({ - type: UPDATE_EDIT_WORKSPACE_FORM, - changes: validate(changes, getValidationRules()), - }); -}; - -export const save = () => async (dispatch: any, getState: any) => { - const { form } = getState().dialogEditWorkspace; - - const validatedChanges = validate(form, getValidationRules()); - if (hasErrors(validatedChanges)) { - return dispatch(updateForm(validatedChanges)); - } - - const id = window.remote.getGlobal('editWorkspaceId'); - const url = form.homeUrl.trim(); - const homeUrl = isUrl(url) ? url : `http://${url}`; - - await window.service.workspace.set(id, { - name: form.name, - port: form.port, - tagName: form.tagName, - homeUrl, - // prefs - disableAudio: Boolean(form.disableAudio), - disableNotifications: Boolean(form.disableNotifications), - hibernateWhenUnused: Boolean(form.hibernateWhenUnused), - transparentBackground: Boolean(form.transparentBackground), - }); - - if (form.picturePath) { - await window.service.workspace.setWorkspacePicture(id, form.picturePath); - } else if (form.internetIcon) { - await window.service.workspace.setWorkspacePicture(id, form.internetIcon); - } else { - await window.service.workspace.removeWorkspacePicture(id); - } - - window.remote.closeCurrentWindow(); - return null; -}; diff --git a/src/state/dialog-edit-workspace/reducers.ts b/src/state/dialog-edit-workspace/reducers.ts deleted file mode 100644 index ac1d3c74..00000000 --- a/src/state/dialog-edit-workspace/reducers.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { combineReducers } from 'redux'; - -import { DIALOG_EDIT_WORKSPACE_INIT, UPDATE_EDIT_WORKSPACE_DOWNLOADING_ICON, UPDATE_EDIT_WORKSPACE_FORM } from '../../constants/actions'; - -const form = async (state = {}, action: any) => { - switch (action.type) { - case DIALOG_EDIT_WORKSPACE_INIT: { - const editWorkspaceId = window.remote.getGlobal('editWorkspaceId'); - const workspaces = await window.service.workspace.getWorkspaces(); - const workspaceList = Object.values(workspaces); - const workspace = workspaces[editWorkspaceId]; - workspaceList.some((item, index) => { - // @ts-expect-error ts-migrate(2571) FIXME: Object is of type 'unknown'. - if (item.id === editWorkspaceId) { - workspace.order = index; - return true; - } - return false; - }); - return workspace; - } - case UPDATE_EDIT_WORKSPACE_FORM: - return { ...state, ...action.changes }; - default: - return state; - } -}; - -const downloadingIcon = (state = false, action: any) => { - switch (action.type) { - case UPDATE_EDIT_WORKSPACE_DOWNLOADING_ICON: - return action.downloadingIcon; - default: - return state; - } -}; - -export default combineReducers({ downloadingIcon, form }); diff --git a/src/state/dialog-go-to-url/actions.ts b/src/state/dialog-go-to-url/actions.ts deleted file mode 100644 index 3e3d531c..00000000 --- a/src/state/dialog-go-to-url/actions.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { UPDATE_GO_TO_URL_FORM } from '../../constants/actions'; -import hasErrors from '../../helpers/has-errors'; -import isUrl from '../../helpers/is-url'; -import validate from '../../helpers/validate'; - -const getValidationRules = () => ({ - url: { - fieldName: 'URL', - required: true, - lessStrictUrl: true, - }, -}); - -export const updateForm = (changes: any) => (dispatch: any) => - dispatch({ - type: UPDATE_GO_TO_URL_FORM, - changes: validate(changes, getValidationRules()), - }); - -export const go = () => (dispatch: any, getState: any) => { - const { form } = getState().dialogGoToUrl; - - const validatedChanges = validate(form, getValidationRules()); - if (hasErrors(validatedChanges)) { - return dispatch(updateForm(validatedChanges)); - } - - const { url } = form; - const finalUrl = isUrl(url) ? url : `http://${url}`; - - void window.service.workspaceView.loadURL(finalUrl).then(() => { - window.remote.closeCurrentWindow(); - }) - return null; -}; diff --git a/src/state/dialog-go-to-url/reducers.ts b/src/state/dialog-go-to-url/reducers.ts deleted file mode 100644 index 4e25bd66..00000000 --- a/src/state/dialog-go-to-url/reducers.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { combineReducers } from 'redux'; - -import { UPDATE_GO_TO_URL_FORM } from '../../constants/actions'; - -const defaultForm = { - url: '', -}; - -const form = (state = defaultForm, action: any) => { - switch (action.type) { - case UPDATE_GO_TO_URL_FORM: - return { ...state, ...action.changes }; - default: - return state; - } -}; - -export default combineReducers({ form }); diff --git a/src/state/dialog-proxy/actions.ts b/src/state/dialog-proxy/actions.ts deleted file mode 100644 index f2fef9fa..00000000 --- a/src/state/dialog-proxy/actions.ts +++ /dev/null @@ -1,68 +0,0 @@ -import { DIALOG_PROXY_FORM_UPDATE, DIALOG_PROXY_INIT } from '../../constants/actions'; - -import validate from '../../helpers/validate'; -import hasErrors from '../../helpers/has-errors'; - -export const init = () => ({ - type: DIALOG_PROXY_INIT, -}); - -const getValidationRules = (proxyType: any) => { - if (proxyType === 'rules') { - return { - proxyRules: { - fieldName: 'Proxy address', - required: true, - }, - }; - } - if (proxyType === 'pacScript') { - return { - proxyPacScript: { - fieldName: 'Script URL', - required: true, - }, - }; - } - return {}; -}; - -export const updateForm = (changes: any) => (dispatch: any, getState: any) => { - const state = getState(); - - const { form } = state.dialogProxy; - - // revalidate all fields if proxy type changes - if (changes.proxyType) { - const validatedChanges = validate({ ...form, ...changes }, getValidationRules(changes.proxyType)); - dispatch({ - type: DIALOG_PROXY_FORM_UPDATE, - changes: validatedChanges, - }); - } else { - dispatch({ - type: DIALOG_PROXY_FORM_UPDATE, - changes: validate(changes, getValidationRules(form.proxyType)), - }); - } -}; - -export const save = async () => async (dispatch: any, getState: any) => { - const state = getState(); - - const { form } = state.dialogProxy; - - const validatedChanges = validate(form, getValidationRules(form.proxyType)); - if (hasErrors(validatedChanges)) { - return dispatch(updateForm(validatedChanges)); - } - - void window.service.preference.set('proxyRules', form.proxyRules); - void window.service.preference.set('proxyBypassRules', form.proxyBypassRules); - void window.service.preference.set('proxyPacScript', form.proxyPacScript); - void window.service.preference.set('proxyType', form.proxyType); - await window.service.window.requestShowRequireRestartDialog() - - window.remote.closeCurrentWindow(); - return null; -}; diff --git a/src/state/dialog-proxy/reducers.ts b/src/state/dialog-proxy/reducers.ts deleted file mode 100644 index 7af84ddf..00000000 --- a/src/state/dialog-proxy/reducers.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { combineReducers } from 'redux'; - -import { DIALOG_PROXY_FORM_UPDATE, DIALOG_PROXY_INIT } from '../../constants/actions'; - -const formInitialState = { - proxyBypassRules: '', - proxyPacScript: '', - proxyRules: '', - proxyType: 'none', -}; -const form = async (state = formInitialState, action: any) => { - switch (action.type) { - case DIALOG_PROXY_INIT: { - const { proxyBypassRules, proxyPacScript, proxyRules, proxyType } = await window.service.preference.getPreferences(); - - return { - proxyBypassRules, - proxyPacScript, - proxyRules, - proxyType, - }; - } - case DIALOG_PROXY_FORM_UPDATE: { - const { changes } = action; - return { ...state, ...changes }; - } - default: - return state; - } -}; - -export default combineReducers({ - form, -}); diff --git a/src/state/dialog-spellcheck-languages/actions.ts b/src/state/dialog-spellcheck-languages/actions.ts deleted file mode 100644 index 4b83e0b8..00000000 --- a/src/state/dialog-spellcheck-languages/actions.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { DIALOG_SPELLCHECK_LANGUAGES_INIT, DIALOG_SPELLCHECK_LANGUAGES_UPDATE_FORM } from '../../constants/actions'; - -export const init = () => ({ - type: DIALOG_SPELLCHECK_LANGUAGES_INIT, -}); - -export const updateForm = (changes: any) => (dispatch: any) => - dispatch({ - type: DIALOG_SPELLCHECK_LANGUAGES_UPDATE_FORM, - changes, - }); - -export const addLanguage = (code: any) => (dispatch: any, getState: any) => { - const { spellcheckLanguages } = getState().dialogSpellcheckLanguages.form; - if (!spellcheckLanguages.includes(code)) { - dispatch( - updateForm({ - spellcheckLanguages: [...spellcheckLanguages, code], - }), - ); - } -}; - -export const removeLanguage = (code: any) => (dispatch: any, getState: any) => { - const { spellcheckLanguages } = getState().dialogSpellcheckLanguages.form; - const filteredSpellCheckerLanguages = spellcheckLanguages.filter((lang: any) => lang !== code); - dispatch( - updateForm({ - spellcheckLanguages: filteredSpellCheckerLanguages, - }), - ); -}; - -export const save = async () => async (dispatch: any, getState: any) => { - const { form } = getState().dialogSpellcheckLanguages; - - void window.service.preference.set('spellcheckLanguages', form.spellcheckLanguages); - - await window.service.window.requestShowRequireRestartDialog() - - window.remote.closeCurrentWindow(); -}; diff --git a/src/state/dialog-spellcheck-languages/reducers.ts b/src/state/dialog-spellcheck-languages/reducers.ts deleted file mode 100644 index 8f012527..00000000 --- a/src/state/dialog-spellcheck-languages/reducers.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { combineReducers } from 'redux'; - -import { DIALOG_SPELLCHECK_LANGUAGES_INIT, DIALOG_SPELLCHECK_LANGUAGES_UPDATE_FORM } from '../../constants/actions'; - -const form = async (state = {}, action: any) => { - switch (action.type) { - case DIALOG_SPELLCHECK_LANGUAGES_INIT: { - return { - spellcheckLanguages: await window.service.preference.get('spellcheckLanguages'), - }; - } - case DIALOG_SPELLCHECK_LANGUAGES_UPDATE_FORM: - return { ...state, ...action.changes }; - default: - return state; - } -}; - -export default combineReducers({ form }); diff --git a/src/state/find-in-page/actions.ts b/src/state/find-in-page/actions.ts deleted file mode 100644 index 8a9ccbc7..00000000 --- a/src/state/find-in-page/actions.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { CLOSE_FIND_IN_PAGE, OPEN_FIND_IN_PAGE, UPDATE_FIND_IN_PAGE_TEXT, UPDATE_FIND_IN_PAGE_MATCHES } from '../../constants/actions'; - -export const closeFindInPage = () => ({ - type: CLOSE_FIND_IN_PAGE, -}); - -export const openFindInPage = () => ({ - type: OPEN_FIND_IN_PAGE, -}); - -export const updateFindInPageText = (text: any) => ({ - type: UPDATE_FIND_IN_PAGE_TEXT, - text, -}); - -export const updateFindInPageMatches = (activeMatch: any, matches: any) => ({ - type: UPDATE_FIND_IN_PAGE_MATCHES, - activeMatch, - matches, -}); diff --git a/src/state/find-in-page/reducers.ts b/src/state/find-in-page/reducers.ts deleted file mode 100644 index 02657fc4..00000000 --- a/src/state/find-in-page/reducers.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { CLOSE_FIND_IN_PAGE, OPEN_FIND_IN_PAGE, UPDATE_FIND_IN_PAGE_TEXT, UPDATE_FIND_IN_PAGE_MATCHES } from '../../constants/actions'; - -const initialState = { - open: false, - text: '', - activeMatch: 0, - matches: 0, -}; - -const findInPage = (state = initialState, action: any) => { - switch (action.type) { - case CLOSE_FIND_IN_PAGE: { - return { ...state, open: false }; - } - case OPEN_FIND_IN_PAGE: { - return { ...state, open: true }; - } - case UPDATE_FIND_IN_PAGE_TEXT: { - return { ...state, text: action.text }; - } - case UPDATE_FIND_IN_PAGE_MATCHES: { - return { - ...state, - activeMatch: action.activeMatch, - matches: action.matches, - }; - } - default: - return state; - } -}; - -export default findInPage; diff --git a/src/state/general/actions.ts b/src/state/general/actions.ts deleted file mode 100644 index d43bb82f..00000000 --- a/src/state/general/actions.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { - UPDATE_SHOULD_USE_DARK_COLORS, - UPDATE_ADDRESS_BAR_INFO, - UPDATE_CAN_GO_BACK, - UPDATE_CAN_GO_FORWARD, - UPDATE_IS_FULL_SCREEN, - UPDATE_TITLE, -} from '../../constants/actions'; - -export const updateShouldUseDarkColors = (shouldUseDarkColors: any) => ({ - type: UPDATE_SHOULD_USE_DARK_COLORS, - shouldUseDarkColors, -}); - -export const updateCanGoBack = (canGoBack: any) => ({ - type: UPDATE_CAN_GO_BACK, - canGoBack, -}); - -export const updateCanGoForward = (canGoForward: any) => ({ - type: UPDATE_CAN_GO_FORWARD, - canGoForward, -}); - -export const updateIsFullScreen = (isFullScreen: any) => ({ - type: UPDATE_IS_FULL_SCREEN, - isFullScreen, -}); - -export const updateAddressBarInfo = (address: any, edited: any) => ({ - type: UPDATE_ADDRESS_BAR_INFO, - address, - edited, -}); - -export const updateTitle = (title: any) => ({ - type: UPDATE_TITLE, - title, -}); diff --git a/src/state/general/reducers.ts b/src/state/general/reducers.ts deleted file mode 100644 index da1ca8c4..00000000 --- a/src/state/general/reducers.ts +++ /dev/null @@ -1,86 +0,0 @@ -import { combineReducers } from 'redux'; - -import { - UPDATE_SHOULD_USE_DARK_COLORS, - UPDATE_CAN_GO_BACK, - UPDATE_CAN_GO_FORWARD, - UPDATE_IS_FULL_SCREEN, - UPDATE_ADDRESS_BAR_INFO, - UPDATE_TITLE, -} from '../../constants/actions'; - -const canGoBack = (state = false, action: any) => { - switch (action.type) { - case UPDATE_CAN_GO_BACK: - return action.canGoBack; - default: - return state; - } -}; - -const canGoForward = (state = false, action: any) => { - switch (action.type) { - case UPDATE_CAN_GO_FORWARD: - return action.canGoForward; - default: - return state; - } -}; - -const address = (state = null, action: any) => { - switch (action.type) { - case UPDATE_ADDRESS_BAR_INFO: - return action.address; - default: - return state; - } -}; - -const addressEdited = (state = false, action: any) => { - switch (action.type) { - case UPDATE_ADDRESS_BAR_INFO: - return action.edited; - default: - return state; - } -}; - -const title = (state = '', action: any) => { - switch (action.type) { - case UPDATE_TITLE: - return action.title; - default: - return state; - } -}; - -const isFullScreen = (state = window.remote.isFullScreen(), action: any) => { - switch (action.type) { - case UPDATE_IS_FULL_SCREEN: - return action.isFullScreen; - default: - return state; - } -}; - -const shouldUseDarkColors = async (state, action: any) => { - if (!state) { - state = await window.service.theme.shouldUseDarkColors(); - } - switch (action.type) { - case UPDATE_SHOULD_USE_DARK_COLORS: - return action.shouldUseDarkColors; - default: - return state; - } -}; - -export default combineReducers({ - address, - addressEdited, - canGoBack, - canGoForward, - isFullScreen, - shouldUseDarkColors, - title, -}); diff --git a/src/state/index.ts b/src/state/index.ts deleted file mode 100644 index 30d44d33..00000000 --- a/src/state/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { applyMiddleware, combineReducers, createStore } from 'redux'; - -export default {}; diff --git a/src/state/notifications/actions.ts b/src/state/notifications/actions.ts deleted file mode 100755 index 8665dc21..00000000 --- a/src/state/notifications/actions.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { UPDATE_PAUSE_NOTIFICATIONS_INFO, UPDATE_SHOW_DATE_TIME_PICKER } from '../../constants/actions'; - -export const updateShowDateTimePicker = (showDateTimePicker: any) => ({ - type: UPDATE_SHOW_DATE_TIME_PICKER, - showDateTimePicker, -}); - -export const updatePauseNotificationsInfo = (pauseNotificationsInfo: any) => ({ - type: UPDATE_PAUSE_NOTIFICATIONS_INFO, - pauseNotificationsInfo, -}); diff --git a/src/state/notifications/reducers.ts b/src/state/notifications/reducers.ts deleted file mode 100755 index c666f7be..00000000 --- a/src/state/notifications/reducers.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { combineReducers } from 'redux'; - -import { UPDATE_PAUSE_NOTIFICATIONS_INFO, UPDATE_SHOW_DATE_TIME_PICKER } from '../../constants/actions'; - -const showDateTimePicker = (state = false, action: any) => { - switch (action.type) { - case UPDATE_SHOW_DATE_TIME_PICKER: { - window.preventClosingWindow = action.showDateTimePicker; - return action.showDateTimePicker; - } - default: - return state; - } -}; - -const pauseNotificationsInfo = (state = await window.service.notification.getPauseNotificationsInfo(), action: any) => { - switch (action.type) { - case UPDATE_PAUSE_NOTIFICATIONS_INFO: { - return action.pauseNotificationsInfo; - } - default: - return state; - } -}; - -export default combineReducers({ - pauseNotificationsInfo, - showDateTimePicker, -}); diff --git a/src/state/preferences/actions.ts b/src/state/preferences/actions.ts deleted file mode 100755 index d9d71433..00000000 --- a/src/state/preferences/actions.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { SET_PREFERENCE } from '../../constants/actions'; - -export const setPreference = (name: any, value: any) => (dispatch: any) => { - dispatch({ - type: SET_PREFERENCE, - name, - value, - }); -}; diff --git a/src/state/preferences/reducers.ts b/src/state/preferences/reducers.ts deleted file mode 100755 index de605243..00000000 --- a/src/state/preferences/reducers.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { SET_PREFERENCE } from '../../constants/actions'; - -const preferences = async (state, action: any) => { - switch (action.type) { - case SET_PREFERENCE: { - const newState = { ...state }; - newState[action.name] = action.value; - - return newState; - } - default: - return state; - } -}; - -export default preferences; diff --git a/src/state/system-preferences/actions.ts b/src/state/system-preferences/actions.ts deleted file mode 100755 index e5766f21..00000000 --- a/src/state/system-preferences/actions.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { SET_SYSTEM_PREFERENCE } from '../../constants/actions'; - -export const setSystemPreference = (name: any, value: any) => (dispatch: any) => { - dispatch({ - type: SET_SYSTEM_PREFERENCE, - name, - value, - }); -}; diff --git a/src/state/system-preferences/reducers.ts b/src/state/system-preferences/reducers.ts deleted file mode 100755 index 01c3161b..00000000 --- a/src/state/system-preferences/reducers.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { SET_SYSTEM_PREFERENCE } from '../../constants/actions'; - -const systemPreferences = async (state, action: any) => { - state = await window.service.systemPreference.getSystemPreferences(); - switch (action.type) { - case SET_SYSTEM_PREFERENCE: { - const newState = { ...state }; - newState[action.name] = action.value; - - return newState; - } - default: - return state; - } -}; - -export default systemPreferences; diff --git a/src/state/updater/actions.ts b/src/state/updater/actions.ts deleted file mode 100755 index 61a71ad7..00000000 --- a/src/state/updater/actions.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { UPDATE_UPDATER } from '../../constants/actions'; - -export const updateUpdater = (updaterObject: any) => ({ - type: UPDATE_UPDATER, - updaterObj: updaterObject, -}); diff --git a/src/state/updater/reducers.ts b/src/state/updater/reducers.ts deleted file mode 100755 index f8b968ae..00000000 --- a/src/state/updater/reducers.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { UPDATE_UPDATER } from '../../constants/actions'; - -const updater = (state = {}, action: any) => { - switch (action.type) { - case UPDATE_UPDATER: { - return action.updaterObj; - } - default: - return state; - } -}; - -export default updater; diff --git a/src/state/workspace-metas/actions.ts b/src/state/workspace-metas/actions.ts deleted file mode 100644 index 343b78f9..00000000 --- a/src/state/workspace-metas/actions.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { SET_WORKSPACE_META, SET_WORKSPACE_METAS } from '../../constants/actions'; - -export const setWorkspaceMeta = (id: any, value: any) => ({ - type: SET_WORKSPACE_META, - id, - value, -}); - -export const setWorkspaceMetas = (workspaceMetas: any) => ({ - type: SET_WORKSPACE_METAS, - workspaceMetas, -}); diff --git a/src/state/workspace-metas/reducers.ts b/src/state/workspace-metas/reducers.ts deleted file mode 100644 index ef3d4b4e..00000000 --- a/src/state/workspace-metas/reducers.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { SET_WORKSPACE_META, SET_WORKSPACE_METAS } from '../../constants/actions'; - - -const workspaceMetas = async (state, action: any) => { - if (state === undefined) { - state = await window.service.workspace.getAllMetaData() - } - switch (action.type) { - case SET_WORKSPACE_METAS: { - return action.workspaceMetas; - } - case SET_WORKSPACE_META: { - const newState = { ...state }; - - if (action.value) newState[action.id] = { ...newState[action.id], ...action.value }; - else delete newState[action.id]; - - return newState; - } - default: - return state; - } -}; - -export default workspaceMetas; diff --git a/src/state/workspaces/actions.ts b/src/state/workspaces/actions.ts deleted file mode 100644 index 5fd0a4d2..00000000 --- a/src/state/workspaces/actions.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { SET_WORKSPACE, SET_WORKSPACES } from '../../constants/actions'; - -export const setWorkspace = (id: any, value: any) => ({ - type: SET_WORKSPACE, - id, - value, -}); - -export const setWorkspaces = (workspaces: any) => ({ - type: SET_WORKSPACES, - workspaces, -}); diff --git a/src/state/workspaces/reducers.ts b/src/state/workspaces/reducers.ts deleted file mode 100644 index a1e8baef..00000000 --- a/src/state/workspaces/reducers.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { SET_WORKSPACE, SET_WORKSPACES } from '../../constants/actions'; - -const workspaces = async (state = initialState, action: any) => { - if (state === undefined) { - state = await window.service.workspace.getWorkspaces(); - } - switch (action.type) { - case SET_WORKSPACES: { - return action.workspaces; - } - case SET_WORKSPACE: { - const newState = { ...state }; - - if (action.value) newState[action.id] = { ...newState[action.id], ...action.value }; - else delete newState[action.id]; - - return newState; - } - default: - return state; - } -}; - -export default workspaces;