Skip to content

Commit 5fa76d2

Browse files
committed
Some cleanup n stuff
1 parent 1e873a3 commit 5fa76d2

16 files changed

Lines changed: 161 additions & 143 deletions

src/lib/api/internal/v2/apis/AccountApi.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import * as runtime from '../runtime';
1717
import type {
1818
ChangeUsernameRequest,
19-
LegacyEmptyResponse,
2019
LoginV2,
2120
LoginV2OkResponse,
2221
OpenShockProblem,
@@ -27,8 +26,6 @@ import type {
2726
import {
2827
ChangeUsernameRequestFromJSON,
2928
ChangeUsernameRequestToJSON,
30-
LegacyEmptyResponseFromJSON,
31-
LegacyEmptyResponseToJSON,
3229
LoginV2FromJSON,
3330
LoginV2ToJSON,
3431
LoginV2OkResponseFromJSON,
@@ -157,12 +154,12 @@ export interface AccountApiInterface {
157154
* @throws {RequiredError}
158155
* @memberof AccountApiInterface
159156
*/
160-
accountSignUpV2Raw(requestParameters: AccountSignUpV2Request, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<LegacyEmptyResponse>>;
157+
accountSignUpV2Raw(requestParameters: AccountSignUpV2Request, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<void>>;
161158

162159
/**
163160
* Signs up a new user
164161
*/
165-
accountSignUpV2(signUpV2?: SignUpV2, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<LegacyEmptyResponse>;
162+
accountSignUpV2(signUpV2?: SignUpV2, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<void>;
166163

167164
}
168165

@@ -333,7 +330,7 @@ export class AccountApi extends runtime.BaseAPI implements AccountApiInterface {
333330
/**
334331
* Signs up a new user
335332
*/
336-
async accountSignUpV2Raw(requestParameters: AccountSignUpV2Request, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<LegacyEmptyResponse>> {
333+
async accountSignUpV2Raw(requestParameters: AccountSignUpV2Request, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<void>> {
337334
const queryParameters: any = {};
338335

339336
const headerParameters: runtime.HTTPHeaders = {};
@@ -351,15 +348,14 @@ export class AccountApi extends runtime.BaseAPI implements AccountApiInterface {
351348
body: SignUpV2ToJSON(requestParameters['signUpV2']),
352349
}, initOverrides);
353350

354-
return new runtime.JSONApiResponse(response, (jsonValue) => LegacyEmptyResponseFromJSON(jsonValue));
351+
return new runtime.VoidApiResponse(response);
355352
}
356353

357354
/**
358355
* Signs up a new user
359356
*/
360-
async accountSignUpV2(signUpV2?: SignUpV2, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<LegacyEmptyResponse> {
361-
const response = await this.accountSignUpV2Raw({ signUpV2: signUpV2 }, initOverrides);
362-
return await response.value();
357+
async accountSignUpV2(signUpV2?: SignUpV2, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<void> {
358+
await this.accountSignUpV2Raw({ signUpV2: signUpV2 }, initOverrides);
363359
}
364360

365361
}
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
import type { ShockerLimits } from "$lib/api/internal/v2";
1+
import type { ShockerLimits } from '$lib/api/internal/v2';
22

33
export default function CompareShockerLimits(a: ShockerLimits, b: ShockerLimits) {
44
// Compare the limits of the two shocker objects
5-
return (
6-
a.intensity === b.intensity &&
7-
a.duration === b.duration
8-
);
5+
return a.intensity === b.intensity && a.duration === b.duration;
96
}
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
import type { ShockerPermissions } from "$lib/api/internal/v2";
1+
import type { ShockerPermissions } from '$lib/api/internal/v2';
22

33
export default function CompareShockerPermissions(a: ShockerPermissions, b: ShockerPermissions) {
44
// Compare the permissions and limits of the two shocker objects
5-
return (
6-
a.live === b.live &&
7-
a.shock === b.shock &&
8-
a.vibrate === b.vibrate &&
9-
a.sound === b.sound
10-
);
5+
return a.live === b.live && a.shock === b.shock && a.vibrate === b.vibrate && a.sound === b.sound;
116
}

src/lib/comparers/UserShareComparer.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import type { UserShareInfo } from "$lib/api/internal/v2";
2-
import CompareShockerPermissions from "$lib/comparers/ShockerPermissionsComparer";
3-
import CompareShockerLimits from "./ShockerLimitsComparer";
4-
1+
import type { UserShareInfo } from '$lib/api/internal/v2';
2+
import CompareShockerPermissions from '$lib/comparers/ShockerPermissionsComparer';
3+
import CompareShockerLimits from './ShockerLimitsComparer';
54

65
export function ComparePermissionsAndLimits(a: UserShareInfo, b: UserShareInfo) {
76
return (

src/lib/components/utils/MultiPauseToggle.svelte

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import type { BooleanLegacyDataResponse } from '$lib/api/internal/v1';
55
import { Button } from '$lib/components/ui/button';
66
import { toast } from 'svelte-sonner';
7+
78
interface Props {
89
shockers: PauseToggleProps[];
910
onPausedChange: (paused: boolean) => void;
@@ -19,22 +20,21 @@
1920
let requestInProgress = $state(false);
2021
2122
let pausedBooleans = $derived(() => {
22-
if (shockers.every(item => item.paused)) {
23-
return "allTrue";
23+
if (shockers.every((item) => item.paused)) {
24+
return 'allTrue';
2425
}
25-
if (shockers.every(item => !item.paused)) {
26-
return "allFalse";
26+
if (shockers.every((item) => !item.paused)) {
27+
return 'allFalse';
2728
}
28-
return "mixed";
29+
return 'mixed';
2930
});
3031
31-
3232
function handleClick(e: MouseEvent) {
3333
e.stopPropagation();
34-
if(requestInProgress) return;
34+
if (requestInProgress) return;
3535
requestInProgress = true;
3636
37-
const pause = pausedBooleans() !== "allTrue";
37+
const pause = pausedBooleans() !== 'allTrue';
3838
3939
let pauseRequests: Promise<void>[] = [];
4040
@@ -57,33 +57,43 @@
5757
let pauseRequest: Promise<BooleanLegacyDataResponse>;
5858
5959
if (shocker.userShareUserId) {
60-
pauseRequest = shockersV1Api.shockerShockerShareCodePause(shocker.shockerId, shocker.userShareUserId, {
61-
pause: pause
62-
});
60+
pauseRequest = shockersV1Api.shockerShockerShareCodePause(
61+
shocker.shockerId,
62+
shocker.userShareUserId,
63+
{
64+
pause: pause,
65+
}
66+
);
6367
} else {
6468
pauseRequest = shockersV1Api.shockerPauseShocker(shocker.shockerId, { pause: pause });
6569
}
6670
67-
pauseRequest.then((newPausedState) => {
68-
shocker.paused = newPausedState.data;
69-
}).catch((error) => {
70-
toast.error(`Failed to set shocker pause state`);
71-
console.error(error);
72-
});
71+
pauseRequest
72+
.then((newPausedState) => {
73+
shocker.paused = newPausedState.data;
74+
})
75+
.catch((error) => {
76+
toast.error(`Failed to set shocker pause state`);
77+
console.error(error);
78+
});
7379
7480
await pauseRequest;
7581
}
76-
7782
</script>
7883

79-
<Button disabled={requestInProgress} onclick={handleClick} class="size-9" variant={pausedBooleans() === 'allTrue' ? 'destructive' : 'default'}>
84+
<Button
85+
disabled={requestInProgress}
86+
onclick={handleClick}
87+
class="size-9"
88+
variant={pausedBooleans() === 'allTrue' ? 'destructive' : 'default'}
89+
>
8090
{#if requestInProgress}
8191
<LoaderCircle class="animate-spin" />
82-
{:else if pausedBooleans() === "allTrue"}
92+
{:else if pausedBooleans() === 'allTrue'}
8393
<Play />
84-
{:else if pausedBooleans() === "allFalse"}
94+
{:else if pausedBooleans() === 'allFalse'}
8595
<Pause />
86-
{:else if pausedBooleans() === "mixed"}
96+
{:else if pausedBooleans() === 'mixed'}
8797
<Asterisk />
8898
{/if}
8999
</Button>

src/lib/components/utils/PauseToggle.svelte

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,12 @@
4444
}
4545
</script>
4646

47-
<Button onclick={handleClick} disabled={requestInProgress} class="size-9" variant={paused ? 'destructive' : 'default'}>
47+
<Button
48+
onclick={handleClick}
49+
disabled={requestInProgress}
50+
class="size-9"
51+
variant={paused ? 'destructive' : 'default'}
52+
>
4853
{#if requestInProgress}
4954
<LoaderCircle class="animate-spin" />
5055
{:else if paused}

src/lib/errorhandling/ValidationProblemDetails.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { isObject } from '$lib/typeguards';
2+
import type { ValidationResult } from '$lib/types/ValidationResult';
23
import type { ProblemDetails } from './ProblemDetails';
34

45
export interface ValidationProblemDetails extends ProblemDetails {
@@ -14,3 +15,11 @@ export function isValidationError(
1415
isObject(problemdetails.errors)
1516
);
1617
}
18+
19+
export function mapToValRes(
20+
problem: ValidationProblemDetails,
21+
key: string
22+
): ValidationResult | null {
23+
const errors = problem.errors[key];
24+
return errors ? { valid: false, message: errors[0] } : null;
25+
}

src/routes/(anonymous)/login/+page.svelte

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
import PasswordInput from '$lib/components/input/PasswordInput.svelte';
88
import TextInput from '$lib/components/input/TextInput.svelte';
99
import { Button } from '$lib/components/ui/button';
10-
import {
11-
type ValidationProblemDetails,
12-
isValidationError,
13-
} from '$lib/errorhandling/ValidationProblemDetails';
10+
import { isValidationError, mapToValRes } from '$lib/errorhandling/ValidationProblemDetails';
1411
import { handleApiError } from '$lib/errorhandling/apiErrorHandling';
1512
import { UserStore } from '$lib/stores/UserStore';
1613
import type { ValidationResult } from '$lib/types/ValidationResult';
@@ -22,11 +19,6 @@
2219
let usernameError = $state<ValidationResult | null>(null);
2320
let passwordError = $state<ValidationResult | null>(null);
2421
25-
function mapToValRes(problem: ValidationProblemDetails, key: string): ValidationResult | null {
26-
const errors = problem.errors[key];
27-
return errors ? { valid: false, message: errors[0] } : null;
28-
}
29-
3022
async function handleSubmission(e: SubmitEvent) {
3123
e.preventDefault();
3224
@@ -35,7 +27,11 @@
3527
}
3628
3729
try {
38-
const account = await accountV2Api.accountLoginV2({ usernameOrEmail, password, turnstileResponse });
30+
const account = await accountV2Api.accountLoginV2({
31+
usernameOrEmail,
32+
password,
33+
turnstileResponse,
34+
});
3935
UserStore.setSelf({
4036
id: account.accountId,
4137
name: account.accountName,

src/routes/(anonymous)/signup/+page.svelte

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
import PasswordInput from '$lib/components/input/PasswordInput.svelte';
88
import UsernameInput from '$lib/components/input/UsernameInput.svelte';
99
import { Button } from '$lib/components/ui/button';
10-
import * as Card from '$lib/components/ui/card';
1110
import * as Dialog from '$lib/components/ui/dialog';
11+
import { isValidationError, mapToValRes } from '$lib/errorhandling/ValidationProblemDetails';
1212
import { handleApiError } from '$lib/errorhandling/apiErrorHandling';
1313
import { validatePasswordMatch } from '$lib/inputvalidation/passwordValidator';
1414
import { toast } from 'svelte-sonner';
@@ -42,25 +42,35 @@
4242
}
4343
}
4444
45-
function handleSubmission(ev: SubmitEvent) {
46-
ev.preventDefault();
45+
async function handleSubmission(e: SubmitEvent) {
46+
e.preventDefault();
4747
4848
if (!username || !email || !password || !passwordConfirm || !turnstileResponse) {
4949
return;
5050
}
5151
52-
accountV2Api
53-
.accountSignUpV2({
52+
try {
53+
await accountV2Api.accountSignUpV2({
5454
username,
5555
password,
5656
email,
5757
turnstileResponse,
58-
})
59-
.then(() => (accountCreated = true))
60-
.catch(handleApiError)
61-
.finally(() => {
62-
turnstileResponse = null;
6358
});
59+
accountCreated = true;
60+
} catch (error) {
61+
await handleApiError(error, (problem) => {
62+
if (!isValidationError(problem)) return false;
63+
64+
console.log(mapToValRes(problem, 'Username'));
65+
console.log(mapToValRes(problem, 'Password'));
66+
console.log(mapToValRes(problem, 'Email'));
67+
console.log(mapToValRes(problem, 'TurnstileResponse'));
68+
69+
return true;
70+
});
71+
} finally {
72+
turnstileResponse = null;
73+
}
6474
}
6575
</script>
6676

src/routes/(authenticated)/settings/api-tokens/dialog-token-create.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@
114114
<Dialog.Content>
115115
<Dialog.Header>
116116
<Dialog.Title>New API Token</Dialog.Title>
117-
<Dialog.Description>Please make sure to select the appropriate permissions for the token.</Dialog.Description>
117+
<Dialog.Description
118+
>Please make sure to select the appropriate permissions for the token.</Dialog.Description
119+
>
118120
</Dialog.Header>
119121
<form class="modal-form border-surface-500 rounded-container-token space-y-4">
120122
<TextInput

0 commit comments

Comments
 (0)