From bfe8847d72cd0893230f2e654242658214943e61 Mon Sep 17 00:00:00 2001 From: Markus Hatvan Date: Sat, 2 Oct 2021 09:24:32 +0200 Subject: chore: convert various files from JS to TS (#2010) --- src/features/basicAuth/Form.ts | 1 + src/features/communityRecipes/store.js | 32 -------------------- src/features/communityRecipes/store.ts | 39 ++++++++++++++++++++++++ src/features/nightlyBuilds/store.js | 7 ----- src/features/nightlyBuilds/store.ts | 7 +++++ src/features/publishDebugInfo/store.js | 7 ----- src/features/publishDebugInfo/store.ts | 7 +++++ src/features/quickSwitch/store.js | 7 ----- src/features/quickSwitch/store.ts | 7 +++++ src/features/serviceProxy/index.js | 38 ------------------------ src/features/serviceProxy/index.ts | 54 ++++++++++++++++++++++++++++++++++ src/features/settingsWS/actions.js | 10 ------- src/features/settingsWS/actions.ts | 10 +++++++ src/features/settingsWS/index.js | 27 ----------------- src/features/settingsWS/index.ts | 28 ++++++++++++++++++ src/features/settingsWS/state.js | 13 -------- src/features/settingsWS/state.ts | 13 ++++++++ src/features/todos/actions.js | 28 ------------------ src/features/todos/actions.ts | 31 +++++++++++++++++++ src/features/todos/constants.js | 8 ----- src/features/todos/constants.ts | 8 +++++ src/features/todos/index.js | 28 ------------------ src/features/todos/index.ts | 29 ++++++++++++++++++ 23 files changed, 234 insertions(+), 205 deletions(-) delete mode 100644 src/features/communityRecipes/store.js create mode 100644 src/features/communityRecipes/store.ts delete mode 100644 src/features/nightlyBuilds/store.js create mode 100644 src/features/nightlyBuilds/store.ts delete mode 100644 src/features/publishDebugInfo/store.js create mode 100644 src/features/publishDebugInfo/store.ts delete mode 100644 src/features/quickSwitch/store.js create mode 100644 src/features/quickSwitch/store.ts delete mode 100644 src/features/serviceProxy/index.js create mode 100644 src/features/serviceProxy/index.ts delete mode 100755 src/features/settingsWS/actions.js create mode 100755 src/features/settingsWS/actions.ts delete mode 100755 src/features/settingsWS/index.js create mode 100755 src/features/settingsWS/index.ts delete mode 100755 src/features/settingsWS/state.js create mode 100755 src/features/settingsWS/state.ts delete mode 100644 src/features/todos/actions.js create mode 100644 src/features/todos/actions.ts delete mode 100644 src/features/todos/constants.js create mode 100644 src/features/todos/constants.ts delete mode 100644 src/features/todos/index.js create mode 100644 src/features/todos/index.ts (limited to 'src/features') diff --git a/src/features/basicAuth/Form.ts b/src/features/basicAuth/Form.ts index 95721d0e9..e84156d96 100644 --- a/src/features/basicAuth/Form.ts +++ b/src/features/basicAuth/Form.ts @@ -1,5 +1,6 @@ import Form from '../../lib/Form'; +// @ts-expect-error Expected 0 arguments, but got 1 export default new Form({ fields: { user: { diff --git a/src/features/communityRecipes/store.js b/src/features/communityRecipes/store.js deleted file mode 100644 index 05e18e2f7..000000000 --- a/src/features/communityRecipes/store.js +++ /dev/null @@ -1,32 +0,0 @@ -import { computed } from 'mobx'; -import { FeatureStore } from '../utils/FeatureStore'; - -const debug = require('debug')('Ferdi:feature:communityRecipes:store'); - -export class CommunityRecipesStore extends FeatureStore { - start(stores, actions) { - debug('start'); - this.stores = stores; - this.actions = actions; - } - - stop() { - debug('stop'); - super.stop(); - } - - @computed get communityRecipes() { - if (!this.stores) return []; - - return this.stores.recipePreviews.dev.map(recipePreview => { - // TODO: Need to figure out if this is even necessary/used - recipePreview.isDevRecipe = !!recipePreview.author.some( - author => author.email === this.stores.user.data.email, - ); - - return recipePreview; - }); - } -} - -export default CommunityRecipesStore; diff --git a/src/features/communityRecipes/store.ts b/src/features/communityRecipes/store.ts new file mode 100644 index 000000000..a8d358ba0 --- /dev/null +++ b/src/features/communityRecipes/store.ts @@ -0,0 +1,39 @@ +import { computed } from 'mobx'; +import { FeatureStore } from '../utils/FeatureStore'; + +const debug = require('debug')('Ferdi:feature:communityRecipes:store'); + +export class CommunityRecipesStore extends FeatureStore { + stores: any; + + actions: any; + + start(stores: any, actions: any) { + debug('start'); + this.stores = stores; + this.actions = actions; + } + + stop() { + debug('stop'); + super.stop(); + } + + @computed get communityRecipes() { + if (!this.stores) return []; + + return this.stores.recipePreviews.dev.map( + (recipePreview: { isDevRecipe: boolean; author: any[] }) => { + // TODO: Need to figure out if this is even necessary/used + recipePreview.isDevRecipe = !!recipePreview.author.some( + (author: { email: any }) => + author.email === this.stores.user.data.email, + ); + + return recipePreview; + }, + ); + } +} + +export default CommunityRecipesStore; diff --git a/src/features/nightlyBuilds/store.js b/src/features/nightlyBuilds/store.js deleted file mode 100644 index ed06e5a7d..000000000 --- a/src/features/nightlyBuilds/store.js +++ /dev/null @@ -1,7 +0,0 @@ -import { observable } from 'mobx'; - -const defaultState = { - isModalVisible: false, -}; - -export const state = observable(defaultState); diff --git a/src/features/nightlyBuilds/store.ts b/src/features/nightlyBuilds/store.ts new file mode 100644 index 000000000..ed06e5a7d --- /dev/null +++ b/src/features/nightlyBuilds/store.ts @@ -0,0 +1,7 @@ +import { observable } from 'mobx'; + +const defaultState = { + isModalVisible: false, +}; + +export const state = observable(defaultState); diff --git a/src/features/publishDebugInfo/store.js b/src/features/publishDebugInfo/store.js deleted file mode 100644 index ed06e5a7d..000000000 --- a/src/features/publishDebugInfo/store.js +++ /dev/null @@ -1,7 +0,0 @@ -import { observable } from 'mobx'; - -const defaultState = { - isModalVisible: false, -}; - -export const state = observable(defaultState); diff --git a/src/features/publishDebugInfo/store.ts b/src/features/publishDebugInfo/store.ts new file mode 100644 index 000000000..ed06e5a7d --- /dev/null +++ b/src/features/publishDebugInfo/store.ts @@ -0,0 +1,7 @@ +import { observable } from 'mobx'; + +const defaultState = { + isModalVisible: false, +}; + +export const state = observable(defaultState); diff --git a/src/features/quickSwitch/store.js b/src/features/quickSwitch/store.js deleted file mode 100644 index ed06e5a7d..000000000 --- a/src/features/quickSwitch/store.js +++ /dev/null @@ -1,7 +0,0 @@ -import { observable } from 'mobx'; - -const defaultState = { - isModalVisible: false, -}; - -export const state = observable(defaultState); diff --git a/src/features/quickSwitch/store.ts b/src/features/quickSwitch/store.ts new file mode 100644 index 000000000..ed06e5a7d --- /dev/null +++ b/src/features/quickSwitch/store.ts @@ -0,0 +1,7 @@ +import { observable } from 'mobx'; + +const defaultState = { + isModalVisible: false, +}; + +export const state = observable(defaultState); diff --git a/src/features/serviceProxy/index.js b/src/features/serviceProxy/index.js deleted file mode 100644 index b9320cda9..000000000 --- a/src/features/serviceProxy/index.js +++ /dev/null @@ -1,38 +0,0 @@ -import { autorun, observable } from 'mobx'; -import { session } from '@electron/remote'; - -const debug = require('debug')('Ferdi:feature:serviceProxy'); - -export const config = observable({ - isEnabled: true, -}); - -export default function init(stores) { - debug('Initializing `serviceProxy` feature'); - - autorun(() => { - config.isEnabled = true; - - const services = stores.services.enabled; - const proxySettings = stores.settings.proxy; - - debug('Service Proxy autorun'); - - for (const service of services) { - const s = session.fromPartition(`persist:service-${service.id}`); - - if (config.isEnabled) { - const serviceProxyConfig = proxySettings[service.id]; - - if (serviceProxyConfig && serviceProxyConfig.isEnabled && serviceProxyConfig.host) { - const proxyHost = `${serviceProxyConfig.host}${serviceProxyConfig.port ? `:${serviceProxyConfig.port}` : ''}`; - debug(`Setting proxy config from service settings for "${service.name}" (${service.id}) to`, proxyHost); - - s.setProxy({ proxyRules: proxyHost }, () => { - debug(`Using proxy "${proxyHost}" for "${service.name}" (${service.id})`); - }); - } - } - } - }); -} diff --git a/src/features/serviceProxy/index.ts b/src/features/serviceProxy/index.ts new file mode 100644 index 000000000..f095b286a --- /dev/null +++ b/src/features/serviceProxy/index.ts @@ -0,0 +1,54 @@ +import { autorun, observable } from 'mobx'; +import { session } from '@electron/remote'; + +const debug = require('debug')('Ferdi:feature:serviceProxy'); + +export const config = observable({ + isEnabled: true, +}); + +export default function init(stores: { + services: { enabled: any }; + settings: { proxy: any }; +}) { + debug('Initializing `serviceProxy` feature'); + + autorun(() => { + config.isEnabled = true; + + const services = stores.services.enabled; + const proxySettings = stores.settings.proxy; + + debug('Service Proxy autorun'); + + for (const service of services) { + const s = session.fromPartition(`persist:service-${service.id}`); + + if (config.isEnabled) { + const serviceProxyConfig = proxySettings[service.id]; + + if ( + serviceProxyConfig && + serviceProxyConfig.isEnabled && + serviceProxyConfig.host + ) { + const proxyHost = `${serviceProxyConfig.host}${ + serviceProxyConfig.port ? `:${serviceProxyConfig.port}` : '' + }`; + debug( + `Setting proxy config from service settings for "${service.name}" (${service.id}) to`, + proxyHost, + ); + + s.setProxy({ proxyRules: proxyHost }) + .then(() => { + debug( + `Using proxy "${proxyHost}" for "${service.name}" (${service.id})`, + ); + }) + .catch(error => console.error(error)); + } + } + } + }); +} diff --git a/src/features/settingsWS/actions.js b/src/features/settingsWS/actions.js deleted file mode 100755 index 631670c8a..000000000 --- a/src/features/settingsWS/actions.js +++ /dev/null @@ -1,10 +0,0 @@ -import PropTypes from 'prop-types'; -import { createActionsFromDefinitions } from '../../actions/lib/actions'; - -export const settingsWSActions = createActionsFromDefinitions({ - greet: { - name: PropTypes.string.isRequired, - }, -}, PropTypes.checkPropTypes); - -export default settingsWSActions; diff --git a/src/features/settingsWS/actions.ts b/src/features/settingsWS/actions.ts new file mode 100755 index 000000000..631670c8a --- /dev/null +++ b/src/features/settingsWS/actions.ts @@ -0,0 +1,10 @@ +import PropTypes from 'prop-types'; +import { createActionsFromDefinitions } from '../../actions/lib/actions'; + +export const settingsWSActions = createActionsFromDefinitions({ + greet: { + name: PropTypes.string.isRequired, + }, +}, PropTypes.checkPropTypes); + +export default settingsWSActions; diff --git a/src/features/settingsWS/index.js b/src/features/settingsWS/index.js deleted file mode 100755 index 7771421d6..000000000 --- a/src/features/settingsWS/index.js +++ /dev/null @@ -1,27 +0,0 @@ -import { reaction } from 'mobx'; -import { SettingsWSStore } from './store'; - -const debug = require('debug')('Ferdi:feature:settingsWS'); - -export const settingsStore = new SettingsWSStore(); - -export default function initSettingsWebSocket(stores, actions) { - const { features } = stores; - - // Toggle SettingsWebSocket feature - reaction( - () => ( - features.features.isSettingsWSEnabled - ), - (isEnabled) => { - if (isEnabled) { - debug('Initializing `settingsWS` feature'); - settingsStore.start(stores, actions); - } else if (settingsStore) { - debug('Disabling `settingsWS` feature'); - settingsStore.stop(); - } - }, - { fireImmediately: true }, - ); -} diff --git a/src/features/settingsWS/index.ts b/src/features/settingsWS/index.ts new file mode 100755 index 000000000..9bb206d82 --- /dev/null +++ b/src/features/settingsWS/index.ts @@ -0,0 +1,28 @@ +import { reaction } from 'mobx'; +import { SettingsWSStore } from './store'; + +const debug = require('debug')('Ferdi:feature:settingsWS'); + +export const settingsStore = new SettingsWSStore(); + +export default function initSettingsWebSocket( + stores: { features: any }, + actions: any, +) { + const { features } = stores; + + // Toggle SettingsWebSocket feature + reaction( + () => features.features.isSettingsWSEnabled, + isEnabled => { + if (isEnabled) { + debug('Initializing `settingsWS` feature'); + settingsStore.start(stores, actions); + } else if (settingsStore) { + debug('Disabling `settingsWS` feature'); + settingsStore.stop(); + } + }, + { fireImmediately: true }, + ); +} diff --git a/src/features/settingsWS/state.js b/src/features/settingsWS/state.js deleted file mode 100755 index 7b16b2b6e..000000000 --- a/src/features/settingsWS/state.js +++ /dev/null @@ -1,13 +0,0 @@ -import { observable } from 'mobx'; - -const defaultState = { - isFeatureActive: false, -}; - -export const settingsWSState = observable(defaultState); - -export function resetState() { - Object.assign(settingsWSState, defaultState); -} - -export default settingsWSState; diff --git a/src/features/settingsWS/state.ts b/src/features/settingsWS/state.ts new file mode 100755 index 000000000..7b16b2b6e --- /dev/null +++ b/src/features/settingsWS/state.ts @@ -0,0 +1,13 @@ +import { observable } from 'mobx'; + +const defaultState = { + isFeatureActive: false, +}; + +export const settingsWSState = observable(defaultState); + +export function resetState() { + Object.assign(settingsWSState, defaultState); +} + +export default settingsWSState; diff --git a/src/features/todos/actions.js b/src/features/todos/actions.js deleted file mode 100644 index cc17e919b..000000000 --- a/src/features/todos/actions.js +++ /dev/null @@ -1,28 +0,0 @@ -import PropTypes from 'prop-types'; -import { createActionsFromDefinitions } from '../../actions/lib/actions'; - -export const todoActions = createActionsFromDefinitions({ - resize: { - width: PropTypes.number.isRequired, - }, - toggleTodosPanel: {}, - toggleTodosFeatureVisibility: {}, - setTodosWebview: { - webview: PropTypes.instanceOf(Element).isRequired, - }, - handleHostMessage: { - action: PropTypes.string.isRequired, - data: PropTypes.object, - }, - handleClientMessage: { - channel: PropTypes.string.isRequired, - message: PropTypes.shape({ - action: PropTypes.string.isRequired, - data: PropTypes.object, - }), - }, - openDevTools: {}, - reload: {}, -}, PropTypes.checkPropTypes); - -export default todoActions; diff --git a/src/features/todos/actions.ts b/src/features/todos/actions.ts new file mode 100644 index 000000000..04e299e71 --- /dev/null +++ b/src/features/todos/actions.ts @@ -0,0 +1,31 @@ +import PropTypes from 'prop-types'; +import { createActionsFromDefinitions } from '../../actions/lib/actions'; + +export const todoActions = createActionsFromDefinitions( + { + resize: { + width: PropTypes.number.isRequired, + }, + toggleTodosPanel: {}, + toggleTodosFeatureVisibility: {}, + setTodosWebview: { + webview: PropTypes.instanceOf(Element).isRequired, + }, + handleHostMessage: { + action: PropTypes.string.isRequired, + data: PropTypes.object, + }, + handleClientMessage: { + channel: PropTypes.string.isRequired, + message: PropTypes.shape({ + action: PropTypes.string.isRequired, + data: PropTypes.object, + }), + }, + openDevTools: {}, + reload: {}, + }, + PropTypes.checkPropTypes, +); + +export default todoActions; diff --git a/src/features/todos/constants.js b/src/features/todos/constants.js deleted file mode 100644 index 303a7a16e..000000000 --- a/src/features/todos/constants.js +++ /dev/null @@ -1,8 +0,0 @@ -export const IPC = { - TODOS_HOST_CHANNEL: 'TODOS_HOST_CHANNEL', - TODOS_CLIENT_CHANNEL: 'TODOS_CLIENT_CHANNEL', -}; - -export const TODOS_ROUTES = { - TARGET: '/todos', -}; diff --git a/src/features/todos/constants.ts b/src/features/todos/constants.ts new file mode 100644 index 000000000..303a7a16e --- /dev/null +++ b/src/features/todos/constants.ts @@ -0,0 +1,8 @@ +export const IPC = { + TODOS_HOST_CHANNEL: 'TODOS_HOST_CHANNEL', + TODOS_CLIENT_CHANNEL: 'TODOS_CLIENT_CHANNEL', +}; + +export const TODOS_ROUTES = { + TARGET: '/todos', +}; diff --git a/src/features/todos/index.js b/src/features/todos/index.js deleted file mode 100644 index 573190881..000000000 --- a/src/features/todos/index.js +++ /dev/null @@ -1,28 +0,0 @@ -import { reaction } from 'mobx'; -import TodoStore from './store'; - -const debug = require('debug')('Ferdi:feature:todos'); - -export const todosStore = new TodoStore(); - -export default function initTodos(stores, actions) { - stores.todos = todosStore; - const { features } = stores; - - // Toggle todos feature - reaction( - () => ( - features.features.isTodosEnabled - ), - (isEnabled) => { - if (isEnabled) { - debug('Initializing `todos` feature'); - todosStore.start(stores, actions); - } else if (todosStore.isFeatureActive) { - debug('Disabling `todos` feature'); - todosStore.stop(); - } - }, - { fireImmediately: true }, - ); -} diff --git a/src/features/todos/index.ts b/src/features/todos/index.ts new file mode 100644 index 000000000..3665812e6 --- /dev/null +++ b/src/features/todos/index.ts @@ -0,0 +1,29 @@ +import { reaction } from 'mobx'; +import TodoStore from './store'; + +const debug = require('debug')('Ferdi:feature:todos'); + +export const todosStore = new TodoStore(); + +export default function initTodos( + stores: { todos?: any; features?: any }, + actions: any, +) { + stores.todos = todosStore; + const { features } = stores; + + // Toggle todos feature + reaction( + () => features.features.isTodosEnabled, + isEnabled => { + if (isEnabled) { + debug('Initializing `todos` feature'); + todosStore.start(stores, actions); + } else if (todosStore.isFeatureActive) { + debug('Disabling `todos` feature'); + todosStore.stop(); + } + }, + { fireImmediately: true }, + ); +} -- cgit v1.2.3-54-g00ecf