Skip to content

Commit

Permalink
Fix some linting issues and a todo comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Dlurak committed Jun 4, 2024
1 parent 14ab3d9 commit a34a0cd
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/lib/components/calendar/List/EditModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -67,8 +68,7 @@
.catch(sendDefaultErrorToast);
}}
>
<!-- TODO: i18n -->
Update
<Store store={i('calendar.update.update')} />
</PrimaryButton>
</div>
</Modal>
5 changes: 2 additions & 3 deletions src/lib/components/filter/SchoolAndClass.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@
}>();
</script>

<Collapseable id="note-filter">
<!-- TODO: I18n -->
<h3 class="pb-3 pt-2" slot="heading">Filters</h3>
<Collapseable id="school-class-filter">
<h3 class="pb-3 pt-2" slot="heading"><Store store={i('filter.filter')} /></h3>

<div class="flex flex-col gap-3" slot="content">
<School bind:school />
Expand Down
3 changes: 3 additions & 0 deletions src/lib/locales/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -432,6 +433,8 @@ const de = {

'settings.save': 'Speichern',

'filter.filter': 'Filter',

literal: '$literal'
} as const satisfies I18nDict;

Expand Down
3 changes: 3 additions & 0 deletions src/lib/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -420,6 +421,8 @@ const en = {

'settings.save': 'Save',

'filter.filter': 'Filters',

literal: '$literal'
} as const satisfies I18nDict;

Expand Down
2 changes: 1 addition & 1 deletion src/lib/types/math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export type SubtractOne<T extends number> = LastItem<Enumerate<T>, 0>;
*/
export type Multiply<T extends number, N extends number> = N extends 1
? T
: // @ts-ignore
: // @ts-expect-error Isn't a number for ts (but in reality it is)
Add<T, Multiply<T, SubtractOne<N>>>;

type PrivatePowerOf<
Expand Down
8 changes: 4 additions & 4 deletions src/lib/types/strToNum.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Add, Multiply, PowerOf, SubtractOne } from '$lib/types/math';
import type { Length } from './strings';

type DigitMap = {
Expand All @@ -21,19 +22,18 @@ type FirstDigitToNum<
> = S extends `${infer First}${infer _}`
? Length<S> extends 1
? DigitToNum<First>
: // @ts-ignore
Multiply<DigitToNum<First>, PowerOf<10, SubtractOne<Length<S>>>>
: Multiply<DigitToNum<First>, PowerOf<10, SubtractOne<Length<S>>>>
: Result;

type PrivateNumberToString<
S extends string,
Result extends number = 0
> = S extends `${infer _}${infer Right}`
? // @ts-ignore
? // @ts-expect-error Too deep
Add<FirstDigitToNum<S>, PrivateNumberToString<Right>>
: Result;

export type NumberToString<S extends string | number> = S extends number
? S
: //@ts-ignore
: //@ts-expect-error S isn't identified as a string
PrivateNumberToString<S>;
4 changes: 3 additions & 1 deletion src/lib/types/strings.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { Add } from '$lib/types/math';

type AddSpaces<T extends string> = ` ${T} `;
type Trimmed<T extends string> = T extends `${' ' | '\t' | '\n'}${infer R}`
? Trimmed<R>
Expand Down Expand Up @@ -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<Right, Add<Result, 1>>
: Result;
23 changes: 23 additions & 0 deletions src/lib/utils/url/query.test.ts
Original file line number Diff line number Diff line change
@@ -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<string, string | number>', () => {
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<string, Record<string, unknown>>', () => {
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`
);
});
});
2 changes: 0 additions & 2 deletions src/lib/utils/url/query.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// TODO: Write unit test

type Convertable = string | number | null | Record<string, unknown>;

export const objToQueryParams = (obj: Record<string, Convertable | Convertable[]>) => {
Expand Down

0 comments on commit a34a0cd

Please sign in to comment.