Skip to content

Commit 485be96

Browse files
committed
Merge branch 'main' of github.com:InferenceKTH/Find-My-Next-Course into course-page
2 parents d8969be + 27a5b77 commit 485be96

38 files changed

Lines changed: 15240 additions & 104 deletions

.DS_Store

6 KB
Binary file not shown.

docs/_config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
theme: jekyll-theme-minimal

docs/index.md

Whitespace-only changes.

my-app/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ yarn-error.log*
77
pnpm-debug.log*
88
lerna-debug.log*
99
/node_modules
10+
.firebase
1011

1112
node_modules
1213
dist
@@ -23,3 +24,4 @@ dist-ssr
2324
*.njsproj
2425
*.sln
2526
*.sw?
27+

my-app/firebase.js

Lines changed: 67 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,31 @@ const firebaseConfig = {
1818
const app = initializeApp(firebaseConfig);
1919
export const auth = getAuth(app);
2020
export const db = getDatabase(app);
21-
// export const googleProvider = new GoogleAuthProvider();
22-
// googleProvider.addScope("profile");
23-
// googleProvider.addScope("email");
21+
export const googleProvider = new GoogleAuthProvider();
22+
googleProvider.addScope("profile");
23+
googleProvider.addScope("email");
2424

2525
// fetches all relevant information to create the model
2626
async function firebaseToModel(model) {
27-
const courses = await fetchCourses();
27+
const courses = await fetchAllCourses();
2828
model.setCourses(courses);
2929
}
3030

3131
export function connectToFirebase(model) {
32-
// onAuthStateChanged(auth, (user) => {
33-
// model.setUser(user);
34-
// }); !can be used for auth!
35-
36-
firebaseToModel(model);
32+
onAuthStateChanged(auth, (user) => {
33+
model.setUser(user);
34+
});
35+
firebaseToModel(model);
3736
}
3837

3938
export async function addCourse(course){
40-
if(!course?.courseCode)
41-
return;
42-
const myRef = ref(db, `courses/${course.courseCode}`);
43-
await set(myRef, course);
39+
if(!course?.code)
40+
return;
41+
const myRef = ref(db, `courses/${course.code}`);
42+
await set(myRef, course);
4443
}
4544

45+
<<<<<<< HEAD
4646
export async function fetchCourses() {
4747
const myRef = ref(db, `courses`);
4848
const snapshot = await get(myRef);
@@ -53,4 +53,58 @@ export async function fetchCourses() {
5353
courses = [...courses, courses[id]];
5454
}
5555
return courses;
56+
=======
57+
export async function fetchAllCourses() {
58+
const myRef = ref(db, `courses`);
59+
const snapshot = await get(myRef);
60+
61+
if (!snapshot.exists()) return [];
62+
63+
const value = snapshot.val(); // Firebase returns an object where keys are course IDs
64+
const courses = [];
65+
66+
for (const id of Object.keys(value)) {
67+
courses.push({ id, ...value[id] });
68+
}
69+
70+
return courses;
71+
>>>>>>> 27a5b77bd1478c3b8493b19385b77340472d7591
5672
}
73+
74+
// Before: [ {courseCode: "CS101", name: "Intro to CS"}, {...} ]
75+
// After: { "CS101": { name: "Intro to CS" }, "CS102": {...} }
76+
77+
78+
export async function fetchCoursesSnapshot() {
79+
const myRef = ref(db, `courses`);
80+
const snapshot = await get(myRef);
81+
if (!snapshot.exists()) return {}; // Return empty object instead of array
82+
83+
return snapshot.val(); // Return the object directly
84+
}
85+
86+
export async function saveJSONCoursesToFirebase(model, data){
87+
if(!data || !model){
88+
console.log("no model or data")
89+
return;
90+
}
91+
const entries = Object.entries(data);
92+
entries.forEach(entry => {
93+
const course = {
94+
code : entry[1].code ,
95+
name: entry[1]?.name ?? "",
96+
location: entry[1]?.location ?? "",
97+
department: entry[1]?.department ?? "",
98+
language: entry[1]?.language ?? "",
99+
description: entry[1]?.description ?? "",
100+
academicLevel: entry[1]?.academic_level ?? "",
101+
period: entry[1]?.period ?? "",
102+
credits: entry[1]?.credits ?? 0,
103+
//lectureCount:entry[1].courseLectureCount,
104+
//prerequisites:entry.coursePrerequisites
105+
}
106+
model.addCourse(course);
107+
108+
});
109+
}
110+

my-app/index.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<!doctype html>
22
<html lang="en">
3+
<<<<<<< HEAD
34
<head>
45
<meta charset="UTF-8" />
56
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
@@ -12,4 +13,15 @@
1213
<div id="modal-root"></div>
1314
<script type="module" src="/src/index.jsx"></script>
1415
</body>
16+
=======
17+
<head>
18+
<meta charset="UTF-8" />
19+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
20+
<link href="/src/styles.css" rel="stylesheet">
21+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
22+
<title>Find my course</title>
23+
</head>
24+
<div id="root"></div>
25+
<script type="module" src="/src/index.jsx"></script>
26+
>>>>>>> 27a5b77bd1478c3b8493b19385b77340472d7591
1527
</html>

0 commit comments

Comments
 (0)