Skip to content

Commit 31f1110

Browse files
authored
Merge branch 'main' into course-page
2 parents 7c3feb8 + a270e9b commit 31f1110

23 files changed

Lines changed: 287 additions & 88 deletions

.DS_Store

0 Bytes
Binary file not shown.

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.git
2+
node_modules
3+
dist
4+
.env

.github/workflows/docker-image.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Docker CI
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
pull_request:
7+
branches: ["main"]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Set up Docker Buildx
18+
uses: docker/setup-buildx-action@v2
19+
20+
- name: Build and start services with Docker Compose
21+
run: docker compose up -d --build
22+
23+
- name: Check running containers
24+
run: docker ps -a

Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM node:18-alpine
2+
WORKDIR /app
3+
COPY my-app .
4+
RUN npm ci
5+
EXPOSE 5173
6+
CMD ["npm", "run", "dev"]

docker-compose.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
services:
2+
app:
3+
build:
4+
context: .
5+
dockerfile: Dockerfile
6+
container_name: my-app
7+
ports:
8+
- "5173:5173"
9+
volumes:
10+
- ./my-app:/app # mount local 'my-app' to /app inside the container
11+
environment:
12+
- NODE_ENV=development # set environment variable to development
13+
command: npm run dev
14+
stdin_open: true # interactive sessions
15+
tty: true # keep the container running interactively

my-app/package-lock.json

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

my-app/src/assets/project_icon.png

69.8 KB
Loading

my-app/src/model.js

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
1-
// This model is representing our program logic.
2-
// A certain model is bound to a specific session.
3-
41
import { addCourse } from "../firebase";
52

63
export const model = {
74
user: undefined,
85
currentCourse: undefined,
9-
currentSearch: {},
6+
currentSearch: [],
107
courses: [],
8+
favourites: [],
119
isReady: false,
1210

1311
// sets the current user
1412
setUser(user) {
1513
if (!this.user)
1614
this.user = user;
1715
},
18-
16+
1917
// sets the currently selected course (detail view?) - could be component state
2018
setCurrentCourse(course){
2119
this.currentCourse = course;
2220
},
2321

2422
// keeps track of the current search / the associated promises.
25-
setCurrentSearch(search){
26-
this.currentSearch = search;
23+
setCurrentSearch(searchResults){
24+
this.currentSearch = searchResults;
2725
},
2826

2927
// sets the course array - for example after loading all courses from the DB
@@ -32,21 +30,23 @@ export const model = {
3230
},
3331

3432
// add a single course
35-
// addCourse(course){
36-
// this.courses = [...this.courses, course] // update local copy
37-
// addCourse(course); // update firebase
38-
// },
39-
4033
async addCourse(course) {
4134
try {
4235
await addCourse(course);
4336
this.courses = [...this.courses, course];
44-
console.log("Course added successfully.");
4537
} catch (error) {
4638
console.error("Error adding course:", error);
4739
}
4840
},
4941

42+
addFavourite(course) {
43+
this.favourites = [...this.favourites, course];
44+
},
45+
46+
removeFavourite(course) {
47+
this.favourites = (this.favourites || []).filter(fav => fav.code !== course.code);
48+
},
49+
5050
getCourse(courseID) {
5151
return this.courses.find(course => course.code === courseID);
5252
},
@@ -72,6 +72,14 @@ export const model = {
7272
};
7373
this.addCourse(course);
7474
});
75-
}
76-
}
75+
},
7776

77+
searchCourses(query) {
78+
const searchResults = this.courses.filter(course =>
79+
course.code.toLowerCase() === query.toLowerCase() ||
80+
course.name.toLowerCase().includes(query.toLowerCase()) ||
81+
course.description.toLowerCase().includes(query.toLowerCase())
82+
);
83+
this.setCurrentSearch(searchResults);
84+
}
85+
};

my-app/src/pages/App.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import { ListViewPresenter } from '../presenters/ListViewPresenter.jsx';
77
function App(props) {
88
return (
99
<div className="flex h-screen w-screen">
10-
<div className="flex-auto w-40% h-full bg-[#49347E]">
11-
<SidebarPresenter model={props.model} />
10+
11+
<div className="flex-auto w-40% h-full bg-gradient-to-t from-[#4f3646] to-[#6747c0]">
12+
<SidebarPresenter model={props.model}/>
1213
</div>
1314

1415
<div className="w-3/4 h-full flex flex-col">

my-app/src/presenters/ListViewPresenter.jsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@ import React from 'react';
22
import { observer } from "mobx-react-lite";
33
import ListView from "../views/ListView.jsx";
44

5-
const ListViewPresenter = observer((props) => {
6-
return <ListView courses={props.model.courses} />;
5+
const ListViewPresenter = observer(({ model }) => {
6+
return <ListView
7+
courses={model.courses}
8+
searchResults={model.currentSearch}
9+
favouriteCourses={model.favourites}
10+
addFavourite={model.addFavourite}
11+
removeFavourite={model.removeFavourite}
12+
/>;
713
});
814

915
export { ListViewPresenter };

0 commit comments

Comments
 (0)