Skip to content
Snippets Groups Projects
Commit 153e2196 authored by Eli Kogan-Wang's avatar Eli Kogan-Wang
Browse files

Merge branch 'dev' into 'master'

Dev

See merge request !9
parents 53aa358b 5cc46b42
No related branches found
No related tags found
2 merge requests!15Master,!9Dev
Pipeline #
......@@ -3,7 +3,7 @@ import { makeAvaliableJsonStringifyMap, makeAvaliableMap } from './LocalStorageM
import { browser } from '$app/env';
import { writableLocalStorageStore } from './localStorageStore';
export const semesterNameStore = writableLocalStorageStore('semesterName', 100, "Sommer 2022")
export const semesterNameStore = writableLocalStorageStore('semesterName', 100, 'Sommer 2022');
let semesterName: string;
......@@ -26,7 +26,7 @@ export const getSemesters = async (): Promise<SemesterWithoutCoursesButId[]> =>
if (!response.ok) {
throw new Error(`${response.status} ${response.statusText}`);
}
const semesters = await response.json() as SemesterWithoutCoursesButId[];
const semesters = (await response.json()) as SemesterWithoutCoursesButId[];
// if the semesterId is still undefined, just choose the last one
if (semesterId === undefined) {
semesterNameStore.set(semesters[semesters.length - 1].name);
......@@ -36,7 +36,7 @@ export const getSemesters = async (): Promise<SemesterWithoutCoursesButId[]> =>
// set value to semesterResponse
semesterResponse = semesters;
return semesters;
}
};
export const getSemesterId = async (): Promise<number> => {
if (semesterId == undefined) {
......@@ -45,7 +45,7 @@ export const getSemesterId = async (): Promise<number> => {
return semesterId as unknown as number;
}
return semesterId;
}
};
const getUrl = () => {
const url = import.meta.env.VITE_PAULINE_API;
......@@ -69,7 +69,9 @@ const getUrl = () => {
if (!browser) {
// return http://0.0.0.0/
return new URL('/', 'http://0.0.0.0');
throw new Error('VITE_PAULINE_API is relative but we are not on the browser, my assumptions were wrong');
throw new Error(
'VITE_PAULINE_API is relative but we are not on the browser, my assumptions were wrong'
);
}
// we are on the browser, so we can use the current origin
......@@ -78,24 +80,23 @@ const getUrl = () => {
return origin;
};
const searchResultsCache = makeAvaliableJsonStringifyMap<{
const searchResultsCache = makeAvaliableJsonStringifyMap<
{
title?: string;
semesterId: number;
}, string[]>(
'searchResultsCacheNew'
); // title -> cid[]
},
string[]
>('searchResultsCacheNew'); // title -> cid[]
export const cidCoursesCache = makeAvaliableJsonStringifyMap<{
export const cidCoursesCache = makeAvaliableJsonStringifyMap<
{
cid: string;
semesterName: string;
}, CourseWithoutAppointments>(
'cidCoursesCacheNew'
); // cid -> course
},
CourseWithoutAppointments
>('cidCoursesCacheNew'); // cid -> course
export const getCourses = async (
signal?: AbortSignal
): Promise<CourseWithoutAppointments[]> => {
export const getCourses = async (signal?: AbortSignal): Promise<CourseWithoutAppointments[]> => {
if (!browser) return [];
const semesterId = await getSemesterId();
const cacheKey = { semesterId };
......@@ -118,10 +119,13 @@ export const getCourses = async (
(course: CourseWithoutAppointments) => !cidCoursesCache.has({ cid: course.cid, semesterName })
);
newCourses.forEach((course: CourseWithoutAppointments) =>
cidCoursesCache.set({
cidCoursesCache.set(
{
cid: course.cid,
semesterName,
}, course)
semesterName
},
course
)
);
searchResultsCache.set(
cacheKey,
......@@ -131,7 +135,7 @@ export const getCourses = async (
};
const courseCache = makeAvaliableJsonStringifyMap<
{ course_id: string; semesterId: number; },
{ course_id: string; semesterId: number },
CourseWithSmallGroupBackrefs
>('courseCache');
......@@ -162,16 +166,15 @@ semesterNameStore.subscribe(async () => {
const cachedId = semesterResponse?.find((semester) => semester.name === semesterName)?.id;
if (cachedId) {
semesterId = cachedId;
}
else {
} else {
const semesters = await getSemesters();
const semester = semesters.find(s => s.name === semesterName);
const semester = semesters.find((s) => s.name === semesterName);
if (!semester) {
throw new Error(`Semester ${semesterName} not found`);
}
semesterId = semester.id;
}
})
});
export const bustCache = (): void => {
searchResultsCache.clear();
......@@ -201,7 +204,7 @@ export type SmallGroup = {
appointments: Appointment[];
};
export type SmallGroupBackref = SmallGroup & { cid: string; };
export type SmallGroupBackref = SmallGroup & { cid: string };
export type CourseWithSmallGroupBackrefs = Omit<Course, 'small_groups'> & {
small_groups: SmallGroupBackref[];
......
......@@ -26,11 +26,17 @@
}
$: instructors = courseData?.appointments?.length ? courseData.appointments[0].instructors : '';
const splitStuff = (str: string | undefined) => {
if (str === undefined) return undefined;
const split = str.split('|');
return split[0];
};
</script>
<details class="info-parent {open ? 'ring ring-primary ring-inset' : ''}" bind:open>
<summary class="info">
<span class="title text-link">{courseInfo?.cid}: {courseInfo?.name}</span>
<span class="title text-link">{splitStuff(courseInfo?.cid)}: {courseInfo?.name}</span>
{#if loading}
<span class="loading">Loading...</span>
{/if}
......@@ -40,7 +46,7 @@
<div class="mb-5">
<p>
<span class="text-link">Kurs ID:</span>
{courseData.cid}
{splitStuff(courseData.cid)}
</p>
<p>
<span class="text-link">Professor/Dozent:</span>
......
<script>
import { bustCache } from '$lib/api';
</script>
<h1 class="text-3xl">Pauline</h1>
<p>
Pauline ist dein Stundenplaner für die Universität Paderborn. Mit Pauline kannst du schnell und
......@@ -26,7 +30,7 @@
machen. Mit <kbd>Ctrl</kbd>+<kbd>Y</kbd> kannst du ihn wiederherstellen. Für Undo/Redo am Handy arbeiten
wir noch ;)
</p>
<br>
<br />
<h2 class="text-2xl">Autoren</h2>
<ul>
<li>Adrian Block (adrblo)</li>
......@@ -37,15 +41,25 @@
Wir alle sind unter unserem IMT-Usernamen (in Klammern) @mail.upb.de zu erreichen. Bitte Erwähne
"Pauline" in deinem Betreff, damit wir wissen, worum es geht.
</p>
<br>
<br />
<h2 class="text-2xl">Mitwirkung</h2>
<p>
Das Projekt ist Open-Source unter <a href='https://git.cs.uni-paderborn.de/pauline'>GitLab</a> zu finden.
Das Projekt ist Open-Source unter <a href="https://git.cs.uni-paderborn.de/pauline">GitLab</a> zu finden.
</p>
<br>
<br />
<h2 class="text-2xl">Privatsphäre</h2>
<p>
Pauline sammelt anonymisierte Nutzungsdaten, um Nutzerzahlen auszuwerten. Es werden jedoch keine persönlichen Daten erhoben.
Pauline sammelt anonymisierte Nutzungsdaten, um Nutzerzahlen auszuwerten. Es werden jedoch keine
persönlichen Daten erhoben.
</p>
<p>
<button
on:click={bustCache}
class="bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-4 rounded"
>
Cache leeren
</button>
</p>
<style>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment