-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from whats2000/main
Fix: Fix course loading show undine selection
Showing
84 changed files
with
4,150 additions
and
23,963 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
name: deploy | ||
|
||
on: | ||
push: | ||
branches: ["main"] | ||
workflow_dispatch: | ||
|
||
permissions: | ||
contents: read | ||
pages: write | ||
id-token: write | ||
|
||
concurrency: | ||
group: "pages" | ||
cancel-in-progress: false | ||
|
||
jobs: | ||
deploy: | ||
environment: | ||
name: github-pages | ||
url: ${{ steps.deployment.outputs.page_url }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup Node.js v20.x | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: '20.x' | ||
|
||
- name: Install | ||
run: yarn install | ||
working-directory: client-website/ | ||
|
||
- name: Build | ||
run: yarn build | ||
working-directory: client-website/ | ||
|
||
- name: Setup Pages | ||
uses: actions/configure-pages@v3 | ||
|
||
- name: Upload artifact | ||
uses: actions/upload-pages-artifact@v1 | ||
with: | ||
path: 'client-website/dist' | ||
|
||
- name: Deploy to GitHub Pages | ||
id: deployment | ||
uses: actions/deploy-pages@v2 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# 中山大學選課助手 React 版 | ||
# 中山大學選課助手 React TypeScript 版 | ||
## 進入網頁 | ||
https://CelleryLin.github.io/selector_helper/ | ||
|
||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
node_modules | ||
dist | ||
dist-ssr | ||
*.local | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
!.vscode/extensions.json | ||
.idea | ||
.DS_Store | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# React + TypeScript + Vite | ||
|
||
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. | ||
|
||
Currently, two official plugins are available: | ||
|
||
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh | ||
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh | ||
|
||
## Expanding the ESLint configuration | ||
|
||
If you are developing a production application, we recommend updating the configuration to enable type aware lint rules: | ||
|
||
- Configure the top-level `parserOptions` property like this: | ||
|
||
```js | ||
export default tseslint.config({ | ||
languageOptions: { | ||
// other options... | ||
parserOptions: { | ||
project: ['./tsconfig.node.json', './tsconfig.app.json'], | ||
tsconfigRootDir: import.meta.dirname, | ||
}, | ||
}, | ||
}) | ||
``` | ||
|
||
- Replace `tseslint.configs.recommended` to `tseslint.configs.recommendedTypeChecked` or `tseslint.configs.strictTypeChecked` | ||
- Optionally add `...tseslint.configs.stylisticTypeChecked` | ||
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and update the config: | ||
|
||
```js | ||
// eslint.config.js | ||
import react from 'eslint-plugin-react' | ||
|
||
export default tseslint.config({ | ||
// Set the react version | ||
settings: { react: { version: '18.3' } }, | ||
plugins: { | ||
// Add the react plugin | ||
react, | ||
}, | ||
rules: { | ||
// other rules... | ||
// Enable its recommended rules | ||
...react.configs.recommended.rules, | ||
...react.configs['jsx-runtime'].rules, | ||
}, | ||
}) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import js from '@eslint/js'; | ||
import globals from 'globals'; | ||
import reactHooks from 'eslint-plugin-react-hooks'; | ||
import reactRefresh from 'eslint-plugin-react-refresh'; | ||
import tseslint from 'typescript-eslint'; | ||
|
||
export default tseslint.config( | ||
{ ignores: ['dist'] }, | ||
{ | ||
extends: [js.configs.recommended, ...tseslint.configs.recommended], | ||
files: ['**/*.{ts,tsx}'], | ||
languageOptions: { | ||
ecmaVersion: 2021, | ||
globals: globals.browser, | ||
}, | ||
plugins: { | ||
'react-hooks': reactHooks, | ||
'react-refresh': reactRefresh, | ||
}, | ||
rules: { | ||
...reactHooks.configs.recommended.rules, | ||
'react-refresh/only-export-components': [ | ||
'warn', | ||
{ allowConstantExport: true }, | ||
], | ||
}, | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"/> | ||
<link rel="icon" type="image/svg+xml" href="/logo.svg"/> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"/> | ||
<meta name="theme-color" content="#000000"/> | ||
<meta | ||
name="description" | ||
content="中山選課助手,幫助你快速查詢國立中山大學的課程資訊。" | ||
/> | ||
<meta | ||
name="keywords" | ||
content="中山大學, 選課, 課程, 課程查詢, 課程表, 課程時間表, 選課助手, 助手" | ||
/> | ||
|
||
<!-- Open Graph / Facebook --> | ||
<meta property="og:type" content="website"/> | ||
<meta | ||
property="og:url" | ||
content="https://whats2000.github.io/CourseSelectorHelperReact/" | ||
/> | ||
<meta property="og:title" content="中山選課助手"/> | ||
<meta | ||
property="og:description" | ||
content="中山選課助手,幫助你快速查詢國立中山大學的課程資訊。" | ||
/> | ||
<meta | ||
property="og:image" | ||
content="https://whats2000.github.io/CourseSelectorHelperReact/logo.svg" | ||
/> | ||
|
||
<!-- Twitter --> | ||
<meta property="twitter:card" content="summary_large_image"/> | ||
<meta | ||
property="twitter:url" | ||
content="https://whats2000.github.io/CourseSelectorHelperReact/" | ||
/> | ||
<meta property="twitter:title" content="中山選課助手"/> | ||
<meta | ||
property="twitter:description" | ||
content="中山選課助手,幫助你快速查詢國立中山大學的課程資訊。" | ||
/> | ||
<meta | ||
property="twitter:image" | ||
content="https://whats2000.github.io/CourseSelectorHelperReact/logo.svg" | ||
/> | ||
<meta charset="UTF-8"/> | ||
|
||
<link rel="apple-touch-icon" href="/logo.svg"/> | ||
<!-- | ||
manifest.json provides metadata used when your web app is installed on a | ||
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/ | ||
--> | ||
<link rel="manifest" href="/manifest.json"/> | ||
<!-- | ||
Notice the use of %PUBLIC_URL% in the tags above. | ||
It will be replaced with the URL of the `public` folder during the build. | ||
Only files inside the `public` folder can be referenced from the HTML. | ||
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will | ||
work correctly both with client-side routing and a non-root public URL. | ||
Learn how to configure a non-root public URL by running `npm run build`. | ||
--> | ||
|
||
<style> | ||
/* 加載動畫的CSS樣式 */ | ||
#loading { | ||
position: fixed; | ||
top: 0; | ||
left: 0; | ||
right: 0; | ||
bottom: 0; | ||
background-color: rgba(255, 255, 255, 0.8); | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
flex-direction: column; | ||
z-index: 1000; | ||
} | ||
|
||
.spinner { | ||
border: 5px solid rgba(0, 0, 0, 0.1); | ||
border-top: 5px solid #333; | ||
border-radius: 50%; | ||
width: 50px; | ||
height: 50px; | ||
animation: spin 2s linear infinite; | ||
} | ||
|
||
@keyframes spin { | ||
0% { | ||
transform: rotate(0deg); | ||
} | ||
100% { | ||
transform: rotate(360deg); | ||
} | ||
} | ||
|
||
.loading-text { | ||
margin-top: 20px; | ||
font-size: 18px; | ||
color: #333; | ||
text-align: center; | ||
max-width: 90%; | ||
} | ||
</style> | ||
<title>中山選課助手</title> | ||
</head> | ||
<body> | ||
<noscript>You need to enable JavaScript to run this app.</noscript> | ||
<div id="loading"> | ||
<div class="spinner"></div> | ||
<div class="loading-text">正在加載網頁...</div> | ||
<div class="loading-text">如持續加載超過10秒,請嘗試重新整理頁面。</div> | ||
</div> | ||
<div id="root"></div> | ||
<script type="module" src="/src/main.tsx"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{ | ||
"name": "client-website", | ||
"private": true, | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "tsc -b && vite build", | ||
"lint": "eslint .", | ||
"preview": "vite preview" | ||
}, | ||
"dependencies": { | ||
"@dnd-kit/core": "^6.1.0", | ||
"@dnd-kit/sortable": "^8.0.0", | ||
"@dnd-kit/utilities": "^3.2.2", | ||
"@swc/plugin-styled-components": "^5.0.0", | ||
"bootstrap": "^5.3.3", | ||
"gh-pages": "^6.2.0", | ||
"papaparse": "^5.4.1", | ||
"react": "^18.3.1", | ||
"react-bootstrap": "^2.10.5", | ||
"react-bootstrap-icons": "^1.11.4", | ||
"react-copy-to-clipboard": "^5.1.0", | ||
"react-dom": "^18.3.1", | ||
"react-ga4": "^2.1.0", | ||
"react-lazy-load-image-component": "^1.6.2", | ||
"react-syntax-highlighter": "^15.6.1", | ||
"react-virtuoso": "^4.12.0", | ||
"styled-components": "^6.1.13" | ||
}, | ||
"devDependencies": { | ||
"@eslint/js": "^9.13.0", | ||
"@types/papaparse": "^5.3.15", | ||
"@types/react": "^18.3.12", | ||
"@types/react-copy-to-clipboard": "^5.0.7", | ||
"@types/react-dom": "^18.3.1", | ||
"@types/react-lazy-load-image-component": "^1.6.4", | ||
"@types/react-syntax-highlighter": "^15.5.13", | ||
"@vitejs/plugin-react-swc": "^3.5.0", | ||
"eslint": "^9.13.0", | ||
"eslint-plugin-react-hooks": "^5.0.0", | ||
"eslint-plugin-react-refresh": "^0.4.14", | ||
"globals": "^15.11.0", | ||
"prettier": "^3.3.3", | ||
"typescript": "~5.6.2", | ||
"typescript-eslint": "^8.11.0", | ||
"vite": "^5.4.10" | ||
} | ||
} |
File renamed without changes
File renamed without changes.
File renamed without changes.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { AcademicYear, NSYSUCourse, SemesterUpdate } from '@/types'; | ||
|
||
const BASE_URL = 'https://whats2000.github.io/NSYSUCourseAPI'; | ||
|
||
export class NSYSUCourseAPI { | ||
/** | ||
* 取得所有可用學期列表 | ||
*/ | ||
static async getAvailableSemesters(): Promise<AcademicYear> { | ||
const response = await fetch(`${BASE_URL}/version.json`); | ||
if (!response.ok) { | ||
throw new Error('Failed to fetch available semesters'); | ||
} | ||
return response.json(); | ||
} | ||
|
||
/** | ||
* 取得指定學年度的學期更新資訊 | ||
* @param academicYear - 學年度 | ||
*/ | ||
static async getSemesterUpdates( | ||
academicYear: string, | ||
): Promise<SemesterUpdate> { | ||
const response = await fetch(`${BASE_URL}/${academicYear}/version.json`); | ||
if (!response.ok) { | ||
throw new Error('Failed to fetch semester updates'); | ||
} | ||
return response.json(); | ||
} | ||
|
||
/** | ||
* 取得指定學年度、更新時間的所有課程 | ||
* @param academicYear - 學年度 | ||
* @param updateTime - 更新時間 | ||
*/ | ||
static async getCourses( | ||
academicYear: string, | ||
updateTime: string, | ||
): Promise<NSYSUCourse[]> { | ||
const response = await fetch( | ||
`${BASE_URL}/${academicYear}/${updateTime}/all.json`, | ||
); | ||
if (!response.ok) { | ||
throw new Error('Failed to fetch courses'); | ||
} | ||
|
||
return response.json().then((courses: NSYSUCourse[]) => { | ||
return Array.from(new Set(courses.map((course) => course.id))).map( | ||
(id) => courses.find((course) => course.id === id)!, | ||
); | ||
}); | ||
} | ||
|
||
/** | ||
* 取得最新學期的所有課程 | ||
*/ | ||
static async getLatestCourses(): Promise<NSYSUCourse[]> { | ||
const semesters = await NSYSUCourseAPI.getAvailableSemesters(); | ||
const latestAcademicYear = semesters.latest; | ||
const updates = await NSYSUCourseAPI.getSemesterUpdates(latestAcademicYear); | ||
const latestUpdateTime = updates.latest; | ||
return NSYSUCourseAPI.getCourses(latestAcademicYear, latestUpdateTime); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import { Course, CourseDataFilesInfo } from '@/types'; | ||
import Papa from 'papaparse'; | ||
|
||
const BASE_URL = | ||
'https://api.github.com/repos/CelleryLin/selector_helper_old/contents/all_classes'; | ||
|
||
export class NSYSUCourseAPIOld { | ||
/** | ||
* 解析 CSV 內容並返回去重的課程資料 | ||
* @param csvText CSV 文字 | ||
*/ | ||
private static parseCourseData(csvText: string): Course[] { | ||
const results = Papa.parse<Course>(csvText, { | ||
header: true, | ||
skipEmptyLines: true, | ||
}); | ||
return results.data.filter( | ||
(course, index, self) => | ||
index === | ||
self.findIndex( | ||
(c) => | ||
c['Name'] === course['Name'] && | ||
c['Number'] === course['Number'] && | ||
c['Teacher'] === course['Teacher'], | ||
), | ||
); | ||
} | ||
|
||
/** | ||
* 取得所有可用課程資料檔案 | ||
*/ | ||
static async getAvailableSemesters(): Promise<CourseDataFilesInfo[]> { | ||
try { | ||
const response = await fetch(BASE_URL); | ||
if (!response.ok) { | ||
console.error('Failed to fetch available course data files'); | ||
return []; | ||
} | ||
const files = await response.json(); | ||
if (!Array.isArray(files)) { | ||
console.error('Invalid course data files, it should be an array'); | ||
return []; | ||
} | ||
|
||
if (files.length === 0) { | ||
console.error('No course data files found'); | ||
return []; | ||
} | ||
|
||
const groupedFiles = files | ||
.filter((file) => file.name.endsWith('.csv')) | ||
.reduce( | ||
( | ||
acc: { | ||
[key: string]: CourseDataFilesInfo[]; | ||
}, | ||
file, | ||
) => { | ||
const match = file.name.match(/all_classes_(\d{3})([123])_/); | ||
if (!match) return acc; | ||
|
||
const key = `${match[1]}-${match[2]}`; // Group key: academicYear-semester | ||
if (!acc[key]) { | ||
acc[key] = []; | ||
} | ||
acc[key].push(file); | ||
|
||
return acc; | ||
}, | ||
{}, | ||
); | ||
|
||
// Select the latest file for each academic year and semester | ||
return Object.values(groupedFiles).map((group) => { | ||
return group.sort((a, b) => b.name.localeCompare(a.name))[0]; | ||
}); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
|
||
return []; | ||
} | ||
|
||
/** | ||
* 下載指定課程資料檔案 | ||
* @param version 課程資料檔案資訊 | ||
*/ | ||
static async getSemesterUpdates( | ||
version: CourseDataFilesInfo, | ||
): Promise<Course[]> { | ||
try { | ||
const response = await fetch(version.download_url); | ||
if (!response.ok) { | ||
console.error('Failed to fetch course data file'); | ||
return []; | ||
} | ||
const csvText = await response.text(); | ||
|
||
if (!csvText) { | ||
console.error('Empty course data file'); | ||
return []; | ||
} | ||
|
||
return this.parseCourseData(csvText); | ||
} catch (error) { | ||
console.error(error); | ||
return []; | ||
} | ||
} | ||
} |
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...etting/AllCourse/AllCourseList/Header.jsx → ...etting/AllCourse/AllCourseList/Header.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 13 additions & 2 deletions
15
.../ListInformation/ClearSelectedCourses.jsx → .../ListInformation/ClearSelectedCourses.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.