From 366200ba092fb46e72de25073d158733266c8541 Mon Sep 17 00:00:00 2001 From: Arthur Danjou Date: Tue, 29 Jul 2025 15:11:54 +0000 Subject: [PATCH] =?UTF-8?q?Refactor=20les=20types=20pour=20utiliser=20des?= =?UTF-8?q?=20tableaux=20typ=C3=A9s=20et=20am=C3=A9lioration=20de=20la=20s?= =?UTF-8?q?tructure=20des=20messages=20d'activit=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/index.ts | 300 ++++++++++++++++--------------------------------- 1 file changed, 96 insertions(+), 204 deletions(-) diff --git a/types/index.ts b/types/index.ts index a3cb29a..29861f8 100644 --- a/types/index.ts +++ b/types/index.ts @@ -15,13 +15,13 @@ export interface Stats { } } editors: { - data: Array + data: WakatimeData[] } os: { - data: Array + data: WakatimeData[] } languages: { - data: Array + data: WakatimeData[] } } @@ -39,7 +39,7 @@ interface LanyardActivity { export interface Activity { data: { - activities: Array + activities: LanyardActivity[] } } @@ -49,58 +49,74 @@ export const IDEs = [ { name: 'WebStorm', icon: 'i-logos:webstorm' }, { name: 'PyCharm Professional', icon: 'i-logos:pycharm' }, { name: 'Cursor', icon: 'i-vscode-icons-file-type-cursorrules' }, -] +] as const -export const activityMessages = { +type TimeUnit = (n: number, past?: boolean) => string +type TimeFormatter = (n: string) => string + +interface ActivityMessages { + justNow: string + past: TimeFormatter + future: TimeFormatter + month: TimeUnit + year: TimeUnit + day: TimeUnit + week: TimeUnit + hour: TimeUnit + minute: TimeUnit + second: TimeUnit + invalid: string +} + +const createTimeUnit = (singular: string, plural: string, pastSingular?: string, futureSingular?: string): TimeUnit => + (n: number, past = true) => { + if (n === 1) { + return past ? (pastSingular || `last ${singular}`) : (futureSingular || `next ${singular}`) + } + return `${n} ${plural}` + } + +const createSimpleTimeUnit = (unit: string): TimeUnit => + (n: number) => `${n} ${unit}${n > 1 ? 's' : ''}` + +export const activityMessages: Record<'en' | 'fr' | 'es', ActivityMessages> = { en: { justNow: 'just now', - past: (n: string) => (n.match(/\d/) ? `${n} ago` : n), - future: (n: string) => (n.match(/\d/) ? `in ${n}` : n), - month: (n: number, past: boolean) => - n === 1 ? (past ? 'last month' : 'next month') : `${n} month${n > 1 ? 's' : ''}`, - year: (n: number, past: boolean) => - n === 1 ? (past ? 'last year' : 'next year') : `${n} year${n > 1 ? 's' : ''}`, - day: (n: number, past: boolean) => - n === 1 ? (past ? 'yesterday' : 'tomorrow') : `${n} day${n > 1 ? 's' : ''}`, - week: (n: number, past: boolean) => - n === 1 ? (past ? 'last week' : 'next week') : `${n} week${n > 1 ? 's' : ''}`, - hour: (n: number) => `${n} hour${n > 1 ? 's' : ''}`, - minute: (n: number) => `${n} minute${n > 1 ? 's' : ''}`, - second: (n: number) => `${n} second${n > 1 ? 's' : ''}`, + past: (n: string) => n.match(/\d/) ? `${n} ago` : n, + future: (n: string) => n.match(/\d/) ? `in ${n}` : n, + month: createTimeUnit('month', 'months'), + year: createTimeUnit('year', 'years'), + day: createTimeUnit('day', 'days', 'yesterday', 'tomorrow'), + week: createTimeUnit('week', 'weeks'), + hour: createSimpleTimeUnit('hour'), + minute: createSimpleTimeUnit('minute'), + second: createSimpleTimeUnit('second'), invalid: '', }, fr: { - justNow: 'à l\'instant', - past: (n: string) => (n.match(/\d/) ? `il y a ${n}` : n), - future: (n: string) => (n.match(/\d/) ? `dans ${n}` : n), - month: (n: number, past: boolean) => - n === 1 ? (past ? 'le mois dernier' : 'le mois prochain') : `${n} mois`, - year: (n: number, past: boolean) => - n === 1 ? (past ? 'l\'année dernière' : 'l\'année prochaine') : `${n} ans`, - day: (n: number, past: boolean) => - n === 1 ? (past ? 'hier' : 'demain') : `${n} jours`, - week: (n: number, past: boolean) => - n === 1 ? (past ? 'la semaine dernière' : 'la semaine prochaine') : `${n} semaines`, - hour: (n: number) => `${n} heure${n > 1 ? 's' : ''}`, - minute: (n: number) => `${n} minute${n > 1 ? 's' : ''}`, - second: (n: number) => `${n} seconde${n > 1 ? 's' : ''}`, + justNow: "à l'instant", + past: (n: string) => n.match(/\d/) ? `il y a ${n}` : n, + future: (n: string) => n.match(/\d/) ? `dans ${n}` : n, + month: (n: number, past = true) => n === 1 ? (past ? 'le mois dernier' : 'le mois prochain') : `${n} mois`, + year: (n: number, past = true) => n === 1 ? (past ? "l'année dernière" : "l'année prochaine") : `${n} ans`, + day: (n: number, past = true) => n === 1 ? (past ? 'hier' : 'demain') : `${n} jours`, + week: (n: number, past = true) => n === 1 ? (past ? 'la semaine dernière' : 'la semaine prochaine') : `${n} semaines`, + hour: createSimpleTimeUnit('heure'), + minute: createSimpleTimeUnit('minute'), + second: createSimpleTimeUnit('seconde'), invalid: '', }, es: { justNow: 'justo ahora', - past: (n: string) => (n.match(/\d/) ? `hace ${n}` : n), - future: (n: string) => (n.match(/\d/) ? `dentro de ${n}` : n), - month: (n: number, past: boolean) => - n === 1 ? (past ? 'el mes pasado' : 'el próximo mes') : `${n} meses`, - year: (n: number, past: boolean) => - n === 1 ? (past ? 'el año pasado' : 'el próximo año') : `${n} años`, - day: (n: number, past: boolean) => - n === 1 ? (past ? 'ayer' : 'mañana') : `${n} días`, - week: (n: number, past: boolean) => - n === 1 ? (past ? 'la semana pasada' : 'la próxima semana') : `${n} semanas`, - hour: (n: number) => `${n} hora${n > 1 ? 's' : ''}`, - minute: (n: number) => `${n} minuto${n > 1 ? 's' : ''}`, - second: (n: number) => `${n} segundo${n > 1 ? 's' : ''}`, + past: (n: string) => n.match(/\d/) ? `hace ${n}` : n, + future: (n: string) => n.match(/\d/) ? `dentro de ${n}` : n, + month: (n: number, past = true) => n === 1 ? (past ? 'el mes pasado' : 'el próximo mes') : `${n} meses`, + year: (n: number, past = true) => n === 1 ? (past ? 'el año pasado' : 'el próximo año') : `${n} años`, + day: (n: number, past = true) => n === 1 ? (past ? 'ayer' : 'mañana') : `${n} días`, + week: (n: number, past = true) => n === 1 ? (past ? 'la semana pasada' : 'la próxima semana') : `${n} semanas`, + hour: createSimpleTimeUnit('hora'), + minute: createSimpleTimeUnit('minuto'), + second: createSimpleTimeUnit('segundo'), invalid: '', }, } @@ -111,62 +127,26 @@ export interface Tag { translation: string } -export const TAGS: Array = [ - { - label: 'R', - translation: 'tags.r', - }, - { - label: 'AI', - translation: 'tags.ai', - }, - { - label: 'Data', - translation: 'tags.data', - }, - { - label: 'Web', - translation: 'tags.web', - }, - { - label: 'Python', - translation: 'tags.python', - }, - { - label: 'Maths', - translation: 'tags.maths', - }, -] +export const TAGS: readonly Tag[] = [ + { label: 'R', translation: 'tags.r' }, + { label: 'AI', translation: 'tags.ai' }, + { label: 'Data', translation: 'tags.data' }, + { label: 'Web', translation: 'tags.web' }, + { label: 'Python', translation: 'tags.python' }, + { label: 'Maths', translation: 'tags.maths' }, +] as const export const socials = [ - { - icon: 'i-ph:x-logo-duotone', - label: 'Twitter', - to: 'https://twitter.com/ArthurDanj', - }, - { - icon: 'i-ph:github-logo-duotone', - label: 'GitHub', - to: 'https://github.com/ArthurDanjou', - }, - { - icon: 'i-ph:linkedin-logo-duotone', - label: 'LinkedIn', - to: 'https://www.linkedin.com/in/arthurdanjou/', - }, - { - icon: 'i-ph:discord-logo-duotone', - label: 'Discord', - to: 'https://discordapp.com/users/179635349100691456', - }, -] + { icon: 'i-ph:x-logo-duotone', label: 'Twitter', to: 'https://twitter.com/ArthurDanj' }, + { icon: 'i-ph:github-logo-duotone', label: 'GitHub', to: 'https://github.com/ArthurDanjou' }, + { icon: 'i-ph:linkedin-logo-duotone', label: 'LinkedIn', to: 'https://www.linkedin.com/in/arthurdanjou/' }, + { icon: 'i-ph:discord-logo-duotone', label: 'Discord', to: 'https://discordapp.com/users/179635349100691456' }, +] as const + +type Locale = 'en' | 'fr' | 'es' interface Nav { - label: { - en: string - fr: string - es: string - } + label: Record to: string icon?: string target?: string @@ -181,113 +161,25 @@ export interface NavColor { interface NavColorGroup { name: string - colors: Array + colors: NavColor[] } -export const navs: Array