From 6a3518daceb12e9e8e421d7d2de5d7e451d75c2a Mon Sep 17 00:00:00 2001 From: WofWca Date: Fri, 3 Mar 2023 14:36:59 +0000 Subject: [PATCH] chore(refactor): improve `stores/config` types (#3190) Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/3190 Reviewed-by: konrad Co-authored-by: WofWca Co-committed-by: WofWca --- src/helpers/checkAndSetApiUrl.ts | 4 ++-- src/stores/config.ts | 10 ++++++---- src/views/migrate/migrators.ts | 4 ++-- 3 files changed, 10 insertions(+), 8 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 2d37693b5..29e4fb37c 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, @@ -78,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 { 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