From 2e0a0a3485e02a63fdbf49114bef6d09ac69d0ed Mon Sep 17 00:00:00 2001 From: WofWca Date: Fri, 3 Mar 2023 15:47:46 +0400 Subject: [PATCH 1/2] chore: improve `stores/config` types --- src/stores/config.ts | 5 +++-- src/views/migrate/migrators.ts | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/stores/config.ts b/src/stores/config.ts index 2d37693b5..b6d501f98 100644 --- a/src/stores/config.ts +++ b/src/stores/config.ts @@ -6,6 +6,7 @@ import {HTTPFactory} from '@/helpers/fetcher' import {objectToCamelCase} from '@/helpers/case' import type {IProvider} from '@/types/IProvider' +import type {MIGRATORS} from '@/views/migrate/migrators' export interface ConfigState { version: string, @@ -14,10 +15,10 @@ export interface ConfigState { linkSharingEnabled: boolean, maxFileSize: string, registrationEnabled: boolean, - availableMigrators: [], + availableMigrators: Array, taskAttachmentsEnabled: boolean, totpEnabled: boolean, - enabledBackgroundProviders: [], + enabledBackgroundProviders: Array<'unsplash' | 'upload'>, legal: { imprintUrl: string, privacyPolicyUrl: string, diff --git a/src/views/migrate/migrators.ts b/src/views/migrate/migrators.ts index 3d7cd0abd..8174e1e21 100644 --- a/src/views/migrate/migrators.ts +++ b/src/views/migrate/migrators.ts @@ -16,7 +16,7 @@ interface IMigratorRecord { [key: Migrator['id']]: Migrator } -export const MIGRATORS: IMigratorRecord = { +export const MIGRATORS = { wunderlist: { id: 'wunderlist', name: 'Wunderlist', @@ -49,4 +49,4 @@ export const MIGRATORS: IMigratorRecord = { icon: tickTickIcon as string, isFileMigrator: true, }, -} as const +} as const satisfies IMigratorRecord -- 2.40.1 From 09549847928c1ccdd2e713c2325843b6bb63ac7a Mon Sep 17 00:00:00 2001 From: WofWca Date: Fri, 3 Mar 2023 16:35:41 +0400 Subject: [PATCH 2/2] chore: simplify a function signature --- src/helpers/checkAndSetApiUrl.ts | 4 ++-- src/stores/config.ts | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/helpers/checkAndSetApiUrl.ts b/src/helpers/checkAndSetApiUrl.ts index 6ce65edf2..0dc4595b6 100644 --- a/src/helpers/checkAndSetApiUrl.ts +++ b/src/helpers/checkAndSetApiUrl.ts @@ -113,8 +113,8 @@ export const checkAndSetApiUrl = (url: string): Promise => { window.API_URL = oldUrl throw e }) - .then(r => { - if (typeof r !== 'undefined') { + .then(success => { + if (success) { localStorage.setItem('API_URL', window.API_URL) return window.API_URL } diff --git a/src/stores/config.ts b/src/stores/config.ts index b6d501f98..29e4fb37c 100644 --- a/src/stores/config.ts +++ b/src/stores/config.ts @@ -79,11 +79,12 @@ export const useConfigStore = defineStore('config', () => { function setConfig(config: ConfigState) { Object.assign(state, config) } - async function update() { + async function update(): Promise { const HTTP = HTTPFactory() const {data: config} = await HTTP.get('info') setConfig(objectToCamelCase(config)) - return config + const success = !!config + return success } return { -- 2.40.1