Skip to content

Commit dea741d

Browse files
committed
fix(frontend): replace SvelteKit server loads and fix svelte-check warnings
1 parent f289765 commit dea741d

18 files changed

Lines changed: 60 additions & 133 deletions

File tree

.pre-commit-config.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ repos:
4747
hooks:
4848
- id: gitleaks
4949

50+
# Svelte/TypeScript - check types and Svelte warnings
51+
- repo: local
52+
hooks:
53+
- id: svelte-check
54+
name: svelte-check
55+
entry: bash -c 'cd frontend/app && npm run check'
56+
language: system
57+
files: ^frontend/app/src/
58+
types_or: [svelte, ts, javascript]
59+
pass_filenames: false
60+
5061
# Lint Github Actions
5162
- repo: https://github.com/rhysd/actionlint
5263
rev: v1.7.9

frontend/app/src/lib/components/DataTable.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@
7070
onGlobalFilterChange: (updater: Updater<string>) => {
7171
globalFilter = typeof updater === 'function' ? updater(globalFilter) : updater;
7272
},
73-
globalFilterFn: globalFilterFn ?? (() => true)
73+
get globalFilterFn() {
74+
return globalFilterFn ?? (() => true);
75+
}
7476
});
7577
</script>
7678

frontend/app/src/lib/components/EmptyState.svelte

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
<script lang="ts">
22
import * as Empty from '$lib/components/ui/empty';
33
4-
let { icon, title, description } = $props();
4+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
5+
let { icon, title, description }: { icon: any; title: string; description: string } = $props();
56
</script>
67

78
<Empty.Root>
89
<Empty.Header>
910
<Empty.Media variant="icon">
10-
<icon />
11+
<icon></icon>
1112
</Empty.Media>
1213
<Empty.Title>{title}</Empty.Title>
1314
<Empty.Description>{description}</Empty.Description>

frontend/app/src/lib/components/FilterBar.svelte

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
import * as DropdownMenu from '$lib/components/ui/dropdown-menu';
66
import { FilterDialog } from '$lib/components/ui/filter-dialog';
77
import type { FilterState, FilterCategory } from '$lib/components/ui/filter-dialog';
8-
import type { ColumnDef, VisibilityState } from '@tanstack/table-core';
8+
import type { VisibilityState } from '@tanstack/table-core';
99
10-
type ColumnWithAccessor = ColumnDef<unknown, unknown> & { accessorKey?: string };
10+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
11+
type ColumnWithAccessor = { header?: any; id?: string; accessorKey?: string };
1112
1213
interface FilterBarProps {
1314
filterCategories?: FilterCategory[];

frontend/app/src/lib/components/Navbar.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<script context="module" lang="ts">
1+
<script module lang="ts">
22
// Module-level cache that persists across component instances
33
let cachedVersion: { pypsa: string | null; app: string | null } = { pypsa: null, app: null };
44
</script>
@@ -12,8 +12,8 @@
1212
import { LogOut, User } from 'lucide-svelte';
1313
1414
// Use cached version immediately to prevent flicker
15-
let pypsaVersion = cachedVersion.pypsa;
16-
let appVersion = cachedVersion.app;
15+
let pypsaVersion = $state(cachedVersion.pypsa);
16+
let appVersion = $state(cachedVersion.app);
1717
1818
// Format version for display (remove .post1. and git hash)
1919
function formatVersion(version: string | null): string | null {

frontend/app/src/lib/server/auth.ts

Lines changed: 0 additions & 49 deletions
This file was deleted.

frontend/app/src/routes/+layout.svelte

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script lang="ts">
22
import type { Snippet } from 'svelte';
33
import { onMount } from 'svelte';
4+
import { goto } from '$app/navigation';
45
import { page } from '$app/stores';
56
import '../app.css';
67
import favicon from '$lib/assets/favicon.svg';
@@ -20,6 +21,34 @@
2021
2122
let { children, toolbar }: { children?: Snippet; toolbar?: Snippet } = $props();
2223
24+
// Client-side auth guard
25+
$effect(() => {
26+
if (authStore.loading || authStore.authEnabled === null) return;
27+
if (authStore.authEnabled === false) return;
28+
29+
const path = $page.url.pathname;
30+
31+
if (path === '/login') {
32+
if (authStore.isAuthenticated && authStore.isApproved) {
33+
goto('/', { replaceState: true });
34+
}
35+
} else if (path === '/pending-approval') {
36+
if (!authStore.isAuthenticated) {
37+
goto('/login', { replaceState: true });
38+
} else if (authStore.isApproved) {
39+
goto('/', { replaceState: true });
40+
}
41+
} else {
42+
if (!authStore.isAuthenticated) {
43+
goto('/login', { replaceState: true });
44+
} else if (authStore.isPending) {
45+
goto('/pending-approval', { replaceState: true });
46+
} else if (path.startsWith('/admin') && !authStore.isAdmin) {
47+
goto('/', { replaceState: true });
48+
}
49+
}
50+
});
51+
2352
const pageInfo = $derived.by(() => {
2453
const path = $page.url.pathname;
2554
if (path === '/') return { name: 'Home', url: '/' };
@@ -62,7 +91,11 @@
6291
<ModeWatcher />
6392
<Toaster position="bottom-right" closeButton richColors duration={8000} />
6493

65-
{#if showSidebar}
94+
{#if authStore.loading}
95+
<div class="flex min-h-svh items-center justify-center">
96+
<div class="h-8 w-8 animate-spin rounded-full border-4 border-muted border-t-foreground"></div>
97+
</div>
98+
{:else if showSidebar}
6699
<Sidebar.Provider bind:open={sidebarStore.open}>
67100
<AppSidebar />
68101
<Sidebar.Inset>

frontend/app/src/routes/+page.server.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

frontend/app/src/routes/admin/backends/+page.server.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

frontend/app/src/routes/admin/networks/+page.server.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)