refactor: improve stores/config types #3190

Merged
konrad merged 2 commits from WofWca/frontend:refactor into main 2023-03-03 14:37:01 +00:00
3 changed files with 10 additions and 8 deletions

View File

@ -113,8 +113,8 @@ export const checkAndSetApiUrl = (url: string): Promise<string> => {
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
}

View File

@ -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<keyof typeof MIGRATORS>,
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<boolean> {
const HTTP = HTTPFactory()
const {data: config} = await HTTP.get('info')
setConfig(objectToCamelCase(config))
return config
const success = !!config
return success
konrad marked this conversation as resolved
Review

Why not Boolean(config)? Or something like Object.keys(config).length > 0?

Why not `Boolean(config)`? Or something like `Object.keys(config).length > 0`?
Review

No particular reason. I'm just used to !!, and I tried to keep the logic the same.

No particular reason. I'm just used to `!!`, and I tried to keep the logic the same.
Review

Fair enough.

Fair enough.
}
return {

View File

@ -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