Skip to content

Commit

Permalink
feat: override semester
Browse files Browse the repository at this point in the history
  • Loading branch information
iceghost committed Dec 25, 2023
1 parent 9274a6f commit 43e6ef9
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"format": "prettier --write --plugin prettier-plugin-svelte --plugin prettier-plugin-tailwindcss ."
},
"devDependencies": {
"@bkalendar/core": "^23.1.3",
"@bkalendar/core": "^23.2.0",
"@fontsource/arimo": "^5.0.17",
"@sveltejs/adapter-static": "^2.0.3",
"@sveltejs/kit": "^1.27.1",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/lib/OkeeButton.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</script>

<button
class="disabled:bg-gradient-none rounded px-2 py-1 font-bold active:opacity-50 enabled:bg-gradient-to-br disabled:cursor-not-allowed disabled:bg-slate-200 disabled:text-slate-500 {variant ==
class="disabled:bg-gradient-none rounded px-2 py-1 font-bold enabled:bg-gradient-to-br enabled:active:opacity-50 disabled:cursor-not-allowed disabled:bg-slate-200 disabled:text-slate-500 {variant ==
'navy'
? 'from-sky-500 to-marine-300 text-slate-50'
: variant == 'slate'
Expand Down
45 changes: 36 additions & 9 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,22 @@
import { fly } from 'svelte/transition';
import Key from '$lib/Key.svelte';
import NameInput from './NameInput.svelte';
import OkeeButton from '$lib/OkeeButton.svelte';
let raw: string;
let kind: 'sinh viên' | 'giảng viên' | 'sau đại học' = 'sinh viên';
let output: 'ical' | 'gapi' = 'gapi';
let step: 'import' | 'export' = 'import';
let semester: number | undefined = undefined;
let error: Error | null = null;
let name: string;
let error: unknown;
$: timetable = process(raw, kind);
let name: string;
$: if (timetable) name = calendarName(kind, timetable);
$: if (!`${semester}`.match(/^\d+[123]$/)) {
error = new Error('mã học kỳ sai định dạng. ví dụ mã đúng: 231, 232, 233.');
} else {
error = null;
}
function process(r: typeof raw, k: typeof kind) {
if (!raw) return null;
Expand All @@ -45,10 +51,12 @@
try {
let timetable = parse(r);
resolve(timetable);
name = calendarName(kind, timetable);
semester = timetable?.semester;
error = null;
return timetable;
} catch (e) {
error = e;
error = e as Error;
return null;
}
}
Expand All @@ -63,30 +71,49 @@
return `SDH${timetable.semester}`;
}
}
function nextStep() {
timetable!.semester = semester!;
step = 'export';
}
</script>

<svelte:head>
<title>Nhập lịch | BKalendar</title>
</svelte:head>

<BKalendar />
<p class="text-right">vì bạn xứng đáng có một bộ lịch đẹp 🌹</p>
<p class="text-right"><i>vì bạn xứng đáng có một bộ lịch đẹp 🌹</i></p>
<div class="h-4" />
{#if !timetable}
{#if step == 'import'}
<div out:fly={{ delay: 500, duration: 500, x: -100 }}>
<p>
hãy <Key>Ctrl</Key>
<Key>A</Key> rồi <Key>Ctrl</Key>
<Key>V</Key> thời khóa biểu của bạn vào bên dưới, mình sẽ tự trích lịch của bạn ra 🎩
<Key>V</Key> thời khóa biểu của bạn vào bên dưới, mình sẽ tự trích lịch của bạn ra 🪄
</p>
<div class="h-4" />
<PasteArea bind:raw />
<div class="h-4" />
<KindSelect bind:kind />
<div class="flex items-center justify-end space-x-4">
<p class="flex-shrink-0">học kỳ</p>
<input
type="number"
class="inline w-16 outline-dashed outline-[1.5px] outline-slate-200 disabled:cursor-not-allowed disabled:bg-slate-100"
disabled={!timetable}
bind:value={semester}
/>
</div>
<div class="h-4" />
<div class="flex justify-end">
<OkeeButton variant="navy" disabled={!timetable || !!error} on:click={nextStep} />
</div>
{#if error}
<div class="h-4" />
<ErrorReport {error} />
{/if}
<div class="h-4" />
<KindSelect bind:kind />
</div>
{:else}
<div in:fly={{ delay: 1000, x: 100 }}>
Expand Down
4 changes: 3 additions & 1 deletion src/routes/ErrorReport.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
UnresolvedError
} from '@bkalendar/core';
export let error: unknown;
export let error: Error;
$: console.error(error);
</script>
Expand Down Expand Up @@ -44,6 +44,8 @@
bạn chịu khó xóa bớt các dòng của các môn không nằm trong thời khóa biểu này ra khỏi đoạn copy
nha.
</p>
{:else if error instanceof UnresolvedError}
<p>thời khóa biểu của bạn hình như không có môn nào đi học hết á</p>
{:else}
<p>{error.message}</p>
{/if}

0 comments on commit 43e6ef9

Please sign in to comment.