From 6bff2bb5439d25e0ab2a24a8ca1b28b89ef40ff9 Mon Sep 17 00:00:00 2001 From: Ricardo Cino Date: Sun, 26 Jun 2022 23:59:32 +0200 Subject: chore: turned all auth containers into typescript (#375) --- src/@types/ferdium-components.types.ts | 13 + src/@types/ferdium.types.ts | 22 ++ src/@types/stores.types.ts | 370 +++++++++++++++++++++ src/I18n.tsx | 4 +- src/components/ui/Loader.tsx | 2 +- src/containers/auth/AuthLayoutContainer.js | 86 ----- src/containers/auth/AuthLayoutContainer.tsx | 63 ++++ src/containers/auth/ChangeServerScreen.js | 45 --- src/containers/auth/ChangeServerScreen.tsx | 33 ++ src/containers/auth/ImportScreen.tsx | 19 +- src/containers/auth/InviteScreen.js | 22 -- src/containers/auth/InviteScreen.tsx | 14 + src/containers/auth/LockedScreen.tsx | 19 +- src/containers/auth/LoginScreen.js | 41 --- src/containers/auth/LoginScreen.tsx | 29 ++ src/containers/auth/PasswordScreen.tsx | 17 +- src/containers/auth/SetupAssistantScreen.tsx | 27 +- src/containers/auth/SignupScreen.js | 46 --- src/containers/auth/SignupScreen.tsx | 32 ++ src/containers/auth/WelcomeScreen.tsx | 16 +- .../workspaces/containers/EditWorkspaceScreen.tsx | 2 +- .../workspaces/containers/WorkspacesScreen.tsx | 2 +- src/helpers/async-helpers.ts | 2 +- src/stores.types.ts | 367 -------------------- src/stores/AppStore.ts | 2 +- src/stores/GlobalErrorStore.ts | 2 +- src/stores/RecipePreviewsStore.ts | 2 +- src/stores/RecipesStore.ts | 2 +- src/stores/RequestStore.ts | 2 +- src/stores/ServicesStore.ts | 2 +- src/stores/SettingsStore.ts | 2 +- src/stores/UIStore.ts | 2 +- src/stores/UserStore.ts | 2 +- src/stores/index.ts | 22 +- src/stores/lib/TypedStore.ts | 2 +- src/types.ts | 22 -- 36 files changed, 632 insertions(+), 725 deletions(-) create mode 100644 src/@types/ferdium-components.types.ts create mode 100644 src/@types/ferdium.types.ts create mode 100644 src/@types/stores.types.ts delete mode 100644 src/containers/auth/AuthLayoutContainer.js create mode 100644 src/containers/auth/AuthLayoutContainer.tsx delete mode 100644 src/containers/auth/ChangeServerScreen.js create mode 100644 src/containers/auth/ChangeServerScreen.tsx delete mode 100644 src/containers/auth/InviteScreen.js create mode 100644 src/containers/auth/InviteScreen.tsx delete mode 100644 src/containers/auth/LoginScreen.js create mode 100644 src/containers/auth/LoginScreen.tsx delete mode 100644 src/containers/auth/SignupScreen.js create mode 100644 src/containers/auth/SignupScreen.tsx delete mode 100644 src/stores.types.ts delete mode 100644 src/types.ts diff --git a/src/@types/ferdium-components.types.ts b/src/@types/ferdium-components.types.ts new file mode 100644 index 000000000..df5e2f6ed --- /dev/null +++ b/src/@types/ferdium-components.types.ts @@ -0,0 +1,13 @@ +import { Actions } from 'src/actions/lib/actions'; +import { RealStores } from 'src/stores'; + +export interface DefaultProps { + actions: Actions; + stores: RealStores; +} + +export interface GlobalError { + status: number; + message: string; + code: string; +} diff --git a/src/@types/ferdium.types.ts b/src/@types/ferdium.types.ts new file mode 100644 index 000000000..0747f8e14 --- /dev/null +++ b/src/@types/ferdium.types.ts @@ -0,0 +1,22 @@ +declare global { + interface Window { + ferdium: any; + } + + namespace NodeJS { + interface ProcessEnv { + GITHUB_AUTH_TOKEN: string; + NODE_ENV: 'development' | 'production'; + FERDIUM_APPDATA_DIR?: string; + PORTABLE_EXECUTABLE_DIR?: string; + ELECTRON_IS_DEV?: string; + APPDATA?: string; + } + } +} + +/** + * Workaround to make TS recognize this file as a module. + * https://fettblog.eu/typescript-augmenting-global-lib-dom/ + */ +export { }; diff --git a/src/@types/stores.types.ts b/src/@types/stores.types.ts new file mode 100644 index 000000000..37b906239 --- /dev/null +++ b/src/@types/stores.types.ts @@ -0,0 +1,370 @@ +import Workspace from '../features/workspaces/models/Workspace'; +import Recipe from '../models/Recipe'; +import Service from '../models/Service'; +import User from '../models/User'; +import { Request } from '../stores/lib/Request'; +import { CachedRequest } from '../stores/lib/CachedRequest'; +import Reaction from '../stores/lib/Reaction'; + +// TODO: This file will be removed in the future when all stores are +// correctly typed and the use of these interfaces are obsolete. + +export interface FerdiumStores { + app: AppStore; + communityRecipes: CommunityRecipesStore; + features: FeaturesStore; + globalError: GlobalErrorStore; + recipePreviews: RecipePreviewsStore; + recipes: RecipeStore; + requests: RequestsStore; + router: RouterStore; + services: ServicesStore; + settings: SettingsStore; + todos: TodosStore; + ui: UIStore; + user: UserStore; + workspaces: WorkspacesStore; +} + +export interface Stores { + app: AppStore; + communityRecipes: CommunityRecipesStore; + features: FeaturesStore; + globalError: GlobalErrorStore; + recipePreviews: RecipePreviewsStore; + recipes: RecipeStore; + requests: RequestsStore; + router: RouterStore; + services: ServicesStore; + settings: SettingsStore; + todos: TodosStore; + ui: UIStore; + user: UserStore; + workspaces: WorkspacesStore; +} + +interface Actions { + app: AppStore; + recipePreviews: RecipePreviewsStore; + recipes: RecipeStore; + requests: RequestsStore; + services: ServicesStore; + settings: SettingsStore; + todos: TodosStore; + ui: UIStore; + user: UserStore; + workspaces: WorkspacesStore; +} + +interface Api { + app: AppStore; + features: FeaturesStore; + local: {}; + recipePreviews: RecipePreviewsStore; + recipes: RecipeStore; + services: ServicesStore; + user: UserStore; +} + +interface TypedStore { + actions: Actions; + api: Api; + stores: Stores; + _reactions: Reaction[]; + _status: any; + actionStatus: () => void; + initialize: () => void; + tearDown: () => void; + resetStatus: () => void; +} + +interface AppStore extends TypedStore { + accentColor: string; + adaptableDarkMode: boolean; + progressbarAccentColor: string; + authRequestFailed: () => void; + autoLaunchOnStart: () => void; + automaticUpdates: boolean; + clearAppCacheRequest: () => void; + clipboardNotifications: boolean; + darkMode: boolean; + dictionaries: []; + enableSpellchecking: boolean; + fetchDataInterval: 4; + get(key: string): any; + getAppCacheSizeRequest: () => void; + healthCheckRequest: () => void; + isClearingAllCache: () => void; + isAppMuted: boolean; + isFocused: () => void; + isFullScreen: () => void; + isOnline: boolean; + isSystemDarkModeEnabled: () => void; + isSystemMuteOverridden: () => void; + locale: () => void; + lockedPassword: string; + reloadAfterResume: boolean; + reloadAfterResumeTime: number; + searchEngine: string; + spellcheckerLanguage: string; + splitMode: boolean; + splitColumns: number; + timeOfflineStart: () => void; + timeSuspensionStart: () => void; + updateStatus: () => void; + updateStatusTypes: { + CHECKING: 'CHECKING'; + AVAILABLE: 'AVAILABLE'; + NOT_AVAILABLE: 'NOT_AVAILABLE'; + DOWNLOADED: 'DOWNLOADED'; + FAILED: 'FAILED'; + }; + universalDarkMode: boolean; + cacheSize: () => void; + debugInfo: () => void; +} + +interface CommunityRecipesStore extends TypedStore { + communityRecipes: () => void; +} + +interface FeaturesStore extends TypedStore { + anonymousFeatures: () => void; + defaultFeaturesRequest: () => void; + features: () => void; + featuresRequest: CachedRequest; + _monitorLoginStatus: () => void; + _updateFeatures: () => void; + _setupFeatures: () => void; +} + +interface GlobalErrorStore extends TypedStore { + error: () => void; + messages: () => void; + response: () => void; + _handleRequests: () => void; +} + +interface RecipePreviewsStore extends TypedStore { + allRecipePreviewsRequest: () => void; + searchRecipePreviewsRequest: () => void; + all: Recipe[]; + dev: Recipe[]; + searchResults: () => void; +} + +interface RecipeStore extends TypedStore { + allRecipesRequest: () => void; + getRecipeUpdatesRequest: () => void; + installRecipeRequest: () => void; + isInstalled: (id: string) => boolean; + active: () => void; + all: Recipe[]; + one: (id: string) => Recipe; + recipeIdForServices: () => void; + _install({ recipeId: string }): Promise; +} + +interface RequestsStore extends TypedStore { + localServerPort: () => void; + retries: number; + retryDelay: number; + servicesRequest: () => void; + showRequiredRequestsError: () => void; + userInfoRequest: () => void; + areRequiredRequestsLoading: () => void; + areRequiredRequestsSuccessful: () => void; +} + +interface RouterStore { + go: () => void; + goBack: () => void; + goForward: () => void; + history: () => void; + location: { + pathname: string; + search: string; + action: string; + key: string; + state: any; + query: any; + hash?: string; + basename?: string; + }; + push(path: string): void; + replace: () => void; +} + +export interface ServicesStore extends TypedStore { + clearCacheRequest: () => void; + createServiceRequest: CachedRequest; + deleteServiceRequest: () => void; + allServicesRequest: CachedRequest; + filterNeedle: string; + lastUsedServices: () => void; + reorderServicesRequest: () => void; + serviceMaintenanceTick: () => void; + updateServiceRequest: () => void; + active: () => void; + activeSettings: () => void; + all: Service[]; + allDisplayed: () => void; + allDisplayedUnordered: () => void; + enabled: () => void; + filtered: () => void; + isTodosServiceActive: () => void; + isTodosServiceAdded: () => void; +} + +// TODO: Create actual type based on the default config in config.ts +interface ISettings { + [key: string]: any; +} + +export interface SettingsStore extends TypedStore { + update: (value: any) => void; + remove: (value: any) => void; + fileSystemSettingsTypes: any[]; + loaded: boolean; + updateAppSettingsRequest: () => void; + _fileSystemSettingsCache: () => void; + all: ISettings; + app: AppStore; + migration: () => void; + proxy: () => void; + service: ServicesStore; + stats: () => void; +} + +interface TodosStore extends TypedStore { + isFeatureActive: () => void; + isInitialized: true; + userAgentModel: () => void; + webview: () => void; + _allReactions: any[]; + _firstLaunchReaction: () => void; + _goToService: () => void; + _handleNewWindowEvent: () => void; + _onTodosClientInitialized: () => void; + _openDevTools: () => void; + _reload: () => void; + _routeCheckReaction: () => void; + _updateSettings: () => void; + _updateTodosConfig: () => void; + isFeatureEnabledByUser: () => void; + isTodoUrlValid: () => void; + isTodosPanelForceHidden: () => void; + isTodosEnabled: boolean; + isTodosPanelVisible: () => void; + isUsingPredefinedTodoServer: () => void; + settings: { + isFeatureEnabledByUser: boolean; + }; + todoRecipeId: () => void; + todoUrl: () => void; + userAgent: () => void; + width: () => void; + _handleClientMessage: () => void; + _handleHostMessage: () => void; + _resize: () => void; + _setTodosWebview: () => void; + _toggleTodosFeatureVisibility: () => void; + _toggleTodosPanel: () => void; +} + +interface UIStore extends TypedStore { + isOsDarkThemeActive: () => void; + showServicesUpdatedInfoBar: boolean; + isDarkThemeActive: () => void; + isSplitModeActive: () => void; + splitColumnsNo: () => void; + showMessageBadgesEvenWhenMuted: boolean; + theme: () => void; +} + +export interface UserStore extends TypedStore { + BASE_ROUTE: '/auth'; + CHANGE_SERVER_ROUTE: '/auth/server'; + IMPORT_ROUTE: '/auth/signup/import'; + INVITE_ROUTE: '/auth/signup/invite'; + LOGIN_ROUTE: '/auth/login'; + LOGOUT_ROUTE: '/auth/logout'; + PASSWORD_ROUTE: '/auth/password'; + SETUP_ROUTE: '/auth/signup/setup'; + SIGNUP_ROUTE: '/auth/signup'; + WELCOME_ROUTE: '/auth/welcome'; + accountType: () => void; + authToken: () => void; + deleteAccountRequest: () => void; + fetchUserInfoInterval: null; + getLegacyServicesRequest: () => void; + getUserInfoRequest: CachedRequest; + hasCompletedSignup: () => void; + id: () => void; + importLegacyServices: () => Promise; + inviteRequest: () => void; + isImportLegacyServicesCompleted: boolean; + isImportLegacyServicesExecuting: boolean; + isLoggingOut: () => void; + loginRequest: () => void; + logoutReason: () => void; + logoutReasonTypes: { SERVER: 'SERVER' }; + passwordRequest: Request; + retrievePassword: Promise; + signupRequest: () => void; + updateUserInfoRequest: () => void; + userData: () => void; + _requireAuthenticatedUser: () => void; + _importLegacyServices: () => void; + _retrievePassword: () => void; + changeServerRoute: () => void; + data: User; + importRoute: string; + inviteRoute: string; + isLoggedIn: boolean; + isTokenExpired: boolean; + legacyServices: () => void; + loginRoute: string; + logoutRoute: string; + passwordRoute: string; + setupRoute: string; + signupRoute: string; + team: () => void; +} + +export interface WorkspacesStore extends TypedStore { + activeWorkspace: () => void; + delete: ({ workspace }) => void; + update: ({ workspace }) => void; + create: ({ workspace }) => void; + edit: ({ workspace }) => void; + saving: boolean; + filterServicesByActiveWorkspace: () => void; + isFeatureActive: () => void; + isAnyWorkspaceActive: boolean; + isSettingsRouteActive: () => void; + isSwitchingWorkspace: () => void; + isWorkspaceDrawerOpen: () => void; + nextWorkspace: () => void; + workspaces: Workspace[]; + workspaceBeingEdited: () => void; + reorderServicesOfActiveWorkspace: ({ + oldIndex, + newIndex, + }: { + oldIndex: string; + newIndex: string; + }) => void; + settings: any; + _activateLastUsedWorkspaceReaction: () => void; + _allActions: any[]; + _allReactions: any[]; + _cleanupInvalidServiceReferences: () => void; + _getWorkspaceById: () => void; + _openDrawerWithSettingsReaction: () => void; + _setActiveServiceOnWorkspaceSwitchReaction: () => void; + _setWorkspaceBeingEditedReaction: () => void; + _toggleKeepAllWorkspacesLoadedSetting: () => void; + _updateSettings: () => void; + _wasDrawerOpenBeforeSettingsRoute: null; +} diff --git a/src/I18n.tsx b/src/I18n.tsx index 1be6ab23d..b486758c3 100644 --- a/src/I18n.tsx +++ b/src/I18n.tsx @@ -8,13 +8,13 @@ import AppStore from './stores/AppStore'; const translations = generatedTranslations(); -type Props = { +interface Props { stores: { app: AppStore; user: UserStore; }; children: ReactNode; -}; +} class I18N extends Component { componentDidUpdate(): void { diff --git a/src/components/ui/Loader.tsx b/src/components/ui/Loader.tsx index d4ed0d6bb..67c9db22e 100644 --- a/src/components/ui/Loader.tsx +++ b/src/components/ui/Loader.tsx @@ -2,7 +2,7 @@ import { Component, ReactChildren } from 'react'; import { observer, inject } from 'mobx-react'; import Loader from 'react-loader'; -import { FerdiumStores } from '../../stores.types'; +import { FerdiumStores } from '../../@types/stores.types'; type Props = { children: ReactChildren; diff --git a/src/containers/auth/AuthLayoutContainer.js b/src/containers/auth/AuthLayoutContainer.js deleted file mode 100644 index e6d6dcf8a..000000000 --- a/src/containers/auth/AuthLayoutContainer.js +++ /dev/null @@ -1,86 +0,0 @@ -import { Component } from 'react'; -import PropTypes from 'prop-types'; -import { inject, observer } from 'mobx-react'; -import { ThemeProvider } from 'react-jss'; - -import AuthLayout from '../../components/auth/AuthLayout'; -import AppStore from '../../stores/AppStore'; -import UserStore from '../../stores/UserStore'; -import GlobalErrorStore from '../../stores/GlobalErrorStore'; -import UIStore from '../../stores/UIStore'; -import SettingsStore from '../../stores/SettingsStore'; -import AppLoader from '../../components/ui/AppLoader'; - -import { oneOrManyChildElements } from '../../prop-types'; -import FeaturesStore from '../../stores/FeaturesStore'; - -class AuthLayoutContainer extends Component { - static propTypes = { - children: oneOrManyChildElements.isRequired, - location: PropTypes.shape({ - pathname: PropTypes.string.isRequired, - }).isRequired, - }; - - render() { - const { stores, actions, children, location } = this.props; - const { app, features, globalError, user } = stores; - - const isLoadingBaseFeatures = - features.defaultFeaturesRequest.isExecuting && - !features.defaultFeaturesRequest.wasExecuted; - - if (isLoadingBaseFeatures) { - return ( - - - - ); - } - - const { isLoggingOut } = user; - if (isLoggingOut) { - return ( - - - - ); - } - - return ( - - - {children} - - - ); - } -} - -AuthLayoutContainer.propTypes = { - stores: PropTypes.shape({ - app: PropTypes.instanceOf(AppStore).isRequired, - features: PropTypes.instanceOf(FeaturesStore).isRequired, - globalError: PropTypes.instanceOf(GlobalErrorStore).isRequired, - user: PropTypes.instanceOf(UserStore).isRequired, - ui: PropTypes.instanceOf(UIStore).isRequired, - }).isRequired, - actions: PropTypes.shape({ - app: PropTypes.instanceOf(AppStore).isRequired, - settings: PropTypes.instanceOf(SettingsStore).isRequired, - }).isRequired, -}; - -export default inject('stores', 'actions')(observer(AuthLayoutContainer)); diff --git a/src/containers/auth/AuthLayoutContainer.tsx b/src/containers/auth/AuthLayoutContainer.tsx new file mode 100644 index 000000000..8d65ec6f4 --- /dev/null +++ b/src/containers/auth/AuthLayoutContainer.tsx @@ -0,0 +1,63 @@ +import { Component, ReactElement, ReactNode } from 'react'; +import { inject, observer } from 'mobx-react'; +import { ThemeProvider } from 'react-jss'; + +import { DefaultProps } from 'src/@types/ferdium-components.types'; +import { Location } from 'mobx-react-router'; +import AuthLayout from '../../components/auth/AuthLayout'; +import AppLoader from '../../components/ui/AppLoader'; + +interface AuthLayoutContainerProps extends DefaultProps { + location: Location; + children: ReactNode[] | ReactNode; +} + +class AuthLayoutContainer extends Component { + render(): ReactElement { + const { stores, actions, children, location } = this.props; + const { app, features, globalError, user } = stores; + + const isLoadingBaseFeatures = + features.defaultFeaturesRequest.isExecuting && + !features.defaultFeaturesRequest.wasExecuted; + + if (isLoadingBaseFeatures) { + return ( + + + + ); + } + + const { isLoggingOut } = user; + if (isLoggingOut) { + return ( + + + + ); + } + + return ( + + + {children} + + + ); + } +} + +export default inject('stores', 'actions')(observer(AuthLayoutContainer)); diff --git a/src/containers/auth/ChangeServerScreen.js b/src/containers/auth/ChangeServerScreen.js deleted file mode 100644 index 60bfde088..000000000 --- a/src/containers/auth/ChangeServerScreen.js +++ /dev/null @@ -1,45 +0,0 @@ -import { Component } from 'react'; -import PropTypes from 'prop-types'; -import { inject, observer } from 'mobx-react'; -import { RouterStore } from 'mobx-react-router'; -import ChangeServer from '../../components/auth/ChangeServer'; -import SettingsStore from '../../stores/SettingsStore'; - -class ChangeServerScreen extends Component { - constructor(props) { - super(props); - - this.onSubmit = this.onSubmit.bind(this); - } - - onSubmit(values) { - const { server } = values; - - this.props.actions.settings.update({ - type: 'app', - data: { - server, - }, - }); - this.props.stores.router.push('/auth'); - } - - render() { - const { stores } = this.props; - const { server } = stores.settings.all.app; - - return ; - } -} - -ChangeServerScreen.propTypes = { - actions: PropTypes.shape({ - settings: PropTypes.instanceOf(SettingsStore).isRequired, - }).isRequired, - stores: PropTypes.shape({ - settings: PropTypes.instanceOf(SettingsStore).isRequired, - router: PropTypes.instanceOf(RouterStore).isRequired, - }).isRequired, -}; - -export default inject('stores', 'actions')(observer(ChangeServerScreen)); diff --git a/src/containers/auth/ChangeServerScreen.tsx b/src/containers/auth/ChangeServerScreen.tsx new file mode 100644 index 000000000..6af87e4a1 --- /dev/null +++ b/src/containers/auth/ChangeServerScreen.tsx @@ -0,0 +1,33 @@ +import { Component, ReactElement } from 'react'; +import { inject, observer } from 'mobx-react'; +import { DefaultProps } from 'src/@types/ferdium-components.types'; +import ChangeServer from '../../components/auth/ChangeServer'; + +class ChangeServerScreen extends Component { + constructor(props: DefaultProps) { + super(props); + + this.onSubmit = this.onSubmit.bind(this); + } + + onSubmit(values: any): void { + const { server } = values; + + this.props.actions.settings.update({ + type: 'app', + data: { + server, + }, + }); + this.props.stores.router.push('/auth'); + } + + render(): ReactElement { + const { stores } = this.props; + const { server } = stores.settings.all.app; + + return ; + } +} + +export default inject('stores', 'actions')(observer(ChangeServerScreen)); diff --git a/src/containers/auth/ImportScreen.tsx b/src/containers/auth/ImportScreen.tsx index 8d318cb2d..c128dec14 100644 --- a/src/containers/auth/ImportScreen.tsx +++ b/src/containers/auth/ImportScreen.tsx @@ -1,21 +1,10 @@ -import { Component } from 'react'; +import { Component, ReactElement } from 'react'; import { inject, observer } from 'mobx-react'; -import { RouterStore } from 'mobx-react-router'; -import { UserStore } from 'src/stores.types'; +import { DefaultProps } from 'src/@types/ferdium-components.types'; import Import from '../../components/auth/Import'; -interface IProps { - actions: { - user: UserStore; - }; - stores: { - user: UserStore; - router: RouterStore; - }; -} - -class ImportScreen extends Component { - render() { +class ImportScreen extends Component { + render(): ReactElement { const { actions, stores } = this.props; if (stores.user.isImportLegacyServicesCompleted) { diff --git a/src/containers/auth/InviteScreen.js b/src/containers/auth/InviteScreen.js deleted file mode 100644 index fc66227cc..000000000 --- a/src/containers/auth/InviteScreen.js +++ /dev/null @@ -1,22 +0,0 @@ -import { Component } from 'react'; -import PropTypes from 'prop-types'; -import { inject, observer } from 'mobx-react'; -import Invite from '../../components/auth/Invite'; - -class InviteScreen extends Component { - render() { - const { actions } = this.props; - - return ; - } -} - -InviteScreen.propTypes = { - actions: PropTypes.shape({ - user: PropTypes.shape({ - invite: PropTypes.func.isRequired, - }).isRequired, - }).isRequired, -}; - -export default inject('stores', 'actions')(observer(InviteScreen)); diff --git a/src/containers/auth/InviteScreen.tsx b/src/containers/auth/InviteScreen.tsx new file mode 100644 index 000000000..a2c684f41 --- /dev/null +++ b/src/containers/auth/InviteScreen.tsx @@ -0,0 +1,14 @@ +import { Component, ReactElement } from 'react'; +import { inject, observer } from 'mobx-react'; +import { DefaultProps } from 'src/@types/ferdium-components.types'; +import Invite from '../../components/auth/Invite'; + +class InviteScreen extends Component { + render(): ReactElement { + const { actions } = this.props; + + return ; + } +} + +export default inject('stores', 'actions')(observer(InviteScreen)); diff --git a/src/containers/auth/LockedScreen.tsx b/src/containers/auth/LockedScreen.tsx index 500bff0d6..8e3c1ec49 100644 --- a/src/containers/auth/LockedScreen.tsx +++ b/src/containers/auth/LockedScreen.tsx @@ -1,34 +1,23 @@ import { Component, ReactElement } from 'react'; import { inject, observer } from 'mobx-react'; -import { SettingsStore } from 'src/stores.types'; +import { DefaultProps } from 'src/@types/ferdium-components.types'; import Locked from '../../components/auth/Locked'; import { hash } from '../../helpers/password-helpers'; -import UserStore from '../../stores/UserStore'; -interface IProps { - actions: { - settings: SettingsStore; - }; - stores: { - settings: SettingsStore; - user: UserStore; - }; -} - -class LockedScreen extends Component { +class LockedScreen extends Component { state = { error: false, }; - constructor(props) { + constructor(props: DefaultProps) { super(props); this.onSubmit = this.onSubmit.bind(this); this.unlock = this.unlock.bind(this); } - onSubmit(values): void { + onSubmit(values: any): void { const { password } = values; let correctPassword = this.props.stores.settings.all.app.lockedPassword; diff --git a/src/containers/auth/LoginScreen.js b/src/containers/auth/LoginScreen.js deleted file mode 100644 index f8351f458..000000000 --- a/src/containers/auth/LoginScreen.js +++ /dev/null @@ -1,41 +0,0 @@ -import { Component } from 'react'; -import PropTypes from 'prop-types'; -import { inject, observer } from 'mobx-react'; -import Login from '../../components/auth/Login'; -import UserStore from '../../stores/UserStore'; - -import { globalError as globalErrorPropType } from '../../prop-types'; - -class LoginScreen extends Component { - static propTypes = { - error: globalErrorPropType.isRequired, - }; - - render() { - const { actions, stores, error } = this.props; - return ( - - ); - } -} - -LoginScreen.propTypes = { - actions: PropTypes.shape({ - user: PropTypes.instanceOf(UserStore).isRequired, - }).isRequired, - stores: PropTypes.shape({ - user: PropTypes.instanceOf(UserStore).isRequired, - }).isRequired, -}; - -export default inject('stores', 'actions')(observer(LoginScreen)); diff --git a/src/containers/auth/LoginScreen.tsx b/src/containers/auth/LoginScreen.tsx new file mode 100644 index 000000000..4c5271fe1 --- /dev/null +++ b/src/containers/auth/LoginScreen.tsx @@ -0,0 +1,29 @@ +import { Component, ReactElement } from 'react'; +import { inject, observer } from 'mobx-react'; +import { DefaultProps, GlobalError } from 'src/@types/ferdium-components.types'; +import Login from '../../components/auth/Login'; + +interface LoginScreenProps extends DefaultProps { + error: GlobalError; +} + +class LoginScreen extends Component { + render(): ReactElement { + const { actions, stores, error } = this.props; + return ( + + ); + } +} + +export default inject('stores', 'actions')(observer(LoginScreen)); diff --git a/src/containers/auth/PasswordScreen.tsx b/src/containers/auth/PasswordScreen.tsx index d88549712..3176e5a8b 100644 --- a/src/containers/auth/PasswordScreen.tsx +++ b/src/containers/auth/PasswordScreen.tsx @@ -1,19 +1,10 @@ -import { Component } from 'react'; +import { Component, ReactElement } from 'react'; import { inject, observer } from 'mobx-react'; -import { UserStore } from 'src/stores.types'; +import { DefaultProps } from 'src/@types/ferdium-components.types'; import Password from '../../components/auth/Password'; -interface IProps { - actions: { - user: UserStore; - }; - stores: { - user: UserStore; - }; -}; - -class PasswordScreen extends Component { - render() { +class PasswordScreen extends Component { + render(): ReactElement { const { actions, stores } = this.props; return ( diff --git a/src/containers/auth/SetupAssistantScreen.tsx b/src/containers/auth/SetupAssistantScreen.tsx index 8f1871776..92f12c0bc 100644 --- a/src/containers/auth/SetupAssistantScreen.tsx +++ b/src/containers/auth/SetupAssistantScreen.tsx @@ -1,29 +1,12 @@ /* eslint-disable no-await-in-loop */ -import { Component } from 'react'; +import { Component, ReactElement } from 'react'; import { inject, observer } from 'mobx-react'; -import { RouterStore } from 'mobx-react-router'; +import { DefaultProps } from 'src/@types/ferdium-components.types'; import { sleep } from '../../helpers/async-helpers'; import SetupAssistant from '../../components/auth/SetupAssistant'; -import ServicesStore from '../../stores/ServicesStore'; -import RecipesStore from '../../stores/RecipesStore'; -import UserStore from '../../stores/UserStore'; -interface IProps { - stores: { - services: ServicesStore; - router: RouterStore; - recipes?: RecipesStore; - user?: UserStore; - }; - actions: { - user: UserStore; - service: ServicesStore; - recipe: RecipesStore; - }; -}; - -class SetupAssistantScreen extends Component { +class SetupAssistantScreen extends Component { state = { isSettingUpServices: false, }; @@ -68,7 +51,7 @@ class SetupAssistantScreen extends Component { }, }; - async setupServices(serviceConfig) { + async setupServices(serviceConfig: any): Promise { const { stores: { services, router }, } = this.props; @@ -103,7 +86,7 @@ class SetupAssistantScreen extends Component { router.push('/'); } - render() { + render(): ReactElement { return ( this.setupServices(config)} diff --git a/src/containers/auth/SignupScreen.js b/src/containers/auth/SignupScreen.js deleted file mode 100644 index 3824e47d5..000000000 --- a/src/containers/auth/SignupScreen.js +++ /dev/null @@ -1,46 +0,0 @@ -import { Component } from 'react'; -import PropTypes from 'prop-types'; -import { inject, observer } from 'mobx-react'; - -import Signup from '../../components/auth/Signup'; -import UserStore from '../../stores/UserStore'; -import FeaturesStore from '../../stores/FeaturesStore'; - -import { globalError as globalErrorPropType } from '../../prop-types'; - -class SignupScreen extends Component { - static propTypes = { - error: globalErrorPropType.isRequired, - }; - - onSignup(values) { - const { actions } = this.props; - - actions.user.signup(values); - } - - render() { - const { stores, error } = this.props; - - return ( - this.onSignup(values)} - isSubmitting={stores.user.signupRequest.isExecuting} - loginRoute={stores.user.loginRoute} - error={error} - /> - ); - } -} - -SignupScreen.propTypes = { - actions: PropTypes.shape({ - user: PropTypes.instanceOf(UserStore).isRequired, - }).isRequired, - stores: PropTypes.shape({ - user: PropTypes.instanceOf(UserStore).isRequired, - features: PropTypes.instanceOf(FeaturesStore).isRequired, - }).isRequired, -}; - -export default inject('stores', 'actions')(observer(SignupScreen)); diff --git a/src/containers/auth/SignupScreen.tsx b/src/containers/auth/SignupScreen.tsx new file mode 100644 index 000000000..1dac392ef --- /dev/null +++ b/src/containers/auth/SignupScreen.tsx @@ -0,0 +1,32 @@ +import { Component, ReactElement } from 'react'; +import { inject, observer } from 'mobx-react'; + +import { DefaultProps, GlobalError } from 'src/@types/ferdium-components.types'; +import Signup from '../../components/auth/Signup'; + +interface SignUpScreenComponents extends DefaultProps { + error: GlobalError; +} + +class SignupScreen extends Component { + onSignup(values: any): void { + const { actions } = this.props; + + actions.user.signup(values); + } + + render(): ReactElement { + const { stores, error } = this.props; + + return ( + this.onSignup(values)} + isSubmitting={stores.user.signupRequest.isExecuting} + loginRoute={stores.user.loginRoute} + error={error} + /> + ); + } +} + +export default inject('stores', 'actions')(observer(SignupScreen)); diff --git a/src/containers/auth/WelcomeScreen.tsx b/src/containers/auth/WelcomeScreen.tsx index 944d288ad..bbd73f4a2 100644 --- a/src/containers/auth/WelcomeScreen.tsx +++ b/src/containers/auth/WelcomeScreen.tsx @@ -1,19 +1,11 @@ -import { Component } from 'react'; +import { Component, ReactElement } from 'react'; import { inject, observer } from 'mobx-react'; +import { DefaultProps } from 'src/@types/ferdium-components.types'; import Welcome from '../../components/auth/Welcome'; -import UserStore from '../../stores/UserStore'; -import RecipePreviewsStore from '../../stores/RecipePreviewsStore'; -interface IProps { - stores: { - user: UserStore, - recipePreviews: RecipePreviewsStore, - }, -}; - -class WelcomeScreen extends Component { - render() { +class WelcomeScreen extends Component { + render(): ReactElement { const { user, recipePreviews } = this.props.stores; return ( diff --git a/src/features/workspaces/containers/EditWorkspaceScreen.tsx b/src/features/workspaces/containers/EditWorkspaceScreen.tsx index 0351ddafb..f0c7e4574 100644 --- a/src/features/workspaces/containers/EditWorkspaceScreen.tsx +++ b/src/features/workspaces/containers/EditWorkspaceScreen.tsx @@ -6,7 +6,7 @@ import EditWorkspaceForm from '../components/EditWorkspaceForm'; import Workspace from '../models/Workspace'; import { workspaceStore } from '../index'; import { deleteWorkspaceRequest, updateWorkspaceRequest } from '../api'; -import { ServicesStore, WorkspacesStore } from '../../../stores.types'; +import { ServicesStore, WorkspacesStore } from '../../../@types/stores.types'; type Props = { actions: { diff --git a/src/features/workspaces/containers/WorkspacesScreen.tsx b/src/features/workspaces/containers/WorkspacesScreen.tsx index 33808b69d..5b153fb50 100644 --- a/src/features/workspaces/containers/WorkspacesScreen.tsx +++ b/src/features/workspaces/containers/WorkspacesScreen.tsx @@ -9,7 +9,7 @@ import { getUserWorkspacesRequest, updateWorkspaceRequest, } from '../api'; -import { WorkspacesStore } from '../../../stores.types'; +import { WorkspacesStore } from '../../../@types/stores.types'; type Props = { actions: { diff --git a/src/helpers/async-helpers.ts b/src/helpers/async-helpers.ts index 56051b065..6556a0141 100644 --- a/src/helpers/async-helpers.ts +++ b/src/helpers/async-helpers.ts @@ -1,4 +1,4 @@ -export function sleep(ms: number = 0) { +export function sleep(ms: number = 0): Promise { // eslint-disable-next-line no-promise-executor-return return new Promise(r => setTimeout(r, ms)); } diff --git a/src/stores.types.ts b/src/stores.types.ts deleted file mode 100644 index 1899db92c..000000000 --- a/src/stores.types.ts +++ /dev/null @@ -1,367 +0,0 @@ -import Workspace from './features/workspaces/models/Workspace'; -import Recipe from './models/Recipe'; -import Service from './models/Service'; -import User from './models/User'; -import { Request } from './stores/lib/Request'; -import { CachedRequest } from './stores/lib/CachedRequest'; -import Reaction from './stores/lib/Reaction'; - -export interface FerdiumStores { - app: AppStore; - communityRecipes: CommunityRecipesStore; - features: FeaturesStore; - globalError: GlobalErrorStore; - recipePreviews: RecipePreviewsStore; - recipes: RecipeStore; - requests: RequestsStore; - router: RouterStore; - services: ServicesStore; - settings: SettingsStore; - todos: TodosStore; - ui: UIStore; - user: UserStore; - workspaces: WorkspacesStore; -} - -export interface Stores { - app: AppStore; - communityRecipes: CommunityRecipesStore; - features: FeaturesStore; - globalError: GlobalErrorStore; - recipePreviews: RecipePreviewsStore; - recipes: RecipeStore; - requests: RequestsStore; - router: RouterStore; - services: ServicesStore; - settings: SettingsStore; - todos: TodosStore; - ui: UIStore; - user: UserStore; - workspaces: WorkspacesStore; -} - -interface Actions { - app: AppStore; - recipePreviews: RecipePreviewsStore; - recipes: RecipeStore; - requests: RequestsStore; - services: ServicesStore; - settings: SettingsStore; - todos: TodosStore; - ui: UIStore; - user: UserStore; - workspaces: WorkspacesStore; -} - -interface Api { - app: AppStore; - features: FeaturesStore; - local: {}; - recipePreviews: RecipePreviewsStore; - recipes: RecipeStore; - services: ServicesStore; - user: UserStore; -} - -interface TypedStore { - actions: Actions; - api: Api; - stores: Stores; - _reactions: Reaction[]; - _status: any; - actionStatus: () => void; - initialize: () => void; - tearDown: () => void; - resetStatus: () => void; -} - -interface AppStore extends TypedStore { - accentColor: string; - adaptableDarkMode: boolean; - progressbarAccentColor: string; - authRequestFailed: () => void; - autoLaunchOnStart: () => void; - automaticUpdates: boolean; - clearAppCacheRequest: () => void; - clipboardNotifications: boolean; - darkMode: boolean; - dictionaries: []; - enableSpellchecking: boolean; - fetchDataInterval: 4; - get(key: string): any; - getAppCacheSizeRequest: () => void; - healthCheckRequest: () => void; - isClearingAllCache: () => void; - isAppMuted: boolean; - isFocused: () => void; - isFullScreen: () => void; - isOnline: boolean; - isSystemDarkModeEnabled: () => void; - isSystemMuteOverridden: () => void; - locale: () => void; - lockedPassword: string; - reloadAfterResume: boolean; - reloadAfterResumeTime: number; - searchEngine: string; - spellcheckerLanguage: string; - splitMode: boolean; - splitColumns: number; - timeOfflineStart: () => void; - timeSuspensionStart: () => void; - updateStatus: () => void; - updateStatusTypes: { - CHECKING: 'CHECKING'; - AVAILABLE: 'AVAILABLE'; - NOT_AVAILABLE: 'NOT_AVAILABLE'; - DOWNLOADED: 'DOWNLOADED'; - FAILED: 'FAILED'; - }; - universalDarkMode: boolean; - cacheSize: () => void; - debugInfo: () => void; -} - -interface CommunityRecipesStore extends TypedStore { - communityRecipes: () => void; -} - -interface FeaturesStore extends TypedStore { - anonymousFeatures: () => void; - defaultFeaturesRequest: () => void; - features: () => void; - featuresRequest: CachedRequest; - _monitorLoginStatus: () => void; - _updateFeatures: () => void; - _setupFeatures: () => void; -} - -interface GlobalErrorStore extends TypedStore { - error: () => void; - messages: () => void; - response: () => void; - _handleRequests: () => void; -} - -interface RecipePreviewsStore extends TypedStore { - allRecipePreviewsRequest: () => void; - searchRecipePreviewsRequest: () => void; - all: Recipe[]; - dev: Recipe[]; - searchResults: () => void; -} - -interface RecipeStore extends TypedStore { - allRecipesRequest: () => void; - getRecipeUpdatesRequest: () => void; - installRecipeRequest: () => void; - isInstalled: (id: string) => boolean; - active: () => void; - all: Recipe[]; - one: (id: string) => Recipe; - recipeIdForServices: () => void; - _install({ recipeId: string }): Promise; -} - -interface RequestsStore extends TypedStore { - localServerPort: () => void; - retries: number; - retryDelay: number; - servicesRequest: () => void; - showRequiredRequestsError: () => void; - userInfoRequest: () => void; - areRequiredRequestsLoading: () => void; - areRequiredRequestsSuccessful: () => void; -} - -interface RouterStore { - go: () => void; - goBack: () => void; - goForward: () => void; - history: () => void; - location: { - pathname: string; - search: string; - action: string; - key: string; - state: any; - query: any; - hash?: string; - basename?: string; - }; - push(path: string): void; - replace: () => void; -} - -export interface ServicesStore extends TypedStore { - clearCacheRequest: () => void; - createServiceRequest: CachedRequest; - deleteServiceRequest: () => void; - allServicesRequest: CachedRequest; - filterNeedle: string; - lastUsedServices: () => void; - reorderServicesRequest: () => void; - serviceMaintenanceTick: () => void; - updateServiceRequest: () => void; - active: () => void; - activeSettings: () => void; - all: Service[]; - allDisplayed: () => void; - allDisplayedUnordered: () => void; - enabled: () => void; - filtered: () => void; - isTodosServiceActive: () => void; - isTodosServiceAdded: () => void; -} - -// TODO: Create actual type based on the default config in config.ts -interface ISettings { - [key: string]: any; -} - -export interface SettingsStore extends TypedStore { - update: (value: any) => void; - remove: (value: any) => void; - fileSystemSettingsTypes: any[]; - loaded: boolean; - updateAppSettingsRequest: () => void; - _fileSystemSettingsCache: () => void; - all: ISettings; - app: AppStore; - migration: () => void; - proxy: () => void; - service: ServicesStore; - stats: () => void; -} - -interface TodosStore extends TypedStore { - isFeatureActive: () => void; - isInitialized: true; - userAgentModel: () => void; - webview: () => void; - _allReactions: any[]; - _firstLaunchReaction: () => void; - _goToService: () => void; - _handleNewWindowEvent: () => void; - _onTodosClientInitialized: () => void; - _openDevTools: () => void; - _reload: () => void; - _routeCheckReaction: () => void; - _updateSettings: () => void; - _updateTodosConfig: () => void; - isFeatureEnabledByUser: () => void; - isTodoUrlValid: () => void; - isTodosPanelForceHidden: () => void; - isTodosEnabled: boolean; - isTodosPanelVisible: () => void; - isUsingPredefinedTodoServer: () => void; - settings: { - isFeatureEnabledByUser: boolean; - }; - todoRecipeId: () => void; - todoUrl: () => void; - userAgent: () => void; - width: () => void; - _handleClientMessage: () => void; - _handleHostMessage: () => void; - _resize: () => void; - _setTodosWebview: () => void; - _toggleTodosFeatureVisibility: () => void; - _toggleTodosPanel: () => void; -} - -interface UIStore extends TypedStore { - isOsDarkThemeActive: () => void; - showServicesUpdatedInfoBar: boolean; - isDarkThemeActive: () => void; - isSplitModeActive: () => void; - splitColumnsNo: () => void; - showMessageBadgesEvenWhenMuted: boolean; - theme: () => void; -} - -export interface UserStore extends TypedStore { - BASE_ROUTE: '/auth'; - CHANGE_SERVER_ROUTE: '/auth/server'; - IMPORT_ROUTE: '/auth/signup/import'; - INVITE_ROUTE: '/auth/signup/invite'; - LOGIN_ROUTE: '/auth/login'; - LOGOUT_ROUTE: '/auth/logout'; - PASSWORD_ROUTE: '/auth/password'; - SETUP_ROUTE: '/auth/signup/setup'; - SIGNUP_ROUTE: '/auth/signup'; - WELCOME_ROUTE: '/auth/welcome'; - accountType: () => void; - authToken: () => void; - deleteAccountRequest: () => void; - fetchUserInfoInterval: null; - getLegacyServicesRequest: () => void; - getUserInfoRequest: CachedRequest; - hasCompletedSignup: () => void; - id: () => void; - importLegacyServices: () => Promise; - inviteRequest: () => void; - isImportLegacyServicesCompleted: boolean; - isImportLegacyServicesExecuting: boolean; - isLoggingOut: () => void; - loginRequest: () => void; - logoutReason: () => void; - logoutReasonTypes: { SERVER: 'SERVER' }; - passwordRequest: Request; - retrievePassword: Promise - signupRequest: () => void; - updateUserInfoRequest: () => void; - userData: () => void; - _requireAuthenticatedUser: () => void; - _importLegacyServices: () => void; - _retrievePassword: () => void; - changeServerRoute: () => void; - data: User; - importRoute: string; - inviteRoute: string; - isLoggedIn: boolean; - isTokenExpired: boolean; - legacyServices: () => void; - loginRoute: string; - logoutRoute: string; - passwordRoute: string; - setupRoute: string; - signupRoute: string; - team: () => void; -} - -export interface WorkspacesStore extends TypedStore { - activeWorkspace: () => void; - delete: ({ workspace }) => void; - update: ({ workspace }) => void; - create: ({ workspace }) => void; - edit: ({ workspace }) => void; - saving: boolean; - filterServicesByActiveWorkspace: () => void; - isFeatureActive: () => void; - isAnyWorkspaceActive: boolean; - isSettingsRouteActive: () => void; - isSwitchingWorkspace: () => void; - isWorkspaceDrawerOpen: () => void; - nextWorkspace: () => void; - workspaces: Workspace[]; - workspaceBeingEdited: () => void; - reorderServicesOfActiveWorkspace: ({ - oldIndex, - newIndex, - }: { - oldIndex: string; - newIndex: string; - }) => void; - settings: any; - _activateLastUsedWorkspaceReaction: () => void; - _allActions: any[]; - _allReactions: any[]; - _cleanupInvalidServiceReferences: () => void; - _getWorkspaceById: () => void; - _openDrawerWithSettingsReaction: () => void; - _setActiveServiceOnWorkspaceSwitchReaction: () => void; - _setWorkspaceBeingEditedReaction: () => void; - _toggleKeepAllWorkspacesLoadedSetting: () => void; - _updateSettings: () => void; - _wasDrawerOpenBeforeSettingsRoute: null; -} diff --git a/src/stores/AppStore.ts b/src/stores/AppStore.ts index 5659460c6..f333a0060 100644 --- a/src/stores/AppStore.ts +++ b/src/stores/AppStore.ts @@ -14,7 +14,7 @@ import ms from 'ms'; import { URL } from 'url'; import { readJsonSync } from 'fs-extra'; -import { Stores } from 'src/stores.types'; +import { Stores } from 'src/@types/stores.types'; import { ApiInterface } from 'src/api'; import { Actions } from 'src/actions/lib/actions'; import TypedStore from './lib/TypedStore'; diff --git a/src/stores/GlobalErrorStore.ts b/src/stores/GlobalErrorStore.ts index cb364574b..fcc1276c8 100644 --- a/src/stores/GlobalErrorStore.ts +++ b/src/stores/GlobalErrorStore.ts @@ -1,7 +1,7 @@ import { observable, action } from 'mobx'; import { Actions } from 'src/actions/lib/actions'; import { ApiInterface } from 'src/api'; -import { Stores } from 'src/stores.types'; +import { Stores } from 'src/@types/stores.types'; import Request from './lib/Request'; import TypedStore from './lib/TypedStore'; diff --git a/src/stores/RecipePreviewsStore.ts b/src/stores/RecipePreviewsStore.ts index 500f69b40..099867785 100644 --- a/src/stores/RecipePreviewsStore.ts +++ b/src/stores/RecipePreviewsStore.ts @@ -2,7 +2,7 @@ import { action, computed, observable } from 'mobx'; import { Actions } from 'src/actions/lib/actions'; import { ApiInterface } from 'src/api'; import Recipe from 'src/models/Recipe'; -import { Stores } from 'src/stores.types'; +import { Stores } from 'src/@types/stores.types'; import CachedRequest from './lib/CachedRequest'; import Request from './lib/Request'; diff --git a/src/stores/RecipesStore.ts b/src/stores/RecipesStore.ts index af2aa7fb0..d63e46bef 100644 --- a/src/stores/RecipesStore.ts +++ b/src/stores/RecipesStore.ts @@ -2,7 +2,7 @@ import { action, computed, observable } from 'mobx'; import { readJSONSync } from 'fs-extra'; import semver from 'semver'; -import { Stores } from 'src/stores.types'; +import { Stores } from 'src/@types/stores.types'; import { ApiInterface } from 'src/api'; import { Actions } from 'src/actions/lib/actions'; import Recipe from 'src/models/Recipe'; diff --git a/src/stores/RequestStore.ts b/src/stores/RequestStore.ts index 03ad2c7db..af686388a 100644 --- a/src/stores/RequestStore.ts +++ b/src/stores/RequestStore.ts @@ -4,7 +4,7 @@ import ms from 'ms'; import { Actions } from 'src/actions/lib/actions'; import { ApiInterface } from 'src/api'; -import { Stores } from 'src/stores.types'; +import { Stores } from 'src/@types/stores.types'; import CachedRequest from './lib/CachedRequest'; import { LOCAL_PORT } from '../config'; diff --git a/src/stores/ServicesStore.ts b/src/stores/ServicesStore.ts index caa44146f..0164d092a 100644 --- a/src/stores/ServicesStore.ts +++ b/src/stores/ServicesStore.ts @@ -5,7 +5,7 @@ import ms from 'ms'; import { ensureFileSync, pathExistsSync, writeFileSync } from 'fs-extra'; import { join } from 'path'; -import { Stores } from 'src/stores.types'; +import { Stores } from 'src/@types/stores.types'; import { ApiInterface } from 'src/api'; import { Actions } from 'src/actions/lib/actions'; import Request from './lib/Request'; diff --git a/src/stores/SettingsStore.ts b/src/stores/SettingsStore.ts index 524f2e50c..dabd7b099 100644 --- a/src/stores/SettingsStore.ts +++ b/src/stores/SettingsStore.ts @@ -2,7 +2,7 @@ import { ipcRenderer } from 'electron'; import { getCurrentWindow } from '@electron/remote'; import { action, computed, observable, reaction } from 'mobx'; import localStorage from 'mobx-localstorage'; -import { Stores } from 'src/stores.types'; +import { Stores } from 'src/@types/stores.types'; import { ApiInterface } from 'src/api'; import { Actions } from 'src/actions/lib/actions'; import { diff --git a/src/stores/UIStore.ts b/src/stores/UIStore.ts index 306b14cb1..e9e099ebc 100644 --- a/src/stores/UIStore.ts +++ b/src/stores/UIStore.ts @@ -1,7 +1,7 @@ import { action, observable, computed, reaction } from 'mobx'; import { nativeTheme } from '@electron/remote'; -import { Stores } from 'src/stores.types'; +import { Stores } from 'src/@types/stores.types'; import { ApiInterface } from 'src/api'; import { Actions } from 'src/actions/lib/actions'; import { Theme, theme, ThemeType } from '../themes'; diff --git a/src/stores/UserStore.ts b/src/stores/UserStore.ts index 616ff29a6..0827f8196 100644 --- a/src/stores/UserStore.ts +++ b/src/stores/UserStore.ts @@ -6,7 +6,7 @@ import { ipcRenderer } from 'electron'; import { ApiInterface } from 'src/api'; import { Actions } from 'src/actions/lib/actions'; -import { Stores } from 'src/stores.types'; +import { Stores } from 'src/@types/stores.types'; import { TODOS_PARTITION_ID } from '../config'; import { isDevMode } from '../environment-remote'; import Request from './lib/Request'; diff --git a/src/stores/index.ts b/src/stores/index.ts index a5b1a7452..aac501cda 100644 --- a/src/stores/index.ts +++ b/src/stores/index.ts @@ -1,4 +1,3 @@ -import { Stores } from 'src/stores.types'; import { RouterStore } from 'mobx-react-router'; import { ApiInterface } from 'src/api'; import { Actions } from 'src/actions/lib/actions'; @@ -16,12 +15,29 @@ import { workspaceStore } from '../features/workspaces'; import { communityRecipesStore } from '../features/communityRecipes'; import { todosStore } from '../features/todos'; +export interface RealStores { + router: RouterStore; + app: AppStore; + user: UserStore; + features: FeaturesStore; + settings: SettingsStore; + services: ServicesStore; + recipes: RecipesStore; + recipePreviews: RecipePreviewsStore; + ui: UIStore; + requests: RequestStore; + globalError: GlobalErrorStore; + workspaces: typeof workspaceStore; + communityRecipes: typeof communityRecipesStore; + todos: typeof todosStore; +} + export default ( api: ApiInterface, actions: Actions, router: RouterStore, -): Stores => { - const stores: Stores | any = {}; +): RealStores => { + const stores: RealStores | any = {}; Object.assign(stores, { router, app: new AppStore(stores, api, actions), diff --git a/src/stores/lib/TypedStore.ts b/src/stores/lib/TypedStore.ts index 7f9d2d60f..c78f83850 100644 --- a/src/stores/lib/TypedStore.ts +++ b/src/stores/lib/TypedStore.ts @@ -1,7 +1,7 @@ import { computed, IReactionPublic, observable } from 'mobx'; import { Actions } from 'src/actions/lib/actions'; import { ApiInterface } from 'src/api'; -import { Stores } from 'src/stores.types'; +import { Stores } from 'src/@types/stores.types'; import Reaction from './Reaction'; export default abstract class TypedStore { diff --git a/src/types.ts b/src/types.ts deleted file mode 100644 index db8711cd3..000000000 --- a/src/types.ts +++ /dev/null @@ -1,22 +0,0 @@ -declare global { - interface Window { - ferdium: any; - } - - namespace NodeJS { - interface ProcessEnv { - GITHUB_AUTH_TOKEN: string; - NODE_ENV: 'development' | 'production'; - FERDIUM_APPDATA_DIR?: string; - PORTABLE_EXECUTABLE_DIR?: string; - ELECTRON_IS_DEV?: string; - APPDATA?: string; - } - } -} - -/** - * Workaround to make TS recognize this file as a module. - * https://fettblog.eu/typescript-augmenting-global-lib-dom/ - */ -export {}; -- cgit v1.2.3-54-g00ecf