From a34a0cdd05ef31fc6089b071bb9866d3a0d178b1 Mon Sep 17 00:00:00 2001 From: Dlurak <84224239+Dlurak@users.noreply.github.com> Date: Tue, 4 Jun 2024 17:09:10 +0200 Subject: [PATCH] Fix some linting issues and a todo comment --- .../components/calendar/List/EditModal.svelte | 4 ++-- .../components/filter/SchoolAndClass.svelte | 5 ++-- src/lib/locales/de.ts | 3 +++ src/lib/locales/en.ts | 3 +++ src/lib/types/math.ts | 2 +- src/lib/types/strToNum.ts | 8 +++---- src/lib/types/strings.ts | 4 +++- src/lib/utils/url/query.test.ts | 23 +++++++++++++++++++ src/lib/utils/url/query.ts | 2 -- 9 files changed, 41 insertions(+), 13 deletions(-) create mode 100644 src/lib/utils/url/query.test.ts diff --git a/src/lib/components/calendar/List/EditModal.svelte b/src/lib/components/calendar/List/EditModal.svelte index 439ee84..2f374bc 100644 --- a/src/lib/components/calendar/List/EditModal.svelte +++ b/src/lib/components/calendar/List/EditModal.svelte @@ -3,6 +3,7 @@ import PrimaryButton from '$lib/components/buttons/PrimaryButton.svelte'; import { sendDefaultErrorToast, sendToast } from '$lib/components/layout/toasts'; import Modal from '$lib/components/modal/Modal.svelte'; + import Store from '$lib/components/utils/Store.svelte'; import type { Calendar } from '$lib/dlool/calendar/list'; import { updateCalendar } from '$lib/dlool/calendar/update'; import { i } from '$lib/i18n/store'; @@ -67,8 +68,7 @@ .catch(sendDefaultErrorToast); }} > - - Update + diff --git a/src/lib/components/filter/SchoolAndClass.svelte b/src/lib/components/filter/SchoolAndClass.svelte index e507f25..1288c03 100644 --- a/src/lib/components/filter/SchoolAndClass.svelte +++ b/src/lib/components/filter/SchoolAndClass.svelte @@ -21,9 +21,8 @@ }>(); - - -

Filters

+ +

diff --git a/src/lib/locales/de.ts b/src/lib/locales/de.ts index 99df4e4..5f920f1 100644 --- a/src/lib/locales/de.ts +++ b/src/lib/locales/de.ts @@ -394,6 +394,7 @@ const de = { 'calendar.delete.confirm.ok': 'Löschen', 'calendar.delete.success': 'Erfolgreich gelöscht', 'calendar.update.success': 'Erfolgreich aktualisiert', + 'calendar.update.update': 'Aktualisieren', 'settings.noneSelected': 'Wähle eine Kategorie aus', 'settings.profile': 'Profil', @@ -432,6 +433,8 @@ const de = { 'settings.save': 'Speichern', + 'filter.filter': 'Filter', + literal: '$literal' } as const satisfies I18nDict; diff --git a/src/lib/locales/en.ts b/src/lib/locales/en.ts index 0ac2181..cc2a9ad 100644 --- a/src/lib/locales/en.ts +++ b/src/lib/locales/en.ts @@ -384,6 +384,7 @@ const en = { 'calendar.delete.confirm.ok': 'Delete', 'calendar.delete.success': 'Successfully deleted', 'calendar.update.success': 'Successfully updated', + 'calendar.update.update': 'Update', 'settings.noneSelected': 'Select a category', 'settings.profile': 'Account', @@ -420,6 +421,8 @@ const en = { 'settings.save': 'Save', + 'filter.filter': 'Filters', + literal: '$literal' } as const satisfies I18nDict; diff --git a/src/lib/types/math.ts b/src/lib/types/math.ts index 9be0215..dab3981 100644 --- a/src/lib/types/math.ts +++ b/src/lib/types/math.ts @@ -41,7 +41,7 @@ export type SubtractOne = LastItem, 0>; */ export type Multiply = N extends 1 ? T - : // @ts-ignore + : // @ts-expect-error Isn't a number for ts (but in reality it is) Add>>; type PrivatePowerOf< diff --git a/src/lib/types/strToNum.ts b/src/lib/types/strToNum.ts index 622b4b0..1bdd3ed 100644 --- a/src/lib/types/strToNum.ts +++ b/src/lib/types/strToNum.ts @@ -1,3 +1,4 @@ +import type { Add, Multiply, PowerOf, SubtractOne } from '$lib/types/math'; import type { Length } from './strings'; type DigitMap = { @@ -21,19 +22,18 @@ type FirstDigitToNum< > = S extends `${infer First}${infer _}` ? Length extends 1 ? DigitToNum - : // @ts-ignore - Multiply, PowerOf<10, SubtractOne>>> + : Multiply, PowerOf<10, SubtractOne>>> : Result; type PrivateNumberToString< S extends string, Result extends number = 0 > = S extends `${infer _}${infer Right}` - ? // @ts-ignore + ? // @ts-expect-error Too deep Add, PrivateNumberToString> : Result; export type NumberToString = S extends number ? S - : //@ts-ignore + : //@ts-expect-error S isn't identified as a string PrivateNumberToString; diff --git a/src/lib/types/strings.ts b/src/lib/types/strings.ts index 0d4cb29..2bfa9b8 100644 --- a/src/lib/types/strings.ts +++ b/src/lib/types/strings.ts @@ -1,3 +1,5 @@ +import type { Add } from '$lib/types/math'; + type AddSpaces = ` ${T} `; type Trimmed = T extends `${' ' | '\t' | '\n'}${infer R}` ? Trimmed @@ -38,6 +40,6 @@ export type Length< S extends string, Result extends number = 0 > = S extends `${infer _}${infer Right}` - ? // @ts-ignore + ? // @ts-expect-error Add<> isn't a number Length> : Result; diff --git a/src/lib/utils/url/query.test.ts b/src/lib/utils/url/query.test.ts new file mode 100644 index 0000000..877db08 --- /dev/null +++ b/src/lib/utils/url/query.test.ts @@ -0,0 +1,23 @@ +import { objToQueryParams } from '$lib/utils/url/query'; +import { describe, it, expect } from 'vitest'; + +describe('object to query params', () => { + it('converts a Record', () => { + expect(objToQueryParams({})).toBe(''); + expect(objToQueryParams({ key: 'value' })).toBe('key=value'); + expect(objToQueryParams({ key: 'value', key2: 'value2' })).toBe('key=value&key2=value2'); + expect(objToQueryParams({ key: 'value', key2: 42 })).toBe('key=value&key2=42'); + }); + it('converts a handles null', () => { + expect(objToQueryParams({ key: null })).toBe(''); + expect(objToQueryParams({ key: 'value', key2: 'value2' })).toBe('key=value&key2=value2'); + expect(objToQueryParams({ key: 'value', key2: null })).toBe('key=value'); + }); + it('converrts a Record>', () => { + const obj = { key: { key: { key: { key: [4, 2.42, { key: { value: 'hi' } }] } } } }; + + expect(objToQueryParams({ key: obj, key2: 'value2' })).toBe( + `key=${encodeURIComponent(JSON.stringify(obj))}&key2=value2` + ); + }); +}); diff --git a/src/lib/utils/url/query.ts b/src/lib/utils/url/query.ts index 0454e65..fa1aaa9 100644 --- a/src/lib/utils/url/query.ts +++ b/src/lib/utils/url/query.ts @@ -1,5 +1,3 @@ -// TODO: Write unit test - type Convertable = string | number | null | Record; export const objToQueryParams = (obj: Record) => {