Skip to content

Commit b25e2bb

Browse files
committed
okay no more adding courses that don't exist
1 parent 2b59428 commit b25e2bb

File tree

3 files changed

+56
-33
lines changed

3 files changed

+56
-33
lines changed

src-tauri/src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ fn get_courses(courses: String) -> String {
135135
}
136136

137137
#[tauri::command]
138-
fn check_course_exists(course_id: String) -> String {
138+
fn check_course_exists(course_id: String) -> bool {
139139
let response = reqwest::blocking::get(format!(
140140
"https://oscar.gatech.edu/pls/bprod/bwckschd.p_disp_detail_sched?term_in=202302&crn_in={}",
141141
course_id,
@@ -150,13 +150,13 @@ fn check_course_exists(course_id: String) -> String {
150150
let err_selector = Selector::parse(error_str).unwrap();
151151

152152
let err_exists = document.select(&err_selector);
153-
153+
154154
for el in err_exists {
155155
if el.text().collect::<String>() == "No detailed class information found" {
156-
return format!("{}", false);
156+
return true;
157157
}
158158
}
159-
return format!("{}", true);
159+
return false;
160160
}
161161

162162
fn main() {

src/App.tsx

Lines changed: 51 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,48 +14,57 @@ import {
1414
} from "./utils";
1515

1616
const [courses, setCourses] = createStore<Course[]>([
17-
{
18-
id: 1,
19-
courseNum: 21135,
20-
seatAvailable: false,
21-
waitlistAvailable: false,
22-
},
23-
{
24-
id: 2,
25-
courseNum: 25587,
26-
seatAvailable: false,
27-
waitlistAvailable: false,
28-
},
29-
{
30-
id: 3,
31-
courseNum: 27395,
32-
seatAvailable: false,
33-
waitlistAvailable: false,
34-
},
35-
{
36-
id: 4,
37-
courseNum: 24649,
38-
seatAvailable: false,
39-
waitlistAvailable: false,
40-
},
17+
// {
18+
// id: 1,
19+
// courseNum: 21135,
20+
// seatAvailable: false,
21+
// waitlistAvailable: false,
22+
// },
23+
// {
24+
// id: 2,
25+
// courseNum: 25587,
26+
// seatAvailable: false,
27+
// waitlistAvailable: false,
28+
// },
29+
// {
30+
// id: 3,
31+
// courseNum: 27395,
32+
// seatAvailable: false,
33+
// waitlistAvailable: false,
34+
// },
35+
// {
36+
// id: 4,
37+
// courseNum: 24649,
38+
// seatAvailable: false,
39+
// waitlistAvailable: false,
40+
// },
4141
]);
4242

4343
const [newCourse, setNewCourse] = createSignal(0);
4444

45-
const addCourse = () => {
45+
const addCourse = async () => {
4646
if (newCourse() > courseMAX || newCourse() < courseMIN) {
4747
toast.error("Course value not in range");
4848
return;
4949
}
5050

51-
if (!checkCourseExists(newCourse())) {
51+
const courseExists = await checkCourseExists(newCourse());
52+
53+
if (courseExists) {
5254
toast.error("Course CRN doesn't exist");
5355
return;
5456
}
5557

56-
const valid = courses.some((course: any) => course.courseNum == newCourse());
58+
const isInList = courses.some(
59+
(course: any) => course.courseNum == newCourse()
60+
);
5761

58-
if (!valid) {
62+
if (isInList) {
63+
toast.error("Course already in your list");
64+
return;
65+
}
66+
67+
if (courses.length > 0) {
5968
setCourses([
6069
...courses,
6170
{
@@ -65,13 +74,27 @@ const addCourse = () => {
6574
waitlistAvailable: false,
6675
},
6776
]);
77+
return;
6878
}
79+
80+
setCourses([
81+
{
82+
id: 1,
83+
courseNum: newCourse(),
84+
seatAvailable: false,
85+
waitlistAvailable: false,
86+
},
87+
]);
6988
};
7089

7190
const App = () => {
7291
const [data, setData] = createSignal("No data fetched!");
7392

7493
const getData = async () => {
94+
if (courses.length == 0) {
95+
toast.error("Add a course before fetching data!");
96+
return;
97+
}
7598
setData("Loading");
7699
toast.loading("Fetching your data");
77100

src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const openLink = async () => {
1515
export const checkCourseExists = async (courseNumber: number) => {
1616
const exists = await invoke("check_course_exists", {
1717
courseId: courseNumber,
18-
});
18+
})
1919

2020
return exists;
2121
};

0 commit comments

Comments
 (0)