1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Chore: Moved app state to separate file

This commit is contained in:
Laurent Cozic 2021-09-04 18:11:29 +01:00
parent 8e5d209d3c
commit 80762572cf
22 changed files with 57 additions and 53 deletions

View File

@ -1,4 +1,4 @@
import { AppState } from './app'; import { AppState } from './app.reducer';
import appReducer, { createAppDefaultState } from './app.reducer'; import appReducer, { createAppDefaultState } from './app.reducer';
describe('app.reducer', function() { describe('app.reducer', function() {

View File

@ -1,11 +1,44 @@
import produce from 'immer'; import produce from 'immer';
import Setting from '@joplin/lib/models/Setting'; import Setting from '@joplin/lib/models/Setting';
import { defaultState } from '@joplin/lib/reducer'; import { defaultState, State } from '@joplin/lib/reducer';
import { AppState } from './app';
import iterateItems from './gui/ResizableLayout/utils/iterateItems'; import iterateItems from './gui/ResizableLayout/utils/iterateItems';
import { LayoutItem } from './gui/ResizableLayout/utils/types'; import { LayoutItem } from './gui/ResizableLayout/utils/types';
import validateLayout from './gui/ResizableLayout/utils/validateLayout'; import validateLayout from './gui/ResizableLayout/utils/validateLayout';
export interface AppStateRoute {
type: string;
routeName: string;
props: any;
}
export enum AppStateDialogName {
SyncWizard = 'syncWizard',
MasterPassword = 'masterPassword',
}
export interface AppStateDialog {
name: AppStateDialogName;
}
export interface AppState extends State {
route: AppStateRoute;
navHistory: any[];
noteVisiblePanes: string[];
windowContentSize: any;
watchedNoteFiles: string[];
lastEditorScrollPercents: any;
devToolsVisible: boolean;
visibleDialogs: any; // empty object if no dialog is visible. Otherwise contains the list of visible dialogs.
focusedField: string;
layoutMoveMode: boolean;
startupPluginsLoaded: boolean;
// Extra reducer keys go here
watchedResources: any;
mainLayout: LayoutItem;
dialogs: AppStateDialog[];
}
export function createAppDefaultState(windowContentSize: any, resourceEditWatcherDefaultState: any): AppState { export function createAppDefaultState(windowContentSize: any, resourceEditWatcherDefaultState: any): AppState {
return { return {
...defaultState, ...defaultState,

View File

@ -3,7 +3,6 @@ import CommandService from '@joplin/lib/services/CommandService';
import KeymapService from '@joplin/lib/services/KeymapService'; import KeymapService from '@joplin/lib/services/KeymapService';
import PluginService, { PluginSettings } from '@joplin/lib/services/plugins/PluginService'; import PluginService, { PluginSettings } from '@joplin/lib/services/plugins/PluginService';
import resourceEditWatcherReducer, { defaultState as resourceEditWatcherDefaultState } from '@joplin/lib/services/ResourceEditWatcher/reducer'; import resourceEditWatcherReducer, { defaultState as resourceEditWatcherDefaultState } from '@joplin/lib/services/ResourceEditWatcher/reducer';
import { State } from '@joplin/lib/reducer';
import PluginRunner from './services/plugins/PluginRunner'; import PluginRunner from './services/plugins/PluginRunner';
import PlatformImplementation from './services/plugins/PlatformImplementation'; import PlatformImplementation from './services/plugins/PlatformImplementation';
import shim from '@joplin/lib/shim'; import shim from '@joplin/lib/shim';
@ -19,7 +18,6 @@ import SpellCheckerService from '@joplin/lib/services/spellChecker/SpellCheckerS
import SpellCheckerServiceDriverNative from './services/spellChecker/SpellCheckerServiceDriverNative'; import SpellCheckerServiceDriverNative from './services/spellChecker/SpellCheckerServiceDriverNative';
import bridge from './services/bridge'; import bridge from './services/bridge';
import menuCommandNames from './gui/menuCommandNames'; import menuCommandNames from './gui/menuCommandNames';
import { LayoutItem } from './gui/ResizableLayout/utils/types';
import stateToWhenClauseContext from './services/commands/stateToWhenClauseContext'; import stateToWhenClauseContext from './services/commands/stateToWhenClauseContext';
import ResourceService from '@joplin/lib/services/ResourceService'; import ResourceService from '@joplin/lib/services/ResourceService';
import ExternalEditWatcher from '@joplin/lib/services/ExternalEditWatcher'; import ExternalEditWatcher from '@joplin/lib/services/ExternalEditWatcher';
@ -60,40 +58,12 @@ const globalCommands = appCommands.concat(libCommands);
import editorCommandDeclarations from './gui/NoteEditor/editorCommandDeclarations'; import editorCommandDeclarations from './gui/NoteEditor/editorCommandDeclarations';
import ShareService from '@joplin/lib/services/share/ShareService'; import ShareService from '@joplin/lib/services/share/ShareService';
import checkForUpdates from './checkForUpdates'; import checkForUpdates from './checkForUpdates';
import { AppState } from './app.reducer';
const pluginClasses = [ const pluginClasses = [
require('./plugins/GotoAnything').default, require('./plugins/GotoAnything').default,
]; ];
interface AppStateRoute {
type: string;
routeName: string;
props: any;
}
export interface AppStateDialog {
name: string;
}
export interface AppState extends State {
route: AppStateRoute;
navHistory: any[];
noteVisiblePanes: string[];
windowContentSize: any;
watchedNoteFiles: string[];
lastEditorScrollPercents: any;
devToolsVisible: boolean;
visibleDialogs: any; // empty object if no dialog is visible. Otherwise contains the list of visible dialogs.
focusedField: string;
layoutMoveMode: boolean;
startupPluginsLoaded: boolean;
// Extra reducer keys go here
watchedResources: any;
mainLayout: LayoutItem;
dialogs: AppStateDialog[];
}
const appDefaultState = createAppDefaultState( const appDefaultState = createAppDefaultState(
bridge().windowContentSize(), bridge().windowContentSize(),
resourceEditWatcherDefaultState resourceEditWatcherDefaultState

View File

@ -1,5 +1,5 @@
import CommandService, { CommandRuntime, CommandDeclaration, CommandContext } from '@joplin/lib/services/CommandService'; import CommandService, { CommandRuntime, CommandDeclaration, CommandContext } from '@joplin/lib/services/CommandService';
import { AppState } from '../app'; import { AppState } from '../app.reducer';
import bridge from '../services/bridge'; import bridge from '../services/bridge';
export const declaration: CommandDeclaration = { export const declaration: CommandDeclaration = {

View File

@ -8,7 +8,7 @@ import { _ } from '@joplin/lib/locale';
import ClipperServer from '@joplin/lib/ClipperServer'; import ClipperServer from '@joplin/lib/ClipperServer';
import Setting from '@joplin/lib/models/Setting'; import Setting from '@joplin/lib/models/Setting';
import EncryptionService from '@joplin/lib/services/e2ee/EncryptionService'; import EncryptionService from '@joplin/lib/services/e2ee/EncryptionService';
import { AppState } from '../app'; import { AppState } from '../app.reducer';
class ClipperConfigScreenComponent extends React.Component { class ClipperConfigScreenComponent extends React.Component {
constructor() { constructor() {

View File

@ -17,7 +17,7 @@ import { stateUtils } from '@joplin/lib/reducer';
import InteropServiceHelper from '../../InteropServiceHelper'; import InteropServiceHelper from '../../InteropServiceHelper';
import { _ } from '@joplin/lib/locale'; import { _ } from '@joplin/lib/locale';
import NoteListWrapper from '../NoteListWrapper/NoteListWrapper'; import NoteListWrapper from '../NoteListWrapper/NoteListWrapper';
import { AppState } from '../../app'; import { AppState } from '../../app.reducer';
import { saveLayout, loadLayout } from '../ResizableLayout/utils/persist'; import { saveLayout, loadLayout } from '../ResizableLayout/utils/persist';
import Setting from '@joplin/lib/models/Setting'; import Setting from '@joplin/lib/models/Setting';
import produce from 'immer'; import produce from 'immer';

View File

@ -2,7 +2,7 @@ import { CommandContext, CommandDeclaration, CommandRuntime } from '@joplin/lib/
import { _ } from '@joplin/lib/locale'; import { _ } from '@joplin/lib/locale';
import bridge from '../../../services/bridge'; import bridge from '../../../services/bridge';
import SpellCheckerService from '@joplin/lib/services/spellChecker/SpellCheckerService'; import SpellCheckerService from '@joplin/lib/services/spellChecker/SpellCheckerService';
import { AppState } from '../../../app'; import { AppState } from '../../../app.reducer';
const Menu = bridge().Menu; const Menu = bridge().Menu;

View File

@ -1,6 +1,6 @@
import { CommandDeclaration, CommandRuntime, CommandContext } from '@joplin/lib/services/CommandService'; import { CommandDeclaration, CommandRuntime, CommandContext } from '@joplin/lib/services/CommandService';
import { _ } from '@joplin/lib/locale'; import { _ } from '@joplin/lib/locale';
import { AppState } from '../../../app'; import { AppState } from '../../../app.reducer';
export const declaration: CommandDeclaration = { export const declaration: CommandDeclaration = {
name: 'toggleLayoutMoveMode', name: 'toggleLayoutMoveMode',

View File

@ -2,7 +2,7 @@ import { CommandContext, CommandDeclaration, CommandRuntime } from '@joplin/lib/
import { _ } from '@joplin/lib/locale'; import { _ } from '@joplin/lib/locale';
import setLayoutItemProps from '../../ResizableLayout/utils/setLayoutItemProps'; import setLayoutItemProps from '../../ResizableLayout/utils/setLayoutItemProps';
import layoutItemProp from '../../ResizableLayout/utils/layoutItemProp'; import layoutItemProp from '../../ResizableLayout/utils/layoutItemProp';
import { AppState } from '../../../app'; import { AppState } from '../../../app.reducer';
export const declaration: CommandDeclaration = { export const declaration: CommandDeclaration = {
name: 'toggleNoteList', name: 'toggleNoteList',

View File

@ -2,7 +2,7 @@ import { CommandContext, CommandDeclaration, CommandRuntime } from '@joplin/lib/
import { _ } from '@joplin/lib/locale'; import { _ } from '@joplin/lib/locale';
import setLayoutItemProps from '../../ResizableLayout/utils/setLayoutItemProps'; import setLayoutItemProps from '../../ResizableLayout/utils/setLayoutItemProps';
import layoutItemProp from '../../ResizableLayout/utils/layoutItemProp'; import layoutItemProp from '../../ResizableLayout/utils/layoutItemProp';
import { AppState } from '../../../app'; import { AppState } from '../../../app.reducer';
export const declaration: CommandDeclaration = { export const declaration: CommandDeclaration = {
name: 'toggleSideBar', name: 'toggleSideBar',

View File

@ -1,5 +1,5 @@
import { useEffect, useState, useRef, useCallback } from 'react'; import { useEffect, useState, useRef, useCallback } from 'react';
import { AppState } from '../app'; import { AppState } from '../app.reducer';
import InteropService from '@joplin/lib/services/interop/InteropService'; import InteropService from '@joplin/lib/services/interop/InteropService';
import { stateUtils } from '@joplin/lib/reducer'; import { stateUtils } from '@joplin/lib/reducer';
import CommandService from '@joplin/lib/services/CommandService'; import CommandService from '@joplin/lib/services/CommandService';

View File

@ -3,7 +3,7 @@ import CommandService from '@joplin/lib/services/CommandService';
import ToolbarBase from '../../../ToolbarBase'; import ToolbarBase from '../../../ToolbarBase';
import { utils as pluginUtils } from '@joplin/lib/services/plugins/reducer'; import { utils as pluginUtils } from '@joplin/lib/services/plugins/reducer';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { AppState } from '../../../../app'; import { AppState } from '../../../../app.reducer';
import ToolbarButtonUtils, { ToolbarButtonInfo } from '@joplin/lib/services/commands/ToolbarButtonUtils'; import ToolbarButtonUtils, { ToolbarButtonInfo } from '@joplin/lib/services/commands/ToolbarButtonUtils';
import stateToWhenClauseContext from '../../../../services/commands/stateToWhenClauseContext'; import stateToWhenClauseContext from '../../../../services/commands/stateToWhenClauseContext';
const { buildStyle } = require('@joplin/lib/theme'); const { buildStyle } = require('@joplin/lib/theme');

View File

@ -20,7 +20,7 @@ import CommandService from '@joplin/lib/services/CommandService';
import ToolbarButton from '../ToolbarButton/ToolbarButton'; import ToolbarButton from '../ToolbarButton/ToolbarButton';
import Button, { ButtonLevel } from '../Button/Button'; import Button, { ButtonLevel } from '../Button/Button';
import eventManager from '@joplin/lib/eventManager'; import eventManager from '@joplin/lib/eventManager';
import { AppState } from '../../app'; import { AppState } from '../../app.reducer';
import ToolbarButtonUtils from '@joplin/lib/services/commands/ToolbarButtonUtils'; import ToolbarButtonUtils from '@joplin/lib/services/commands/ToolbarButtonUtils';
import { _ } from '@joplin/lib/locale'; import { _ } from '@joplin/lib/locale';
import TagList from '../TagList'; import TagList from '../TagList';

View File

@ -1,4 +1,4 @@
import { AppState } from '../../app'; import { AppState } from '../../app.reducer';
import eventManager from '@joplin/lib/eventManager'; import eventManager from '@joplin/lib/eventManager';
import NoteListUtils from '../utils/NoteListUtils'; import NoteListUtils from '../utils/NoteListUtils';
import { _ } from '@joplin/lib/locale'; import { _ } from '@joplin/lib/locale';

View File

@ -1,4 +1,5 @@
import app, { AppState, AppStateDialog } from '../app'; import app from '../app';
import { AppState, AppStateDialog } from '../app.reducer';
import MainScreen from './MainScreen/MainScreen'; import MainScreen from './MainScreen/MainScreen';
import ConfigScreen from './ConfigScreen/ConfigScreen'; import ConfigScreen from './ConfigScreen/ConfigScreen';
import StatusScreen from './StatusScreen/StatusScreen'; import StatusScreen from './StatusScreen/StatusScreen';

View File

@ -13,7 +13,7 @@ import { StateShare } from '@joplin/lib/services/share/reducer';
import { NoteEntity } from '@joplin/lib/services/database/types'; import { NoteEntity } from '@joplin/lib/services/database/types';
import Button from './Button/Button'; import Button from './Button/Button';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { AppState } from '../app'; import { AppState } from '../app.reducer';
import { getEncryptionEnabled } from '@joplin/lib/services/synchronizer/syncInfoUtils'; import { getEncryptionEnabled } from '@joplin/lib/services/synchronizer/syncInfoUtils';
const { clipboard } = require('electron'); const { clipboard } = require('electron');

View File

@ -10,7 +10,7 @@ import InteropServiceHelper from '../../InteropServiceHelper';
import { _ } from '@joplin/lib/locale'; import { _ } from '@joplin/lib/locale';
import { PluginStates, utils as pluginUtils } from '@joplin/lib/services/plugins/reducer'; import { PluginStates, utils as pluginUtils } from '@joplin/lib/services/plugins/reducer';
import { MenuItemLocation } from '@joplin/lib/services/plugins/api/types'; import { MenuItemLocation } from '@joplin/lib/services/plugins/api/types';
import { AppState } from '../../app'; import { AppState } from '../../app.reducer';
import { ModelType } from '@joplin/lib/BaseModel'; import { ModelType } from '@joplin/lib/BaseModel';
import BaseModel from '@joplin/lib/BaseModel'; import BaseModel from '@joplin/lib/BaseModel';
import Folder from '@joplin/lib/models/Folder'; import Folder from '@joplin/lib/models/Folder';

View File

@ -1,7 +1,7 @@
import { CommandRuntime, CommandDeclaration, CommandContext } from '@joplin/lib/services/CommandService'; import { CommandRuntime, CommandDeclaration, CommandContext } from '@joplin/lib/services/CommandService';
import { _ } from '@joplin/lib/locale'; import { _ } from '@joplin/lib/locale';
import layoutItemProp from '../../ResizableLayout/utils/layoutItemProp'; import layoutItemProp from '../../ResizableLayout/utils/layoutItemProp';
import { AppState } from '../../../app'; import { AppState } from '../../../app.reducer';
export const declaration: CommandDeclaration = { export const declaration: CommandDeclaration = {
name: 'focusElementSideBar', name: 'focusElementSideBar',

View File

@ -1,6 +1,6 @@
import * as React from 'react'; import * as React from 'react';
import { useMemo } from 'react'; import { useMemo } from 'react';
import { AppState } from '../app'; import { AppState } from '../app.reducer';
const { connect } = require('react-redux'); const { connect } = require('react-redux');
const { themeStyle } = require('@joplin/lib/theme'); const { themeStyle } = require('@joplin/lib/theme');

View File

@ -1,5 +1,5 @@
import * as React from 'react'; import * as React from 'react';
import { AppState } from '../app'; import { AppState } from '../app.reducer';
import CommandService, { SearchResult as CommandSearchResult } from '@joplin/lib/services/CommandService'; import CommandService, { SearchResult as CommandSearchResult } from '@joplin/lib/services/CommandService';
import KeymapService from '@joplin/lib/services/KeymapService'; import KeymapService from '@joplin/lib/services/KeymapService';
import shim from '@joplin/lib/shim'; import shim from '@joplin/lib/shim';

View File

@ -3,7 +3,7 @@
// general, any desktop component should import this file, and not the lib // general, any desktop component should import this file, and not the lib
// one. // one.
import { AppState } from '../../app'; import { AppState } from '../../app.reducer';
import libStateToWhenClauseContext, { WhenClauseContextOptions } from '@joplin/lib/services/commands/stateToWhenClauseContext'; import libStateToWhenClauseContext, { WhenClauseContextOptions } from '@joplin/lib/services/commands/stateToWhenClauseContext';
import layoutItemProp from '../../gui/ResizableLayout/utils/layoutItemProp'; import layoutItemProp from '../../gui/ResizableLayout/utils/layoutItemProp';

View File

@ -1,4 +1,4 @@
import { AppState } from '../../app'; import { AppState } from '../../app.reducer';
export interface DesktopCommandContext { export interface DesktopCommandContext {
state: AppState; state: AppState;