Skip to content

Commit e817940

Browse files
committed
Merge branch 'main' of github.com:InferenceKTH/Find-My-Next-Course into fav-list-rework
2 parents dc4e519 + 874fa25 commit e817940

26 files changed

Lines changed: 583 additions & 204 deletions

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/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: 25 additions & 6 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) {
@@ -127,6 +131,11 @@ export const model = {
127131
this.filtersCalculated = true;
128132
},
129133

134+
setApplyRemoveNullCourses() {
135+
this.filterOptions.applyRemoveNullCourses = !this.filterOptions.applyRemoveNullCourses;
136+
this.setFiltersChange();
137+
},
138+
130139
updateLevelFilter(level) {
131140
this.filterOptions.level = level;
132141
},
@@ -144,6 +153,10 @@ export const model = {
144153
this.filterOptions.eligibility = eligibility;
145154
},
146155

156+
updateDepartmentFilter(department) {
157+
this.filterOptions.department = department;
158+
},
159+
147160
//setters for the filter options
148161
setApplyTranscriptFilter(transcriptFilterState) {
149162
this.filterOptions.applyTranscriptFilter = transcriptFilterState;
@@ -160,10 +173,16 @@ export const model = {
160173
setApplyCreditsFilter(creditsFilterState) {
161174
this.filterOptions.applyCreditsFilter = creditsFilterState;
162175
},
163-
// setApplyDepartmentFilter(departmentFilterState) {
164-
// this.filterOptions.applyDepartmentFilter = departmentFilterState;
165-
// },
176+
setApplyDepartmentFilter(departmentFilterState) {
177+
this.filterOptions.applyDepartmentFilter = departmentFilterState;
178+
},
166179

180+
async getAverageRating(courseCode) {
181+
const reviews = await getReviewsForCourse(courseCode);
182+
if (!reviews || reviews.length === 0) return null;
183+
const total = reviews.reduce((sum, review) => sum + (review.overallRating || 0), 0);
184+
return (total / reviews.length).toFixed(1);
185+
},
167186

168187

169188
};

my-app/src/pages/App.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { model } from '/src/model.js';
1010
function MainAppLayout({ model }) {
1111
return (
1212
<div className="flex h-screen w-screen overflow-hidden">
13-
<FilterPresenter model={model} />
1413
<div className="flex-auto w-40% h-full bg-gradient-to-t from-[#4f3646] to-[#6747c0]">
1514
<SidebarPresenter model={model} />
1615
</div>
@@ -21,6 +20,7 @@ function MainAppLayout({ model }) {
2120
<div className="flex-auto border bg-[#121212] relative">
2221
<ListViewPresenter model={model} />
2322
</div>
23+
<FilterPresenter model={model} />
2424
</div>
2525
</div>
2626
);

0 commit comments

Comments
 (0)