Skip to content

Commit 5df4e5d

Browse files
committed
Merge branch 'main' of github.com:jkluge/Find-My-Next-Course into persistance
2 parents 7099590 + c00d68b commit 5df4e5d

30 files changed

Lines changed: 804 additions & 273 deletions

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Project Structure Draft:
2+
3+
```
4+
.
5+
├── firebase.js // handles fetching and saving to the realtime database on firebase
6+
├── firebase.json // used for firebase deploy
7+
├── index.html // the main index page - contains header and loads the index.jsx
8+
├── package.json // used for nodejs (npm) packages
9+
├── package-lock.json // used for nodejs (npm) packages
10+
├── README.md // this file ^^
11+
├── src // contains all source filed
12+
│   ├── assets // content, e.g. pictures, ressources etc.
13+
│   │   └── react.svg
14+
│   ├── index.jsx // the react router - routes between pages, all pages are inserted here
15+
│   ├── model.js // the model - handles prog. logic, that is either global or account specific
16+
│   ├── pages // pages combine the presenters to a webpage. mby obsolete for 1 page project
17+
│   │   └── App.jsx // The future homepage?
18+
│   ├── presenters // Presenters link views and the model.
19+
│   | Hooks to modify the model & component state is defined here
20+
│   │   └── HandleSearchPresenter.jsx // An example presenter
21+
│   ├── styles.css // a style document - mby one for each view?
22+
│   └── views // views define parts of pages cosmetically.
23+
│   └── DummyView.jsx
24+
└── vite.config.js
25+
```
26+
27+

my-app/package-lock.json

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

my-app/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
"preview": "vite preview"
1111
},
1212
"dependencies": {
13-
13+
"@dagrejs/dagre": "^1.1.4",
1414
"@headlessui/react": "^2.2.1",
1515
"@heroicons/react": "^2.2.0",
16-
"@dagrejs/dagre": "^1.1.4",
16+
"@react-buddy/ide-toolbox": "^2.4.0",
1717
"@tailwindcss/vite": "^4.0.17",
1818
"@xyflow/react": "^12.5.5",
1919
"autoprefixer": "^10.4.21",

my-app/src/assets/example.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145248,4 +145248,4 @@
145248145248
"prerequisites_text": "null",
145249145249
"learning_outcomes": "null"
145250145250
}
145251-
}
145251+
}

my-app/src/dev/README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
This directory contains utility files which enable some visual features of the
2+
[React Buddy](https://plugins.jetbrains.com/plugin/17467-react-buddy/) plugin.
3+
Files in the directory should be committed to source control.
4+
5+
React Buddy palettes describe reusable components and building blocks. `React Palette` tool window becomes available
6+
when an editor with React components is active. You can drag and drop items from the tool window to the code editor or
7+
JSX Outline. Alternatively, you can insert components from the palette using code generation action (`alt+insert` /
8+
`⌘ N`).
9+
10+
Add components to the palette using `Add to React Palette` intention or via palette editor (look for the corresponding
11+
link in `palette.tsx`). There are some ready-to-use palettes for popular React libraries which are published as npm
12+
packages and can be added as a dependency:
13+
14+
```jsx
15+
import AntdPalette from "@react-buddy/palette-antd";
16+
import ReactIntlPalette from "@react-buddy/palette-react-intl";
17+
18+
export const PaletteTree = () => (
19+
<Palette>
20+
<AntdPalette/>
21+
<ReactIntlPalette/>
22+
<Category name="App templates">
23+
<Component name="Card">
24+
<Variant name="Loading">
25+
<Card title="Card title">
26+
<Skeleton loading={true} avatar active>
27+
Card content
28+
</Skeleton>
29+
</Card>
30+
</Variant>
31+
</Component>
32+
<Component name="Form">
33+
<Variant proto={FormTemplate}/>
34+
</Component>
35+
</Category>
36+
</Palette>
37+
)
38+
```
39+
40+
React Buddy explicitly registers any previewed component in the `previews.tsx` file so that you can specify required
41+
props.
42+
43+
```jsx
44+
<ComponentPreview path="/Page">
45+
<Page title={'Hello'}/>
46+
</ComponentPreview>
47+
```
48+
49+
You can add some global initialization logic for the preview mode in `useInitital.ts`,
50+
e.g. implicitly obtain user session:
51+
52+
```typescript
53+
export const useInitial: () => InitialHookStatus = () => {
54+
const [loading, setLoading] = useState<boolean>(false);
55+
const [error, setError] = useState<boolean>(false);
56+
57+
useEffect(() => {
58+
setLoading(true);
59+
async function login() {
60+
const response = await loginRequest(DEV_LOGIN, DEV_PASSWORD);
61+
if (response?.status !== 200) {
62+
setError(true);
63+
}
64+
setLoading(false);
65+
}
66+
login();
67+
}, []);
68+
return { loading, error };
69+
};
70+
```

my-app/src/dev/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import React from "react"
2+
import {useInitial} from "./useInitial"
3+
4+
const ComponentPreviews = React.lazy(() => import("./previews"))
5+
6+
export {
7+
ComponentPreviews,
8+
useInitial
9+
}

my-app/src/dev/palette.jsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import {Fragment} from "react"
2+
import {
3+
Category,
4+
Component,
5+
Variant,
6+
Palette,
7+
} from "@react-buddy/ide-toolbox"
8+
9+
export const PaletteTree = () => (
10+
<Palette>
11+
<Category name="App">
12+
<Component name="Loader">
13+
<Variant>
14+
<ExampleLoaderComponent/>
15+
</Variant>
16+
</Component>
17+
</Category>
18+
</Palette>
19+
)
20+
21+
export function ExampleLoaderComponent() {
22+
return (
23+
<Fragment>Loading...</Fragment>
24+
)
25+
}

my-app/src/dev/previews.jsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {Previews} from '@react-buddy/ide-toolbox'
2+
import {PaletteTree} from './palette'
3+
4+
const ComponentPreviews = () => {
5+
return (
6+
<Previews palette={<PaletteTree/>}>
7+
</Previews>
8+
)
9+
}
10+
11+
export default ComponentPreviews

my-app/src/dev/useInitial.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import {useState} from 'react'
2+
3+
export const useInitial = () => {
4+
const [status, setStatus] = useState({
5+
loading: false,
6+
error: false
7+
})
8+
/*
9+
Implement hook functionality here.
10+
If you need to execute async operation, set loading to true and when it's over, set loading to false.
11+
If you caught some errors, set error status to true.
12+
Initial hook is considered to be successfully completed if it will return {loading: false, error: false}.
13+
*/
14+
return status
15+
}

my-app/src/model.js

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,20 @@ export const model = {
1818
applyTranscriptFilter: true,
1919
eligibility: "weak", //the possible values for the string are: "weak"/"moderate"/"strong"
2020
applyLevelFilter: true,
21-
level: [], //the possible values for the array are: "PREPARATORY", "BASIC", "ADVANCED", "RESEARCH"
21+
level: ["PREPARATORY", "BASIC", "ADVANCED", "RESEARCH"], //the possible values for the array are: "PREPARATORY", "BASIC", "ADVANCED", "RESEARCH"
2222
applyLanguageFilter: true,
2323
language: "none", //the possible values for the string are: "none"/"english"/"swedish"/"both"
2424
applyLocationFilter:true,
2525
location: [], //the possible values for the array are: 'KTH Campus', 'KTH Kista', 'AlbaNova', 'KTH Flemingsberg', 'KTH Solna', 'KTH Södertälje', 'Handelshögskolan', 'KI Solna', 'Stockholms universitet', 'KONSTFACK'
2626
applyCreditsFilter:true,
2727
creditMin: 0,
2828
creditMax: 45,
29-
applyDepartmentFilter:false,
30-
department: []
29+
applyDepartmentFilter: true,
30+
department: ["EECS/Computational Science and Technology", "EECS/Theoretical Computer Science", "EECS/Electric Power and Energy Systems", "EECS/Network and Systems Engineering",
31+
"ITM/Learning in Engineering Sciences", "ITM/Industrial Economics and Management", "ITM/Energy Systems", "ITM/Integrated Product Development and Design", "ITM/SKD GRU",
32+
"SCI/Mathematics", "SCI/Applied Physics", "SCI/Mechanics", "SCI/Aeronautical and Vehicle Engineering",
33+
"ABE/Sustainability and Environmental Engineering", "ABE/Concrete Structures", "ABE/Structural Design & Bridges", "ABE/History of Science, Technology and Environment", ],
34+
applyRemoveNullCourses: false
3135
},
3236

3337
setUser(user) {
@@ -84,15 +88,17 @@ export const model = {
8488
entries.forEach(entry => {
8589
const course = {
8690
code: entry[1].code,
87-
name: entry[1]?.name ?? "",
88-
location: entry[1]?.location ?? "",
89-
department: entry[1]?.department ?? "",
90-
language: entry[1]?.language ?? "",
91-
description: entry[1]?.description ?? "",
92-
academicLevel: entry[1]?.academic_level ?? "",
93-
period: entry[1]?.period ?? "",
91+
name: entry[1]?.name ?? "null",
92+
location: entry[1]?.location ?? "null",
93+
department: entry[1]?.department ?? "null",
94+
language: entry[1]?.language ?? "null",
95+
description: entry[1]?.description ?? "null",
96+
academicLevel: entry[1]?.academic_level ?? "null",
97+
period: entry[1]?.period ?? "null",
9498
credits: entry[1]?.credits ?? 0,
95-
prerequisites: entry[1]?.prerequisites ?? "",
99+
prerequisites: entry[1]?.prerequisites ?? "null",
100+
prerequisites_text: entry[1]?.prerequisites_text ?? "null",
101+
learning_outcomes: entry[1]?.learning_outcomes ?? "null"
96102
};
97103
this.addCourse(course);
98104
});
@@ -129,6 +135,11 @@ export const model = {
129135
this.filterOptions = options; // do we want to set the flags? What about useEffect?
130136
},
131137

138+
setApplyRemoveNullCourses() {
139+
this.filterOptions.applyRemoveNullCourses = !this.filterOptions.applyRemoveNullCourses;
140+
this.setFiltersChange();
141+
},
142+
132143
updateLevelFilter(level) {
133144
this.filterOptions.level = level;
134145
},
@@ -146,6 +157,10 @@ export const model = {
146157
this.filterOptions.eligibility = eligibility;
147158
},
148159

160+
updateDepartmentFilter(department) {
161+
this.filterOptions.department = department;
162+
},
163+
149164
//setters for the filter options
150165
setApplyTranscriptFilter(transcriptFilterState) {
151166
this.filterOptions.applyTranscriptFilter = transcriptFilterState;
@@ -162,10 +177,16 @@ export const model = {
162177
setApplyCreditsFilter(creditsFilterState) {
163178
this.filterOptions.applyCreditsFilter = creditsFilterState;
164179
},
165-
// setApplyDepartmentFilter(departmentFilterState) {
166-
// this.filterOptions.applyDepartmentFilter = departmentFilterState;
167-
// },
180+
setApplyDepartmentFilter(departmentFilterState) {
181+
this.filterOptions.applyDepartmentFilter = departmentFilterState;
182+
},
168183

184+
async getAverageRating(courseCode) {
185+
const reviews = await getReviewsForCourse(courseCode);
186+
if (!reviews || reviews.length === 0) return null;
187+
const total = reviews.reduce((sum, review) => sum + (review.overallRating || 0), 0);
188+
return (total / reviews.length).toFixed(1);
189+
},
169190

170191

171192
};

0 commit comments

Comments
 (0)