From 85927dc191a935761b3f175bcd50e7c3076acc9e Mon Sep 17 00:00:00 2001 From: MCMXC <16797721+mcmxcdev@users.noreply.github.com> Date: Fri, 22 Dec 2023 15:12:16 -0700 Subject: refactor: remove unused code with knip (#1492) - remove unused code snippets flagged by `npx knip` --- src/@types/stores.types.ts | 8 -------- src/api/UserApi.ts | 4 ---- src/api/server/ServerApi.ts | 36 +----------------------------------- src/config.ts | 11 +---------- src/environment-remote.ts | 7 ------- src/features/workspaces/store.ts | 5 ----- src/models/User.ts | 2 -- src/stores/AppStore.ts | 2 -- src/stores/SettingsStore.ts | 6 ------ src/stores/UserStore.ts | 27 --------------------------- src/stores/lib/Request.ts | 9 --------- 11 files changed, 2 insertions(+), 115 deletions(-) diff --git a/src/@types/stores.types.ts b/src/@types/stores.types.ts index 973889802..d036f8ee1 100644 --- a/src/@types/stores.types.ts +++ b/src/@types/stores.types.ts @@ -90,7 +90,6 @@ export interface AppStore extends TypedStore { clearAppCacheRequest: () => void; clipboardNotifications: boolean; darkMode: boolean; - dictionaries: []; enableSpellchecking: boolean; enableTranslator: boolean; fetchDataInterval: 4; @@ -234,7 +233,6 @@ interface SettingsStore extends TypedStore { remove: (value: any) => void; fileSystemSettingsTypes: any[]; loaded: boolean; - updateAppSettingsRequest: () => void; _fileSystemSettingsCache: () => void; all: ISettings; app: AppStore; @@ -304,7 +302,6 @@ interface UserStore extends TypedStore { accountType: () => void; authToken: () => void; deleteAccountRequest: () => void; - fetchUserInfoInterval: null; getLegacyServicesRequest: () => void; getUserInfoRequest: CachedRequest; hasCompletedSignup: () => void; @@ -327,15 +324,10 @@ interface UserStore extends TypedStore { _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; } diff --git a/src/api/UserApi.ts b/src/api/UserApi.ts index 9364b3383..38f489131 100644 --- a/src/api/UserApi.ts +++ b/src/api/UserApi.ts @@ -52,10 +52,6 @@ export default class UserApi { return this.server.updateUserInfo(userData); } - getLegacyServices() { - return this.server.getLegacyServices(); - } - delete() { return this.server.deleteAccount(); } diff --git a/src/api/server/ServerApi.ts b/src/api/server/ServerApi.ts index 1530dd478..9e7582e1e 100644 --- a/src/api/server/ServerApi.ts +++ b/src/api/server/ServerApi.ts @@ -22,7 +22,7 @@ import UserModel from '../../models/User'; import sleep from '../../helpers/async-helpers'; import { SERVER_NOT_LOADED } from '../../config'; -import { userDataRecipesPath, userDataPath } from '../../environment-remote'; +import { userDataRecipesPath } from '../../environment-remote'; import { asarRecipesPath } from '../../helpers/asar-helpers'; import apiBase from '../apiBase'; import { @@ -500,40 +500,6 @@ export default class ServerApi { debug('ServerApi::healthCheck resolves'); } - async getLegacyServices() { - const file = userDataPath('settings', 'services.json'); - - try { - const config = readJsonSync(file); - - if (Object.hasOwn(config, 'services')) { - const services = await Promise.all( - config.services.map(async (s: { service: any }) => { - const service = s; - const request = await sendAuthRequest( - `${apiBase()}/recipes/${s.service}`, - ); - - if (request.status === 200) { - const data = await request.json(); - // @ts-expect-error Property 'recipe' does not exist on type '{ service: any; }'. - service.recipe = new RecipePreviewModel(data); - } - - return service; - }), - ); - - debug('ServerApi::getLegacyServices resolves', services); - return services; - } - } catch { - console.error('ServerApi::getLegacyServices no config found'); - } - - return []; - } - // Helper async _mapServiceModels(services: any[]) { const recipes = services.map((s: { recipeId: string }) => s.recipeId); diff --git a/src/config.ts b/src/config.ts index 922b01628..fd1b1cced 100644 --- a/src/config.ts +++ b/src/config.ts @@ -27,12 +27,8 @@ export const LIVE_API_FERDIUM_WEBSITE = 'https://ferdium.org'; export const LIVE_API_FERDIUM_LIBRETRANSLATE = 'https://translator.ferdium.org/translate'; -export const STATS_API = 'https://stats.franzinfra.com'; - export const LOCAL_TODOS_FRONTEND_URL = 'http://localhost:4000'; export const PRODUCTION_TODOS_FRONTEND_URL = 'https://app.franztodos.com'; -export const DEVELOPMENT_TODOS_FRONTEND_URL = - 'https://development--franz-todos.netlify.com'; export const CDN_URL = 'https://cdn.franzinfra.com'; @@ -282,11 +278,6 @@ export const TODO_APPS = { [CUSTOM_TODO_SERVICE]: 'Other service', }; -export const DEFAULT_TODO_SERVICE = TODO_TODOIST_URL; -export const DEFAULT_TODO_RECIPE_ID = - TODO_SERVICE_RECIPE_IDS[DEFAULT_TODO_SERVICE]; -export const DEFAULT_TODO_SERVICE_NAME = TODO_APPS[DEFAULT_TODO_SERVICE]; - export const SIDEBAR_WIDTH = { 35: 'Extremely slim sidebar', 45: 'Very slim sidebar', @@ -385,7 +376,7 @@ export const DEFAULT_APP_SETTINGS = { // Ferdium specific options server: LIVE_FERDIUM_API, - predefinedTodoServer: DEFAULT_TODO_SERVICE, + predefinedTodoServer: TODO_TODOIST_URL, autohideMenuBar: false, lockingFeatureEnabled: false, locked: false, diff --git a/src/environment-remote.ts b/src/environment-remote.ts index da1477346..7662d69a0 100644 --- a/src/environment-remote.ts +++ b/src/environment-remote.ts @@ -10,8 +10,6 @@ import { LIVE_WS_API, LOCAL_WS_API, DEV_WS_API, - LOCAL_TODOS_FRONTEND_URL, - PRODUCTION_TODOS_FRONTEND_URL, } from './config'; import { isWindows } from './environment'; @@ -56,28 +54,23 @@ export const useLiveAPI = process.env.USE_LIVE_API; let api: string; let wsApi: string; let web: string; -let todos: string; if (!isDevMode || (isDevMode && useLiveAPI)) { api = LIVE_FERDIUM_API; wsApi = LIVE_WS_API; web = LIVE_API_FERDIUM_WEBSITE; - todos = PRODUCTION_TODOS_FRONTEND_URL; } else if (isDevMode && useLocalAPI) { api = LOCAL_API; wsApi = LOCAL_WS_API; web = LOCAL_API_WEBSITE; - todos = LOCAL_TODOS_FRONTEND_URL; } else { api = DEV_FRANZ_API; wsApi = DEV_WS_API; web = DEV_API_FRANZ_WEBSITE; - todos = PRODUCTION_TODOS_FRONTEND_URL; } export const API: string = api; export const API_VERSION: string = 'v1'; export const WS_API: string = wsApi; export const WEBSITE: string = web; -export const TODOS_FRONTEND: string = todos; // For deeplink protocol: 'ferdium' or 'ferdium-dev' if we want '{DEEPLINK_PROTOCOL_CLIENT}://' export const protocolClient = isDevMode ? 'ferdium-dev' : 'ferdium'; diff --git a/src/features/workspaces/store.ts b/src/features/workspaces/store.ts index 34a4126c8..f97009186 100644 --- a/src/features/workspaces/store.ts +++ b/src/features/workspaces/store.ts @@ -51,11 +51,6 @@ export default class WorkspacesStore extends FeatureStore { return getUserWorkspacesRequest.result || []; } - @computed get isLoadingWorkspaces() { - if (!this.isFeatureActive) return false; - return getUserWorkspacesRequest.isExecutingFirstTime; - } - @computed get settings() { return localStorage.getItem('workspaces') || {}; } diff --git a/src/models/User.ts b/src/models/User.ts index 6540a14e9..f89ea0465 100644 --- a/src/models/User.ts +++ b/src/models/User.ts @@ -27,8 +27,6 @@ export default class User { @observable accountType: string | null = null; - @observable emailIsConfirmed = true; - // Note: Kept around to be able to handle the response from Franz server // better assume it's confirmed to avoid noise @observable subscription = {}; diff --git a/src/stores/AppStore.ts b/src/stores/AppStore.ts index 9af0a9a4f..b8c980dea 100644 --- a/src/stores/AppStore.ts +++ b/src/stores/AppStore.ts @@ -126,8 +126,6 @@ export default class AppStore extends TypedStore { @observable launchInBackground = DEFAULT_APP_SETTINGS.autoLaunchInBackground; - dictionaries = []; - fetchDataInterval: NodeJS.Timeout | null = null; @observable downloads: Download[] = []; diff --git a/src/stores/SettingsStore.ts b/src/stores/SettingsStore.ts index 90cd82690..2e8568134 100644 --- a/src/stores/SettingsStore.ts +++ b/src/stores/SettingsStore.ts @@ -11,17 +11,11 @@ import { LOCAL_SERVER, } from '../config'; import { hash } from '../helpers/password-helpers'; -import Request from './lib/Request'; import TypedStore from './lib/TypedStore'; const debug = require('../preload-safe-debug')('Ferdium:SettingsStore'); export default class SettingsStore extends TypedStore { - @observable updateAppSettingsRequest = new Request( - this.api.local, - 'updateAppSettings', - ); - @observable loaded: boolean = false; fileSystemSettingsTypes = FILE_SYSTEM_SETTINGS_TYPES; diff --git a/src/stores/UserStore.ts b/src/stores/UserStore.ts index f98f7d340..9c3fcd3b9 100644 --- a/src/stores/UserStore.ts +++ b/src/stores/UserStore.ts @@ -60,11 +60,6 @@ export default class UserStore extends TypedStore { 'updateInfo', ); - @observable getLegacyServicesRequest: CachedRequest = new CachedRequest( - this.api.user, - 'getLegacyServices', - ); - @observable deleteAccountRequest: CachedRequest = new CachedRequest( this.api.user, 'delete', @@ -93,8 +88,6 @@ export default class UserStore extends TypedStore { @observable logoutReason: string | null = null; - fetchUserInfoInterval = null; - constructor(stores: Stores, api: ApiInterface, actions: Actions) { super(stores, api, actions); @@ -132,26 +125,10 @@ export default class UserStore extends TypedStore { return this.LOGIN_ROUTE; } - get logoutRoute(): string { - return this.LOGOUT_ROUTE; - } - get signupRoute(): string { return this.SIGNUP_ROUTE; } - get setupRoute(): string { - return this.SETUP_ROUTE; - } - - get inviteRoute(): string { - return this.INVITE_ROUTE; - } - - get importRoute(): string { - return this.IMPORT_ROUTE; - } - get passwordRoute(): string { return this.PASSWORD_ROUTE; } @@ -191,10 +168,6 @@ export default class UserStore extends TypedStore { return this.data.team || null; } - @computed get legacyServices(): any { - return this.getLegacyServicesRequest.execute() || {}; - } - // Actions @action async _login({ email, password }): Promise { const authToken = await this.loginRequest.execute(email, password).promise; diff --git a/src/stores/lib/Request.ts b/src/stores/lib/Request.ts index 911c5ccfb..587af87d7 100644 --- a/src/stores/lib/Request.ts +++ b/src/stores/lib/Request.ts @@ -1,5 +1,4 @@ import { observable, action, computed, makeObservable } from 'mobx'; -import { isEqual } from 'lodash/fp'; // eslint-disable-next-line no-use-before-define type Hook = (request: Request) => void; @@ -123,14 +122,6 @@ export default class Request { return this.execute(...args); } - isExecutingWithArgs(...args: any[]): boolean { - return ( - this.isExecuting && - this.currentApiCall && - isEqual(this.currentApiCall.args, args) - ); - } - @computed get isExecutingFirstTime(): boolean { return !this.wasExecuted && this.isExecuting; } -- cgit v1.2.3-54-g00ecf