refactor: remove useless redux store

This commit is contained in:
tiddlygit-test 2021-02-19 23:00:06 +08:00
parent 9510cef510
commit ab41872cff
36 changed files with 59 additions and 892 deletions

View file

@ -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<void> {
const isDevelopment = (await window.service.context.get('isDevelopment')) as boolean;
await i18n
.use(ElectronFsBackend)
.use(initReactI18next)

View file

@ -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<void> {
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;

View file

@ -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),

View file

@ -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<void> {
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<void> {
});
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<void> {
}
ReactDOM.render(
<Provider store={store}>
<>
<AppWrapper>
<CssBaseline />
<React.Suspense fallback={<div />}>
@ -124,7 +113,7 @@ async function runApp(): Promise<void> {
</I18nextProvider>
</React.Suspense>
</AppWrapper>
</Provider>,
</>,
document.querySelector('#app'),
);

View file

@ -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<void>;
onReceive: (channel: I18NChannels, callback: (readWriteFileArgs: IReadWriteFileRequest) => void) => void;
onLanguageChange: (callback: (language: string) => unknown) => void;
} {
return {
send: async (channel: I18NChannels, readWriteFileArgs: IReadWriteFileRequest): Promise<void> => {
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

View file

@ -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<void>;
onReceive: (channel: I18NChannels, callback: (readWriteFileArgs: IReadWriteFileRequest) => void) => void;
onLanguageChange: (callback: (language: string) => unknown) => void;
} {
return {
send: async (channel: I18NChannels, readWriteFileArgs: IReadWriteFileRequest): Promise<void> => {
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);
});
},
};
};

View file

@ -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 {}

View file

@ -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();
}
};

View file

@ -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,
});

View file

@ -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();
};

View file

@ -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 });

View file

@ -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;
};

View file

@ -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 });

View file

@ -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;
};

View file

@ -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 });

View file

@ -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;
};

View file

@ -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,
});

View file

@ -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();
};

View file

@ -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 });

View file

@ -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,
});

View file

@ -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;

View file

@ -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,
});

View file

@ -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,
});

View file

@ -1,3 +0,0 @@
import { applyMiddleware, combineReducers, createStore } from 'redux';
export default {};

View file

@ -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,
});

View file

@ -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,
});

View file

@ -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,
});
};

View file

@ -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;

View file

@ -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,
});
};

View file

@ -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;

View file

@ -1,6 +0,0 @@
import { UPDATE_UPDATER } from '../../constants/actions';
export const updateUpdater = (updaterObject: any) => ({
type: UPDATE_UPDATER,
updaterObj: updaterObject,
});

View file

@ -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;

View file

@ -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,
});

View file

@ -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;

View file

@ -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,
});

View file

@ -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;