mirror of
https://github.com/lukasabbe/liu-stats-website.git
synced 2026-04-30 10:50:52 +00:00
init
This commit is contained in:
+23
@@ -0,0 +1,23 @@
|
||||
node_modules
|
||||
|
||||
# Output
|
||||
.output
|
||||
.vercel
|
||||
.netlify
|
||||
.wrangler
|
||||
/.svelte-kit
|
||||
/build
|
||||
|
||||
# OS
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
# Env
|
||||
.env
|
||||
.env.*
|
||||
!.env.example
|
||||
!.env.test
|
||||
|
||||
# Vite
|
||||
vite.config.js.timestamp-*
|
||||
vite.config.ts.timestamp-*
|
||||
@@ -0,0 +1,9 @@
|
||||
# Package Managers
|
||||
package-lock.json
|
||||
pnpm-lock.yaml
|
||||
yarn.lock
|
||||
bun.lock
|
||||
bun.lockb
|
||||
|
||||
# Miscellaneous
|
||||
/static/
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"useTabs": true,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "none",
|
||||
"printWidth": 100,
|
||||
"plugins": ["prettier-plugin-svelte", "prettier-plugin-tailwindcss"],
|
||||
"overrides": [
|
||||
{
|
||||
"files": "*.svelte",
|
||||
"options": {
|
||||
"parser": "svelte"
|
||||
}
|
||||
}
|
||||
],
|
||||
"tailwindStylesheet": "./src/routes/layout.css"
|
||||
}
|
||||
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"recommendations": [
|
||||
"svelte.svelte-vscode",
|
||||
"esbenp.prettier-vscode",
|
||||
"dbaeumer.vscode-eslint",
|
||||
"bradlc.vscode-tailwindcss"
|
||||
]
|
||||
}
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"*.css": "tailwindcss"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import prettier from 'eslint-config-prettier';
|
||||
import path from 'node:path';
|
||||
import { includeIgnoreFile } from '@eslint/compat';
|
||||
import js from '@eslint/js';
|
||||
import svelte from 'eslint-plugin-svelte';
|
||||
import { defineConfig } from 'eslint/config';
|
||||
import globals from 'globals';
|
||||
import ts from 'typescript-eslint';
|
||||
import svelteConfig from './svelte.config.js';
|
||||
|
||||
const gitignorePath = path.resolve(import.meta.dirname, '.gitignore');
|
||||
|
||||
export default defineConfig(
|
||||
includeIgnoreFile(gitignorePath),
|
||||
js.configs.recommended,
|
||||
ts.configs.recommended,
|
||||
svelte.configs.recommended,
|
||||
prettier,
|
||||
svelte.configs.prettier,
|
||||
{
|
||||
languageOptions: { globals: { ...globals.browser, ...globals.node } },
|
||||
rules: {
|
||||
// typescript-eslint strongly recommend that you do not use the no-undef lint rule on TypeScript projects.
|
||||
// see: https://typescript-eslint.io/troubleshooting/faqs/eslint/#i-get-errors-from-the-no-undef-rule-about-global-variables-not-being-defined-even-though-there-are-no-typescript-errors
|
||||
'no-undef': 'off'
|
||||
}
|
||||
},
|
||||
{
|
||||
files: ['**/*.svelte', '**/*.svelte.ts', '**/*.svelte.js'],
|
||||
languageOptions: {
|
||||
parserOptions: {
|
||||
projectService: true,
|
||||
extraFileExtensions: ['.svelte'],
|
||||
parser: ts.parser,
|
||||
svelteConfig
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
// Override or add rule settings here, such as:
|
||||
// 'svelte/button-has-type': 'error'
|
||||
rules: {}
|
||||
}
|
||||
);
|
||||
@@ -0,0 +1,47 @@
|
||||
{
|
||||
"name": "liu-stats",
|
||||
"private": true,
|
||||
"version": "0.0.1",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite dev",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview",
|
||||
"prepare": "svelte-kit sync || echo ''",
|
||||
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
||||
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
||||
"lint": "prettier --check . && eslint .",
|
||||
"format": "prettier --write ."
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/compat": "^2.0.4",
|
||||
"@eslint/js": "^10.0.1",
|
||||
"@sveltejs/adapter-auto": "^7.0.1",
|
||||
"@sveltejs/kit": "^2.57.0",
|
||||
"@sveltejs/vite-plugin-svelte": "^7.0.0",
|
||||
"@tailwindcss/vite": "^4.2.2",
|
||||
"@types/node": "^24",
|
||||
"eslint": "^10.2.0",
|
||||
"eslint-config-prettier": "^10.1.8",
|
||||
"eslint-plugin-svelte": "^3.17.0",
|
||||
"globals": "^17.4.0",
|
||||
"prettier": "^3.8.1",
|
||||
"prettier-plugin-svelte": "^3.5.1",
|
||||
"prettier-plugin-tailwindcss": "^0.7.2",
|
||||
"svelte": "^5.55.2",
|
||||
"svelte-check": "^4.4.6",
|
||||
"tailwindcss": "^4.2.2",
|
||||
"typescript": "^6.0.2",
|
||||
"typescript-eslint": "^8.58.1",
|
||||
"vite": "^8.0.7"
|
||||
},
|
||||
"dependencies": {
|
||||
"@fontsource-variable/geist-mono": "^5.2.7",
|
||||
"@fontsource-variable/inter": "^5.2.8",
|
||||
"bits-ui": "^2.17.3",
|
||||
"layerchart": "^2.0.0-next.43",
|
||||
"liu-tentor-package": "^1.2.0",
|
||||
"lucide-svelte": "^1.0.1",
|
||||
"mode-watcher": "^1.1.0"
|
||||
}
|
||||
}
|
||||
Generated
+2709
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,3 @@
|
||||
onlyBuiltDependencies:
|
||||
- esbuild
|
||||
- '@tailwindcss/oxide'
|
||||
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
// See https://svelte.dev/docs/kit/types#app.d.ts
|
||||
// for information about these interfaces
|
||||
declare global {
|
||||
namespace App {
|
||||
// interface Error {}
|
||||
// interface Locals {}
|
||||
// interface PageData {}
|
||||
// interface PageState {}
|
||||
// interface Platform {}
|
||||
}
|
||||
}
|
||||
|
||||
export {};
|
||||
@@ -0,0 +1,28 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="text-scale" content="scale" />
|
||||
<meta name="description" content="View statistics and grade distribution for LIU courses" />
|
||||
<meta property="og:title" content="LiuStats - Course Statistics" />
|
||||
<meta
|
||||
property="og:description"
|
||||
content="View statistics and grade distribution for LIU courses"
|
||||
/>
|
||||
<meta property="og:type" content="website" />
|
||||
<meta property="og:url" content="https://liustats.se" />
|
||||
<meta property="og:image" content="https://liustats.se/og-image.png" />
|
||||
<meta name="twitter:card" content="summary_large_image" />
|
||||
<meta name="twitter:title" content="LiuStats - Course Statistics" />
|
||||
<meta
|
||||
name="twitter:description"
|
||||
content="View statistics and grade distribution for LIU courses"
|
||||
/>
|
||||
<meta name="twitter:image" content="https://liustats.se/og-image.png" />
|
||||
%sveltekit.head%
|
||||
</head>
|
||||
<body data-sveltekit-preload-data="hover">
|
||||
<div style="display: contents">%sveltekit.body%</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,126 @@
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation';
|
||||
import { Combobox } from 'bits-ui';
|
||||
import { ChevronsDownUp, Check, LoaderCircle, Search } from 'lucide-svelte';
|
||||
import { locale, getTranslation } from '$lib/i18n';
|
||||
import type { Locale } from '$lib/i18n/translations';
|
||||
|
||||
let courses: string[] = $state([]);
|
||||
let loading = $state(true);
|
||||
let error = $state(false);
|
||||
let currentLocale = $state<Locale>('en');
|
||||
|
||||
locale.subscribe((l) => (currentLocale = l));
|
||||
|
||||
let inputValue = $state('');
|
||||
let selectedCourse = $state('');
|
||||
|
||||
let filteredCourses = $derived(
|
||||
inputValue ? courses.filter((c) => c.includes(inputValue)).slice(0, 25) : courses.slice(0, 25)
|
||||
);
|
||||
|
||||
$effect(() => {
|
||||
fetchCourses();
|
||||
});
|
||||
|
||||
async function fetchCourses() {
|
||||
try {
|
||||
const res = await fetch('https://liutentor.lukasabbe.com/api/courses/');
|
||||
if (!res.ok) {
|
||||
error = true;
|
||||
return;
|
||||
}
|
||||
const data = await res.json();
|
||||
courses = data;
|
||||
} catch (e) {
|
||||
error = true;
|
||||
} finally {
|
||||
loading = false;
|
||||
}
|
||||
}
|
||||
|
||||
function handleCourseSelect(course: string | undefined) {
|
||||
if (!course) return;
|
||||
inputValue = '';
|
||||
goto(`/${course}`);
|
||||
}
|
||||
</script>
|
||||
|
||||
<Combobox.Root
|
||||
type="single"
|
||||
name="courseSelect"
|
||||
bind:value={selectedCourse}
|
||||
onValueChange={handleCourseSelect}
|
||||
>
|
||||
<div class="group relative w-max">
|
||||
<div
|
||||
class="text-muted-foreground/60 pointer-events-none absolute inset-s-3 top-1/2 -translate-y-1/2"
|
||||
>
|
||||
<Search class="size-4" />
|
||||
</div>
|
||||
|
||||
<Combobox.Input
|
||||
oninput={(e) => {
|
||||
e.currentTarget.value = e.currentTarget.value.toUpperCase();
|
||||
inputValue = e.currentTarget.value;
|
||||
}}
|
||||
onkeydown={(e) => {
|
||||
if (e.key === 'Enter') {
|
||||
setTimeout(() => {
|
||||
if (inputValue && filteredCourses.length > 0) {
|
||||
const exactMatch = courses.find((c) => c === inputValue);
|
||||
const targetCourse = exactMatch || filteredCourses[0];
|
||||
handleCourseSelect(targetCourse);
|
||||
}
|
||||
}, 0);
|
||||
}
|
||||
}}
|
||||
class="border-input bg-background ring-offset-background placeholder:text-muted-foreground/50 flex h-10 w-74 rounded-lg border pr-10 pl-10 text-sm transition-all focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50"
|
||||
placeholder={getTranslation('searchCourse', currentLocale)}
|
||||
aria-label={getTranslation('searchCourse', currentLocale)}
|
||||
/>
|
||||
|
||||
<Combobox.Trigger
|
||||
class="absolute inset-e-1 top-1/2 size-8 -translate-y-1/2 transition-all active:scale-95"
|
||||
>
|
||||
<ChevronsDownUp class="mx-auto size-4 opacity-50" />
|
||||
</Combobox.Trigger>
|
||||
</div>
|
||||
|
||||
<Combobox.Content
|
||||
class="bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 z-50 min-w-74 overflow-hidden rounded-xl border p-1 shadow-lg"
|
||||
sideOffset={6}
|
||||
>
|
||||
<Combobox.Viewport class="max-h-70 p-1">
|
||||
{#if loading}
|
||||
<div class="text-muted-foreground flex items-center justify-center py-8 text-sm">
|
||||
<LoaderCircle class="mr-2 size-4 animate-spin" />
|
||||
Loading courses...
|
||||
</div>
|
||||
{:else if error}
|
||||
<div class="text-destructive py-6 text-center text-sm font-medium">
|
||||
Failed to load courses.
|
||||
</div>
|
||||
{:else if filteredCourses.length === 0}
|
||||
<div class="text-muted-foreground py-6 text-center text-sm">No results found.</div>
|
||||
{:else}
|
||||
{#each filteredCourses as course (course)}
|
||||
<Combobox.Item
|
||||
value={course}
|
||||
label={course}
|
||||
class="data-highlighted:text-foreground relative flex w-full cursor-pointer items-center rounded-md py-2 pr-2 pl-8 text-sm outline-hidden transition-colors select-none data-disabled:pointer-events-none data-disabled:opacity-50 data-highlighted:bg-gray-100 dark:data-highlighted:bg-gray-800"
|
||||
>
|
||||
{#snippet children({ selected })}
|
||||
<span class="absolute left-2 flex h-4 w-4 items-center justify-center">
|
||||
{#if selected}
|
||||
<Check class="text-primary size-4" />
|
||||
{/if}
|
||||
</span>
|
||||
<span class="truncate font-medium">{course}</span>
|
||||
{/snippet}
|
||||
</Combobox.Item>
|
||||
{/each}
|
||||
{/if}
|
||||
</Combobox.Viewport>
|
||||
</Combobox.Content>
|
||||
</Combobox.Root>
|
||||
@@ -0,0 +1,59 @@
|
||||
<script lang="ts">
|
||||
import { PieChart } from 'layerchart';
|
||||
import ModuleModal from './ModuleModal.svelte';
|
||||
import type { Module } from 'liu-tentor-package';
|
||||
import { locale } from '$lib/i18n';
|
||||
import type { Locale } from '$lib/i18n/translations';
|
||||
|
||||
let { moduleData }: { moduleData: Module } = $props();
|
||||
let open = $state(false);
|
||||
let currentLocale = $state<Locale>('en');
|
||||
|
||||
locale.subscribe((l) => (currentLocale = l));
|
||||
|
||||
const colors = $derived.by(() => {
|
||||
const passingGrades = moduleData.grades.filter((g) => g.grade !== 'U');
|
||||
const minOrder = Math.min(...passingGrades.map((g) => g.gradeOrder));
|
||||
const maxOrder = Math.max(...passingGrades.map((g) => g.gradeOrder));
|
||||
const range = maxOrder - minOrder || 1;
|
||||
|
||||
return moduleData.grades.map((g) => {
|
||||
if (g.grade === 'U') {
|
||||
return '#ef4444';
|
||||
}
|
||||
const normalized = (g.gradeOrder - minOrder) / range;
|
||||
const hue = 120 - normalized * 60;
|
||||
const saturation = 80 - normalized * 20;
|
||||
return `hsl(${hue}, ${saturation}%, 45%)`;
|
||||
});
|
||||
});
|
||||
|
||||
function formatDate(date: string): string {
|
||||
return new Date(date).toLocaleDateString(currentLocale === 'sv' ? 'sv-SE' : 'en-US');
|
||||
}
|
||||
</script>
|
||||
|
||||
<ModuleModal {moduleData} bind:open />
|
||||
|
||||
<div class="flex min-w-0 flex-col rounded-lg border border-gray-300 p-4">
|
||||
<button
|
||||
onclick={() => (open = true)}
|
||||
class="w-full cursor-pointer border-0 bg-transparent p-0 text-left"
|
||||
>
|
||||
<h1 class="mb-1 text-xl font-semibold">{moduleData.moduleCode}</h1>
|
||||
</button>
|
||||
<p class="mb-4 text-sm text-gray-500">{formatDate(moduleData.date)}</p>
|
||||
<div class="min-h-[300px]">
|
||||
<PieChart
|
||||
data={moduleData.grades}
|
||||
key="grade"
|
||||
value="quantity"
|
||||
cRange={colors}
|
||||
height={300}
|
||||
innerRadius={50}
|
||||
cornerRadius={2}
|
||||
padAngle={0.05}
|
||||
legend={true}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,11 @@
|
||||
<script>
|
||||
let { path = '#', icon: Icon, ariaLabel = 'Link' } = $props();
|
||||
</script>
|
||||
|
||||
<a
|
||||
href={path}
|
||||
aria-label={ariaLabel}
|
||||
class="relative inline-flex h-10 w-10 items-center justify-center rounded transition-all active:scale-95"
|
||||
>
|
||||
<Icon size={24} class="text-black dark:text-white" />
|
||||
</a>
|
||||
@@ -0,0 +1,18 @@
|
||||
<script lang="ts">
|
||||
import { locale } from '$lib/i18n';
|
||||
import type { Locale } from '$lib/i18n/translations';
|
||||
|
||||
let currentLocale = $state<Locale>('en');
|
||||
|
||||
locale.subscribe((l) => {
|
||||
currentLocale = l;
|
||||
});
|
||||
|
||||
function toggle() {
|
||||
locale.toggle();
|
||||
}
|
||||
</script>
|
||||
|
||||
<button onclick={toggle} class="rounded px-3 py-1.5 text-sm transition-all active:scale-95">
|
||||
{currentLocale === 'en' ? 'EN' : 'SV'}
|
||||
</button>
|
||||
@@ -0,0 +1,93 @@
|
||||
<script lang="ts">
|
||||
import { BarChart } from 'layerchart';
|
||||
import { Dialog } from 'bits-ui';
|
||||
import { X } from 'lucide-svelte';
|
||||
import type { Module } from 'liu-tentor-package';
|
||||
import { locale, getTranslation } from '$lib/i18n';
|
||||
import type { Locale } from '$lib/i18n/translations';
|
||||
|
||||
let { moduleData, open = $bindable(false) }: { moduleData: Module; open: boolean } = $props();
|
||||
let currentLocale = $state<Locale>('en');
|
||||
|
||||
locale.subscribe((l) => (currentLocale = l));
|
||||
|
||||
const colors = $derived.by(() => {
|
||||
const passingGrades = moduleData.grades.filter((g) => g.grade !== 'U');
|
||||
const minOrder = Math.min(...passingGrades.map((g) => g.gradeOrder));
|
||||
const maxOrder = Math.max(...passingGrades.map((g) => g.gradeOrder));
|
||||
const range = maxOrder - minOrder || 1;
|
||||
|
||||
return moduleData.grades.map((g) => {
|
||||
if (g.grade === 'U') {
|
||||
return '#ef4444';
|
||||
}
|
||||
const normalized = (g.gradeOrder - minOrder) / range;
|
||||
const hue = 120 - normalized * 60;
|
||||
const saturation = 80 - normalized * 20;
|
||||
return `hsl(${hue}, ${saturation}%, 45%)`;
|
||||
});
|
||||
});
|
||||
|
||||
const totalStudents = $derived(moduleData.grades.reduce((sum, g) => sum + g.quantity, 0));
|
||||
const passedStudents = $derived(
|
||||
moduleData.grades.filter((g) => g.grade !== 'U').reduce((sum, g) => sum + g.quantity, 0)
|
||||
);
|
||||
const passRate = $derived(
|
||||
totalStudents > 0 ? ((passedStudents / totalStudents) * 100).toFixed(1) : 0
|
||||
);
|
||||
|
||||
function formatDate(date: string): string {
|
||||
return new Date(date).toLocaleDateString(currentLocale === 'sv' ? 'sv-SE' : 'en-US');
|
||||
}
|
||||
</script>
|
||||
|
||||
<Dialog.Root bind:open>
|
||||
<Dialog.Portal>
|
||||
<Dialog.Overlay class="fixed inset-0 z-50 bg-black/50" />
|
||||
<Dialog.Content
|
||||
class="fixed top-1/2 left-1/2 z-50 max-h-[90vh] w-full max-w-2xl -translate-x-1/2 -translate-y-1/2 overflow-y-auto rounded-lg border border-gray-300 bg-gray-50 p-6 shadow-xl dark:border-gray-700 dark:bg-[#1a1a1a]"
|
||||
>
|
||||
<div class="mb-4 flex items-start justify-between">
|
||||
<div>
|
||||
<Dialog.Title class="text-2xl font-bold">{moduleData.moduleCode}</Dialog.Title>
|
||||
<p class="text-sm text-gray-500 dark:text-gray-400">
|
||||
{formatDate(moduleData.date)}
|
||||
</p>
|
||||
</div>
|
||||
<Dialog.Close
|
||||
class="rounded p-2 transition-colors hover:bg-gray-100 dark:hover:bg-gray-800"
|
||||
>
|
||||
<X class="h-5 w-5" />
|
||||
</Dialog.Close>
|
||||
</div>
|
||||
|
||||
<div class="mb-6 grid grid-cols-2 gap-4">
|
||||
<div class="rounded-lg border bg-gray-50 p-4 text-center dark:bg-[#1a1a1a]">
|
||||
<p class="text-3xl font-bold">{totalStudents}</p>
|
||||
<p class="text-sm text-gray-500 dark:text-gray-400">
|
||||
{getTranslation('totalStudents', currentLocale)}
|
||||
</p>
|
||||
</div>
|
||||
<div class="rounded-lg border bg-gray-50 p-4 text-center dark:bg-[#1a1a1a]">
|
||||
<p class="text-3xl font-bold">{passRate}%</p>
|
||||
<p class="text-sm text-gray-500 dark:text-gray-400">
|
||||
{getTranslation('passRate', currentLocale)}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h3 class="mb-2 text-lg font-semibold">
|
||||
{getTranslation('gradeDistribution', currentLocale)}
|
||||
</h3>
|
||||
<BarChart
|
||||
data={moduleData.grades}
|
||||
x="grade"
|
||||
y="quantity"
|
||||
cRange={colors}
|
||||
orientation="vertical"
|
||||
height={200}
|
||||
padding={{ top: 20, right: 20, bottom: 40, left: 40 }}
|
||||
/>
|
||||
</Dialog.Content>
|
||||
</Dialog.Portal>
|
||||
</Dialog.Root>
|
||||
@@ -0,0 +1,24 @@
|
||||
<script lang="ts">
|
||||
import { Toggle } from 'bits-ui';
|
||||
import { setMode, mode } from 'mode-watcher';
|
||||
import { Sun, Moon } from 'lucide-svelte';
|
||||
function handlePressedChange(pressed: boolean) {
|
||||
setMode(pressed ? 'dark' : 'light');
|
||||
}
|
||||
</script>
|
||||
|
||||
<Toggle.Root
|
||||
pressed={mode.current === 'dark'}
|
||||
onPressedChange={handlePressedChange}
|
||||
class="relative inline-flex h-10 w-10 items-center justify-center rounded transition-all active:scale-95"
|
||||
>
|
||||
<Sun
|
||||
class="h-5 w-5 scale-100 rotate-0 text-black transition-all dark:scale-0 dark:-rotate-90 dark:text-white"
|
||||
/>
|
||||
|
||||
<Moon
|
||||
class="absolute h-5 w-5 scale-0 rotate-90 text-black transition-all dark:scale-100 dark:rotate-0 dark:text-white"
|
||||
/>
|
||||
|
||||
<span class="sr-only">Toggle theme</span>
|
||||
</Toggle.Root>
|
||||
@@ -0,0 +1,30 @@
|
||||
import { writable } from 'svelte/store';
|
||||
import { translations, type Locale } from './translations';
|
||||
import type { TranslationKey } from './translations';
|
||||
|
||||
function createLocaleStore() {
|
||||
const { subscribe, set, update } = writable<Locale>('en');
|
||||
|
||||
return {
|
||||
subscribe,
|
||||
set,
|
||||
setSwedish: () => set('sv'),
|
||||
setEnglish: () => set('en'),
|
||||
toggle: () =>
|
||||
update((current) => {
|
||||
return current === 'en' ? 'sv' : 'en';
|
||||
})
|
||||
};
|
||||
}
|
||||
|
||||
export const locale = createLocaleStore();
|
||||
|
||||
export function t(key: TranslationKey): string {
|
||||
let currentLocale: Locale = 'en';
|
||||
locale.subscribe((l) => (currentLocale = l))();
|
||||
return translations[currentLocale][key];
|
||||
}
|
||||
|
||||
export function getTranslation(key: TranslationKey, currentLocale: Locale): string {
|
||||
return translations[currentLocale][key];
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
export const translations = {
|
||||
en: {
|
||||
welcome: 'Welcome to LIU Exam Stats',
|
||||
searchPrompt: 'Search for a course to view exam statistics.',
|
||||
searchCourse: 'Search a course...',
|
||||
course: 'Course',
|
||||
courseWebsite: 'Course Website',
|
||||
back: 'Back',
|
||||
next: 'Next',
|
||||
allModules: 'All modules',
|
||||
totalStudents: 'Total Students',
|
||||
passRate: 'Pass Rate',
|
||||
gradeDistribution: 'Grade Distribution',
|
||||
github: 'GitHub',
|
||||
myWebsite: 'My Website',
|
||||
loading: 'Loading...',
|
||||
notFound: 'Course not found',
|
||||
modules: 'modules'
|
||||
},
|
||||
sv: {
|
||||
welcome: 'Välkommen till LIU tentastatistik',
|
||||
searchPrompt: 'Sök efter en kurs för att se tentastatistik.',
|
||||
searchCourse: 'Sök kurs...',
|
||||
course: 'Kurs',
|
||||
courseWebsite: 'Kurswebbplats',
|
||||
back: 'Tillbaka',
|
||||
next: 'Nästa',
|
||||
allModules: 'Alla moment',
|
||||
totalStudents: 'Totalt antal studenter',
|
||||
passRate: 'Andel godkända',
|
||||
gradeDistribution: 'Betygsfördelning',
|
||||
github: 'GitHub',
|
||||
myWebsite: 'Min webbplats',
|
||||
loading: 'Laddar...',
|
||||
notFound: 'Kursen hittades inte',
|
||||
modules: 'moduler'
|
||||
}
|
||||
} as const;
|
||||
|
||||
export type Locale = keyof typeof translations;
|
||||
export type TranslationKey = keyof typeof translations.en;
|
||||
@@ -0,0 +1,40 @@
|
||||
<script lang="ts">
|
||||
import './layout.css';
|
||||
import { ModeWatcher } from 'mode-watcher';
|
||||
import ThemeSwitcher from '$lib/components/ThemeSwitcher.svelte';
|
||||
import LanguageSwitcher from '$lib/components/LanguageSwitcher.svelte';
|
||||
import HeaderButton from '$lib/components/HeaderButton.svelte';
|
||||
import { locale, getTranslation } from '$lib/i18n';
|
||||
import { House } from 'lucide-svelte';
|
||||
import type { Locale } from '$lib/i18n/translations';
|
||||
|
||||
let { children } = $props();
|
||||
|
||||
let currentLocale = $state<Locale>('en');
|
||||
locale.subscribe((l) => (currentLocale = l));
|
||||
</script>
|
||||
|
||||
<svelte:head><link rel="icon" /></svelte:head>
|
||||
<ModeWatcher />
|
||||
|
||||
<div class="flex min-h-screen flex-col">
|
||||
<header class="flex w-full shrink-0 items-center justify-between p-4">
|
||||
<HeaderButton path="/" icon={House} ariaLabel="Home" />
|
||||
<div class="flex items-center gap-2">
|
||||
<LanguageSwitcher />
|
||||
<ThemeSwitcher />
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="flex-1">{@render children()}</div>
|
||||
|
||||
<footer class="flex w-full shrink-0 items-center justify-center gap-4 border-t p-4">
|
||||
<a href="https://github.com/LiuStats" target="_blank" rel="noopener" class="hover:underline">
|
||||
{getTranslation('github', currentLocale)}
|
||||
</a>
|
||||
<span>|</span>
|
||||
<a href="https://lukasabbe.com/" target="_blank" rel="noopener" class="hover:underline">
|
||||
{getTranslation('myWebsite', currentLocale)}
|
||||
</a>
|
||||
</footer>
|
||||
</div>
|
||||
@@ -0,0 +1,17 @@
|
||||
<script lang="ts">
|
||||
import CoursePicker from '$lib/components/CoursePicker.svelte';
|
||||
import { locale, getTranslation } from '$lib/i18n';
|
||||
import type { Locale } from '$lib/i18n/translations';
|
||||
|
||||
let currentLocale = $state<Locale>('en');
|
||||
locale.subscribe((l) => (currentLocale = l));
|
||||
</script>
|
||||
|
||||
<div class="m-10 flex flex-col items-center justify-center text-center font-mono">
|
||||
<h1 class="text-3xl font-bold">{getTranslation('welcome', currentLocale)}</h1>
|
||||
<p class="text-lg">{getTranslation('searchPrompt', currentLocale)}</p>
|
||||
</div>
|
||||
|
||||
<div class="flex justify-center">
|
||||
<CoursePicker />
|
||||
</div>
|
||||
@@ -0,0 +1,117 @@
|
||||
<script lang="ts">
|
||||
import { page } from '$app/state';
|
||||
import { Button } from 'bits-ui';
|
||||
import CoursePie from '$lib/components/CoursePie.svelte';
|
||||
import { getCourseStatistic, type DataCourseStatistic } from 'liu-tentor-package';
|
||||
import { locale, getTranslation } from '$lib/i18n';
|
||||
import type { Locale } from '$lib/i18n/translations';
|
||||
import type { LanguageContent } from 'liu-tentor-package';
|
||||
|
||||
let course = page.params.course;
|
||||
|
||||
let loading = $state(true);
|
||||
let error: null | Error = $state(null);
|
||||
let courseStats: DataCourseStatistic = $state({} as DataCourseStatistic);
|
||||
let currentPage = $state(0);
|
||||
let selectedModuleCode = $state<string | undefined>(undefined);
|
||||
let currentLocale = $state<Locale>('en');
|
||||
const perPage = 6;
|
||||
|
||||
locale.subscribe((l) => (currentLocale = l));
|
||||
|
||||
$effect(() => {
|
||||
getCourseStats();
|
||||
});
|
||||
|
||||
async function getCourseStats() {
|
||||
if (!course) {
|
||||
error = new Error('Course not found');
|
||||
loading = false;
|
||||
return;
|
||||
}
|
||||
courseStats = (await getCourseStatistic(course)) ?? ({} as DataCourseStatistic);
|
||||
loading = false;
|
||||
}
|
||||
|
||||
function next() {
|
||||
currentPage++;
|
||||
}
|
||||
|
||||
function back() {
|
||||
if (currentPage > 0) {
|
||||
currentPage--;
|
||||
}
|
||||
}
|
||||
|
||||
let filteredModules = $derived(
|
||||
selectedModuleCode
|
||||
? (courseStats.modules?.filter((m) => m.moduleCode === selectedModuleCode) ?? [])
|
||||
: (courseStats.modules ?? [])
|
||||
);
|
||||
|
||||
let uniqueModuleCodes = $derived([
|
||||
...new Set(courseStats.modules?.map((m) => m.moduleCode) ?? [])
|
||||
]);
|
||||
|
||||
function getLocalizedTitle(title: LanguageContent | undefined): string {
|
||||
if (!title) return '';
|
||||
return currentLocale === 'sv' ? title.sv : title.en;
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col items-center justify-center text-center font-mono">
|
||||
<h1 class="text-3xl font-bold">
|
||||
{getTranslation('course', currentLocale)}
|
||||
{course?.toUpperCase()} - {courseStats.modules?.length ?? 0}
|
||||
{getTranslation('modules', currentLocale)}
|
||||
</h1>
|
||||
<p>{getLocalizedTitle(courseStats.courseTitle)}</p>
|
||||
</div>
|
||||
|
||||
{#if loading}
|
||||
<p>{getTranslation('loading', currentLocale)}</p>
|
||||
{:else if error}
|
||||
<p>{error.message}</p>
|
||||
{:else if courseStats?.modules}
|
||||
<div class="mx-auto mt-8 flex max-w-5xl items-center justify-between px-4">
|
||||
<select bind:value={selectedModuleCode} class="h-10 min-w-[200px] rounded border px-3 py-2">
|
||||
<option value={undefined}>{getTranslation('allModules', currentLocale)}</option>
|
||||
{#each uniqueModuleCodes as code}
|
||||
<option value={code}>{code}</option>
|
||||
{/each}
|
||||
</select>
|
||||
<a
|
||||
href="https://studieinfo.liu.se/kurs/{course}"
|
||||
class="rounded border px-4 py-2 transition-all active:scale-95"
|
||||
target="_blank"
|
||||
>
|
||||
{getTranslation('courseWebsite', currentLocale)}
|
||||
</a>
|
||||
</div>
|
||||
|
||||
{@const start = currentPage * perPage}
|
||||
{@const visibleModules = filteredModules.slice(start, start + perPage)}
|
||||
<div class="mx-auto grid max-w-5xl grid-cols-1 gap-4 p-4 md:grid-cols-2">
|
||||
{#each visibleModules as module}
|
||||
<CoursePie moduleData={module} />
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
<div class="mt-4 flex justify-center gap-4 pb-8">
|
||||
<Button.Root
|
||||
onclick={back}
|
||||
disabled={currentPage === 0}
|
||||
class="rounded border px-4 py-2 transition-all active:scale-95 disabled:opacity-50 disabled:active:scale-100"
|
||||
>
|
||||
{getTranslation('back', currentLocale)}
|
||||
</Button.Root>
|
||||
<span class="px-4 py-2">{currentPage + 1} / {Math.ceil(filteredModules.length / perPage)}</span>
|
||||
<Button.Root
|
||||
onclick={next}
|
||||
disabled={start + perPage >= filteredModules.length}
|
||||
class="rounded border px-4 py-2 transition-all active:scale-95 disabled:opacity-50 disabled:active:scale-100"
|
||||
>
|
||||
{getTranslation('next', currentLocale)}
|
||||
</Button.Root>
|
||||
</div>
|
||||
{/if}
|
||||
@@ -0,0 +1,9 @@
|
||||
@import 'tailwindcss';
|
||||
@import '@fontsource-variable/geist-mono/wght.css';
|
||||
|
||||
@custom-variant dark (&:where(.dark, .dark *));
|
||||
|
||||
@theme {
|
||||
--font-mono: 'Geist Mono', monospace;
|
||||
--font-sans: 'Geist Mono', monospace;
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 56 KiB |
@@ -0,0 +1,3 @@
|
||||
# allow crawling everything by default
|
||||
User-agent: *
|
||||
Disallow:
|
||||
@@ -0,0 +1,17 @@
|
||||
import adapter from '@sveltejs/adapter-auto';
|
||||
|
||||
/** @type {import('@sveltejs/kit').Config} */
|
||||
const config = {
|
||||
compilerOptions: {
|
||||
// Force runes mode for the project, except for libraries. Can be removed in svelte 6.
|
||||
runes: ({ filename }) => (filename.split(/[/\\]/).includes('node_modules') ? undefined : true)
|
||||
},
|
||||
kit: {
|
||||
// adapter-auto only supports some environments, see https://svelte.dev/docs/kit/adapter-auto for a list.
|
||||
// If your environment is not supported, or you settled on a specific environment, switch out the adapter.
|
||||
// See https://svelte.dev/docs/kit/adapters for more information about adapters.
|
||||
adapter: adapter()
|
||||
}
|
||||
};
|
||||
|
||||
export default config;
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"extends": "./.svelte-kit/tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"rewriteRelativeImportExtensions": true,
|
||||
"allowJs": true,
|
||||
"checkJs": true,
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"resolveJsonModule": true,
|
||||
"skipLibCheck": true,
|
||||
"sourceMap": true,
|
||||
"strict": true,
|
||||
"moduleResolution": "bundler"
|
||||
}
|
||||
// Path aliases are handled by https://svelte.dev/docs/kit/configuration#alias
|
||||
// except $lib which is handled by https://svelte.dev/docs/kit/configuration#files
|
||||
//
|
||||
// To make changes to top-level options such as include and exclude, we recommend extending
|
||||
// the generated config; see https://svelte.dev/docs/kit/configuration#typescript
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import tailwindcss from '@tailwindcss/vite';
|
||||
import { sveltekit } from '@sveltejs/kit/vite';
|
||||
import { defineConfig } from 'vite';
|
||||
|
||||
export default defineConfig({ plugins: [tailwindcss(), sveltekit()] });
|
||||
Reference in New Issue
Block a user