From c50e56d744c360336c21799dd675592145e6bed1 Mon Sep 17 00:00:00 2001
From: whats2000 <60466660+whats2000@users.noreply.github.com>
Date: Wed, 3 Jul 2024 01:25:47 +0800
Subject: [PATCH] Fix: Make the return of course unique
---
nsysu_selector_helper/src/App.tsx | 2 +-
nsysu_selector_helper/src/api/NSYSUCourseAPI.ts | 6 +++++-
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/nsysu_selector_helper/src/App.tsx b/nsysu_selector_helper/src/App.tsx
index efb4f30..1ad76d3 100644
--- a/nsysu_selector_helper/src/App.tsx
+++ b/nsysu_selector_helper/src/App.tsx
@@ -86,7 +86,7 @@ const App: FC = () => {
dataSource={courses}
renderItem={course => (
- {course.name} - {course.teacher} ({course.credit} credits)
+ {course.id} {course.name} - {course.teacher} ({course.credit} credits)
)}
style={{ marginTop: '20px' }}
diff --git a/nsysu_selector_helper/src/api/NSYSUCourseAPI.ts b/nsysu_selector_helper/src/api/NSYSUCourseAPI.ts
index c7adaa8..22633ca 100644
--- a/nsysu_selector_helper/src/api/NSYSUCourseAPI.ts
+++ b/nsysu_selector_helper/src/api/NSYSUCourseAPI.ts
@@ -24,7 +24,11 @@ export class NSYSUCourseAPI {
if (!response.ok) {
throw new Error('Failed to fetch courses');
}
- return response.json();
+
+ return response.json().then((courses: Course[]) => {
+ return Array.from(new Set(courses.map(course => course.id)))
+ .map(id => courses.find(course => course.id === id)!);
+ });
}
static async getLatestCourses(): Promise {