Client - fix type errors

This commit is contained in:
Sam
2023-11-11 20:16:18 +01:00
parent b6d6a91549
commit 473d0aca53
48 changed files with 228 additions and 118 deletions

View File

@ -12,6 +12,7 @@ import {
import { utcToZonedTime } from 'date-fns-tz'
import createI18n from '@/i18n'
import type { TLanguage } from '@/types/locales'
import { localeFromLanguage } from '@/utils/locales'
const { locale } = createI18n.global
@ -114,7 +115,7 @@ export const formatDate = (
timezone: string,
dateFormat: string,
withTime = true,
language: string | null = null,
language: TLanguage | null = null,
withSeconds = false
): string => {
if (!language) {
@ -131,9 +132,9 @@ export const formatDate = (
export const availableDateFormatOptions = (
inputDate: string,
timezone: string,
language: string | null = null
language: TLanguage | null = null
) => {
const l: string = language ? language : locale.value
const l: TLanguage = language ? language : locale.value
const options: Record<string, string>[] = []
availableDateFormats.map((df) => {
const dateFormat = getDateFormat(df, l)

View File

@ -1,16 +1,23 @@
import type { IFileSize } from '@/types/application'
const suffixes = ['bytes', 'KB', 'MB', 'GB', 'TB']
export const getReadableFileSize = (
fileSize: number,
asText = true
): string | Record<string, string> => {
const i = Math.floor(Math.log(fileSize) / Math.log(1024))
export const getReadableFileSize = (fileSize: number): IFileSize => {
if (!fileSize) {
return asText ? '0 bytes' : { size: '0', suffix: 'bytes' }
return { size: '0', suffix: 'bytes' }
}
const i = Math.floor(Math.log(fileSize) / Math.log(1024))
const size = (fileSize / Math.pow(1024, i)).toFixed(1)
const suffix = suffixes[i]
return asText ? `${size}${suffix}` : { size, suffix }
return { size, suffix }
}
export const getReadableFileSizeAsText = (fileSize: number): string => {
if (!fileSize) {
return '0 bytes'
}
const readableFileSize = getReadableFileSize(fileSize)
return `${readableFileSize.size}${readableFileSize.suffix}`
}
export const getFileSizeInMB = (fileSize: number): number => {

View File

@ -2,20 +2,37 @@ import type { Locale } from 'date-fns'
import { de, enUS, es, fr, gl, it, nb, nl, pl } from 'date-fns/locale'
import createI18n from '@/i18n'
import type { TLanguage } from '@/types/locales'
export const localeFromLanguage: Record<string, Locale> = {
export const isLanguageSupported = (
language: string
): language is TLanguage => {
return (
language === 'de' ||
language === 'en' ||
language === 'es' ||
language === 'fr' ||
language === 'gl' ||
language === 'it' ||
language === 'nb' ||
language === 'nl' ||
language === 'pl'
)
}
export const localeFromLanguage: Record<TLanguage, Locale> = {
de: de,
en: enUS,
es: es,
fr: fr,
gl: gl,
it: it,
pl: pl,
nb: nb,
nl: nl,
pl: pl,
}
export const languageLabels: Record<string, string> = {
export const languageLabels: Record<TLanguage, string> = {
de: 'Deutsch',
en: 'English',
es: 'Español',

View File

@ -12,7 +12,7 @@ export const formatRecord = (
tz: string,
useImperialUnits: boolean,
date_format: string
): Record<string, string | number> => {
): IRecord => {
const distanceUnitFrom: TUnit = 'km'
const distanceUnitTo: TUnit = useImperialUnits
? units[distanceUnitFrom].defaultTarget
@ -57,11 +57,13 @@ export const formatRecord = (
)
}
return {
workout_date: formatDate(record.workout_date, tz, date_format, false),
workout_id: record.workout_id,
id: record.id,
record_type: record.record_type,
sport_id: record.sport_id,
value: value,
user: record.user,
workout_date: formatDate(record.workout_date, tz, date_format, false),
workout_id: record.workout_id,
}
}