├── .eslintrc.json ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md └── workflows │ ├── codeql-analysis.yml │ ├── ncn-frontend-v2-dev.yml │ └── ncn-frontend-v2.yml ├── .gitignore ├── .husky └── pre-commit ├── .prettierrc ├── @types └── react-table-drag-select │ └── index.d.ts ├── LICENSE ├── README.md ├── cypress.config.js ├── cypress.env.defaults.json ├── cypress ├── .eslintrc.json ├── README.md ├── e2e │ └── e2e │ │ ├── course.js │ │ └── e2e_home.js ├── plugins │ └── index.js └── support │ ├── commands.js │ └── e2e.js ├── next-env.d.ts ├── next.config.js ├── package.json ├── public ├── apple-touch-icon.png ├── favicon.ico ├── img │ ├── home_cards │ │ ├── course_table.svg │ │ ├── dashboard.svg │ │ ├── search.svg │ │ ├── selection.svg │ │ └── sync.svg │ ├── home_footer.svg │ ├── home_main.svg │ ├── ncn_logo.png │ ├── not_found.svg │ ├── parrot │ │ ├── parrot.gif │ │ └── ultrafastparrot.gif │ └── team_avatar │ │ ├── jc-hiroto.png │ │ ├── swh00tw.png │ │ └── wil0408.png ├── manifest.json ├── og.png └── vercel.svg ├── src ├── components │ ├── BetaBadge.tsx │ ├── CourseInfo │ │ ├── CourseDetailInfoContainer.tsx │ │ ├── PTTContentRowContainer.tsx │ │ ├── Panel.tsx │ │ ├── SignUpCard.tsx │ │ └── SignUpSubmitForm.tsx │ ├── CourseInfoRow.tsx │ ├── CourseInfoRowContainer.tsx │ ├── CourseSearchInput.tsx │ ├── CourseTable │ │ ├── CourseListContainer.tsx │ │ ├── CourseTableCard │ │ │ ├── CourseTableCard.tsx │ │ │ └── SortablePopover.tsx │ │ ├── CourseTableContainer.tsx │ │ └── SideCourseTableContainer.tsx │ ├── CustomIcons.tsx │ ├── DeadlineCountdown.tsx │ ├── FilterModals │ │ ├── CategoryFilterModal.tsx │ │ ├── DeptFilterModal.tsx │ │ ├── TimeFilterModal.tsx │ │ └── components │ │ │ ├── FilterElement.tsx │ │ │ └── TimetableSelector.tsx │ ├── Footer.tsx │ ├── GoogleAnalytics.tsx │ ├── HeaderBar.tsx │ ├── HomeCard.tsx │ ├── Providers │ │ ├── CourseSearchingProvider.tsx │ │ └── DisplayTagsProvider.tsx │ ├── SkeletonRow.tsx │ └── ThemeToggleButton.tsx ├── constant.ts ├── data │ ├── college.ts │ ├── course_select_schedule.ts │ ├── course_type.ts │ ├── department.ts │ └── mapping_table.ts ├── hooks │ ├── useCourseInfo.ts │ ├── useCourseTable.ts │ ├── useNeoLocalStorage.ts │ ├── usePagination.ts │ ├── useSearchResult.ts │ └── useUserInfo.ts ├── pages │ ├── 404.tsx │ ├── _app.tsx │ ├── _document.tsx │ ├── about.tsx │ ├── api │ │ ├── auth │ │ │ └── [...auth0].ts │ │ ├── course │ │ │ ├── enrollInfo.ts │ │ │ ├── ntuRating.ts │ │ │ └── ptt.ts │ │ ├── social │ │ │ ├── createPost.ts │ │ │ ├── deletePost.ts │ │ │ ├── getByCourseId.ts │ │ │ ├── reportPost.ts │ │ │ └── votePost.ts │ │ └── user │ │ │ ├── addFavoriteCourse.ts │ │ │ ├── deleteAccount.ts │ │ │ ├── deleteProfile.ts │ │ │ ├── index.ts │ │ │ ├── linkCourseTable.ts │ │ │ ├── patch.ts │ │ │ ├── register.ts │ │ │ └── removeFavoriteCourse.ts │ ├── course.tsx │ ├── courseinfo │ │ └── [courseId].tsx │ ├── index.tsx │ └── user │ │ ├── info.tsx │ │ └── my.tsx ├── queries │ ├── axiosInstance.ts │ ├── course.ts │ ├── courseTable.ts │ ├── sendLogs.ts │ ├── social.ts │ └── user.ts ├── styles │ ├── nprogress.css │ └── theme.ts ├── types │ ├── course.ts │ ├── courseTable.ts │ ├── search.ts │ └── user.ts └── utils │ ├── CustomFetch.ts │ ├── assert.ts │ ├── cipher.ts │ ├── colorAgent.ts │ ├── ga.ts │ ├── getNolUrls.ts │ ├── hoverCourse.ts │ ├── openPage.ts │ ├── parseCourseSchedule.ts │ ├── parseCourseTime.ts │ └── timeTableConverter.ts ├── tsconfig.json └── yarn.lock /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | "extends": [ 4 | "next/core-web-vitals", 5 | "plugin:prettier/recommended", 6 | "prettier", 7 | "plugin:react-hooks/recommended", 8 | "eslint:recommended", 9 | "plugin:react/recommended", 10 | "plugin:@typescript-eslint/recommended" 11 | ], 12 | "overrides": [ 13 | { 14 | "files": ["*.js", "*.jsx", "*.ts", "*.tsx"], 15 | "extends": [ 16 | "next/core-web-vitals", 17 | "plugin:@typescript-eslint/recommended" 18 | ], 19 | "plugins": [ 20 | "prettier", 21 | "react", 22 | "react-hooks", 23 | "unused-imports", 24 | "@typescript-eslint" 25 | ], 26 | "settings": { 27 | "react": { 28 | "version": "detect" 29 | } 30 | }, 31 | "rules": { 32 | "no-restricted-imports": [ 33 | "error", 34 | { 35 | "patterns": [ 36 | { 37 | "group": [".*"], 38 | "message": "please use absolute import path instead." 39 | } 40 | ] 41 | } 42 | ], 43 | "react-hooks/rules-of-hooks": "error", 44 | "react-hooks/exhaustive-deps": "error", 45 | "react/prop-types": "off", 46 | "react/react-in-jsx-scope": "off", 47 | "react/no-unescaped-entities": "off", 48 | "no-unused-vars": "off", 49 | "unused-imports/no-unused-imports": "error", 50 | "prefer-const": "error", 51 | "react/no-unstable-nested-components": "warn", 52 | "@typescript-eslint/no-unused-vars": "off", 53 | "@typescript-eslint/no-empty-function": "off" 54 | } 55 | } 56 | ], 57 | "ignorePatterns": ["cypress/*"] 58 | } 59 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: feature request 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | name: "CodeQL Check" 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | # The branches below must be a subset of the branches above 8 | branches: [ master ] 9 | schedule: 10 | - cron: '45 11 * * 6' 11 | 12 | jobs: 13 | analyze: 14 | name: Analyze 15 | runs-on: ubuntu-latest 16 | permissions: 17 | actions: read 18 | contents: read 19 | security-events: write 20 | 21 | strategy: 22 | fail-fast: false 23 | matrix: 24 | language: [ 'javascript' ] 25 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] 26 | # Learn more about CodeQL language support at https://git.io/codeql-language-support 27 | 28 | steps: 29 | - name: Checkout repository 30 | uses: actions/checkout@v2 31 | 32 | # Initializes the CodeQL tools for scanning. 33 | - name: Initialize CodeQL 34 | uses: github/codeql-action/init@v1 35 | with: 36 | languages: ${{ matrix.language }} 37 | # If you wish to specify custom queries, you can do so here or in a config file. 38 | # By default, queries listed here will override any specified in a config file. 39 | # Prefix the list here with "+" to use these queries and those in the config file. 40 | # queries: ./path/to/local/query, your-org/your-repo/queries@main 41 | 42 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 43 | # If this step fails, then you should remove it and run the build manually (see below) 44 | - name: Autobuild 45 | uses: github/codeql-action/autobuild@v1 46 | 47 | # ℹ️ Command-line programs to run using the OS shell. 48 | # 📚 https://git.io/JvXDl 49 | 50 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines 51 | # and modify them (or add more) to build your code if your project 52 | # uses a compiled language 53 | 54 | #- run: | 55 | # make bootstrap 56 | # make release 57 | 58 | - name: Perform CodeQL Analysis 59 | uses: github/codeql-action/analyze@v1 60 | -------------------------------------------------------------------------------- /.github/workflows/ncn-frontend-v2-dev.yml: -------------------------------------------------------------------------------- 1 | # Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy 2 | # More GitHub Actions for Azure: https://github.com/Azure/actions 3 | # For staging environment 4 | 5 | name: Azure Web App deploy - ncn-frontend-v2-dev 6 | 7 | on: 8 | pull_request: 9 | types: [opened, synchronize, reopened] 10 | branches: 11 | - master 12 | 13 | env: 14 | NEXT_PUBLIC_API_ENDPOINT: ${{ secrets.AZURE_API_ENDPOINT }} 15 | NEXT_PUBLIC_ENV: "dev" 16 | NEXT_PUBLIC_BASE_URL: "https://ncn-frontend-v2-dev.azurewebsites.net" 17 | NEXT_PUBLIC_GA_ID: ${{ secrets.GA_TRACKING_ID }} 18 | NEXT_PUBLIC_SEMESTER: "1111" 19 | NEXT_PUBLIC_COURSE_TABLE_SECRET: ${{ secrets.COURSE_TABLE_SECRET }} 20 | AUTH0_SELF_API_AUDIENCE: ${{ secrets.SELF_API_AUDIENCE }} 21 | AUTH0_SECRET: ${{ secrets.AUTH0_SECRET_V2 }} 22 | AUTH0_BASE_URL: ${{ secrets.AUTH0_BASE_URL_V2_DEV }} 23 | AUTH0_ISSUER_BASE_URL: ${{ secrets.AUTH0_ISSUER_BASE_URL_V2 }} 24 | AUTH0_CLIENT_ID: ${{ secrets.AUTH0_CLIENT_ID_V2 }} 25 | AUTH0_CLIENT_SECRET: ${{ secrets.AUTH0_CLIENT_SECRET_V2 }} 26 | 27 | jobs: 28 | build: 29 | if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed') 30 | runs-on: ubuntu-latest 31 | 32 | steps: 33 | - uses: actions/checkout@v2 34 | 35 | - name: Set up Node.js version 36 | uses: actions/setup-node@v1 37 | with: 38 | node-version: "16.x" 39 | 40 | - name: Enable NextJS caching 41 | id: enable-cache 42 | uses: actions/cache@v2 43 | with: 44 | path: | 45 | ~/.npm 46 | ${{ github.workspace}}/.next/cache 47 | key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }} 48 | restore-keys: | 49 | ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}- 50 | 51 | - name: zip artifact for deployment 52 | run: zip -r --symlinks rel.zip * 53 | 54 | - name: Upload artifact for deployment job 55 | uses: actions/upload-artifact@v2 56 | with: 57 | name: node-app 58 | path: rel.zip 59 | 60 | deploy: 61 | if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed') 62 | runs-on: ubuntu-latest 63 | needs: build 64 | environment: 65 | name: "Production" 66 | url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} 67 | 68 | steps: 69 | - name: Download artifact from build job 70 | uses: actions/download-artifact@v2 71 | with: 72 | name: node-app 73 | 74 | - name: unzip artifact for deployment 75 | run: unzip rel.zip 76 | 77 | - name: yarn install, build, and test 78 | run: | 79 | yarn 80 | yarn build 81 | 82 | - name: "Deploy to Azure Web App" 83 | id: deploy-to-webapp 84 | uses: azure/webapps-deploy@v2 85 | with: 86 | app-name: "ncn-frontend-v2-dev" 87 | slot-name: "Production" 88 | publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_EEEE4CF99BDD4E84809AEE36522214C4 }} 89 | package: . 90 | -------------------------------------------------------------------------------- /.github/workflows/ncn-frontend-v2.yml: -------------------------------------------------------------------------------- 1 | # Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy 2 | # More GitHub Actions for Azure: https://github.com/Azure/actions 3 | # For production environment 4 | 5 | name: Azure Web App deploy - ncn-frontend-v2 6 | 7 | on: 8 | push: 9 | branches: 10 | - master 11 | workflow_dispatch: 12 | 13 | env: 14 | NEXT_PUBLIC_API_ENDPOINT: ${{ secrets.AZURE_API_ENDPOINT }} 15 | NEXT_PUBLIC_ENV: "prod" 16 | NEXT_PUBLIC_BASE_URL: "https://course.myntu.me" 17 | NEXT_PUBLIC_GA_ID: ${{ secrets.GA_TRACKING_ID }} 18 | NEXT_PUBLIC_SEMESTER: "1111" 19 | NEXT_PUBLIC_COURSE_TABLE_SECRET: ${{ secrets.COURSE_TABLE_SECRET }} 20 | AUTH0_SELF_API_AUDIENCE: ${{ secrets.SELF_API_AUDIENCE }} 21 | AUTH0_SECRET: ${{ secrets.AUTH0_SECRET_V2 }} 22 | AUTH0_BASE_URL: ${{ secrets.AUTH0_BASE_URL_V2 }} 23 | AUTH0_ISSUER_BASE_URL: ${{ secrets.AUTH0_ISSUER_BASE_URL_V2 }} 24 | AUTH0_CLIENT_ID: ${{ secrets.AUTH0_CLIENT_ID_V2 }} 25 | AUTH0_CLIENT_SECRET: ${{ secrets.AUTH0_CLIENT_SECRET_V2 }} 26 | 27 | jobs: 28 | build: 29 | runs-on: ubuntu-latest 30 | 31 | steps: 32 | - uses: actions/checkout@v2 33 | 34 | - name: Set up Node.js version 35 | uses: actions/setup-node@v1 36 | with: 37 | node-version: "16.x" 38 | 39 | - name: Enable NextJS caching 40 | id: enable-cache 41 | uses: actions/cache@v2 42 | with: 43 | path: | 44 | ~/.npm 45 | ${{ github.workspace}}/.next/cache 46 | key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }} 47 | restore-keys: | 48 | ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}- 49 | 50 | - name: zip artifact for deployment 51 | run: zip -r --symlinks rel.zip * 52 | 53 | - name: Upload artifact for deployment job 54 | uses: actions/upload-artifact@v2 55 | with: 56 | name: node-app 57 | path: rel.zip 58 | 59 | deploy: 60 | runs-on: ubuntu-latest 61 | needs: build 62 | environment: 63 | name: "Production" 64 | url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} 65 | 66 | steps: 67 | - name: Download artifact from build job 68 | uses: actions/download-artifact@v2 69 | with: 70 | name: node-app 71 | 72 | - name: unzip artifact for deployment 73 | run: unzip rel.zip 74 | 75 | - name: yarn install, build, and test 76 | run: | 77 | yarn 78 | yarn build 79 | 80 | - name: "Deploy to Azure Web App" 81 | id: deploy-to-webapp 82 | uses: azure/webapps-deploy@v2 83 | with: 84 | app-name: "ncn-frontend-v2" 85 | slot-name: "Production" 86 | publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_BE2056ABFC0947EFBA90F021F0F890C4 }} 87 | package: . 88 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # test.http 12 | test.http 13 | 14 | # next.js 15 | /.next/ 16 | /out/ 17 | .next/ 18 | 19 | # production 20 | /build 21 | 22 | # misc 23 | .DS_Store 24 | *.pem 25 | 26 | # debug 27 | npm-debug.log* 28 | yarn-debug.log* 29 | yarn-error.log* 30 | .pnpm-debug.log* 31 | 32 | # local env files 33 | .env*.local 34 | 35 | # vercel 36 | .vercel 37 | 38 | # eslint 39 | .eslintcache 40 | 41 | # cypress 42 | cypress.env.json 43 | cypress/videos/ 44 | cypress/screenshots/ 45 | 46 | # typescript 47 | tsconfig.tsbuildinfo 48 | -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | . "$(dirname -- "$0")/_/husky.sh" 3 | 4 | npx lint-staged 5 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "arrowParens": "always", 3 | "trailingComma": "es5", 4 | "singleQuote": false, 5 | "semi": true, 6 | "tabWidth": 2, 7 | "useTabs": false, 8 | "printWidth": 80 9 | } 10 | -------------------------------------------------------------------------------- /@types/react-table-drag-select/index.d.ts: -------------------------------------------------------------------------------- 1 | declare module "react-table-drag-select"; 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 NTUCourse-Neo 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ncn-frontend 2 | 3 | The frontend of NTUCourse Neo. 4 | 5 | [![GitHub branches](https://badgen.net/github/branches/NTUCourse-Neo/ncn-frontend)](https://github.com/NTUCourse-Neo/ncn-backend) 6 | [![GitHub branches](https://badgen.net/github/merged-prs/NTUCourse-Neo/ncn-frontend)](https://github.com/NTUCourse-Neo/ncn-backend) 7 | [![GitHub branches](https://badgen.net/github/commits/NTUCourse-Neo/ncn-frontend)](https://github.com/NTUCourse-Neo/ncn-backend) 8 | [![GitHub branches](https://badgen.net/github/last-commit/NTUCourse-Neo/ncn-frontend)](https://github.com/NTUCourse-Neo/ncn-backend) 9 | 10 | [![GitHub branches](https://github.com/NTUCourse-Neo/ncn-frontend/actions/workflows/azure-static-web-apps-gray-river-017c6bf1e.yml/badge.svg)](https://github.com/NTUCourse-Neo/ncn-frontend/actions/workflows/azure-static-web-apps-gray-river-017c6bf1e.yml) 11 | [![Better Uptime Badge](https://betteruptime.com/status-badges/v1/monitor/bqbv.svg)](https://betteruptime.com/?utm_source=status_badge) 12 | 13 | ## 🛠 Deployment 14 | 15 | ### 🐋 Docker (Recommended) 16 | 17 | 1. Clone the repository 18 | ```bash 19 | git clone https://github.com/NTUCourse-Neo/ncn-frontend.git 20 | cd ncn-frontend 21 | ``` 22 | 2. Prepare your `.env` file 23 | 24 | Run command below to create a `.env` file 25 | 26 | ```bash 27 | cp .env.defaults .env 28 | ``` 29 | 30 | Then paste your keys into the file. Please refer to the table below. 31 | _Reminder: Make sure you follow the [environment variable file format](https://docs.docker.com/engine/reference/commandline/run/#set-environment-variables--e---env---env-file) of Docker._ 32 | | KEY | Description | Default Value | 33 | | ------------------------------ | ------------------------------------------------- | -------------------------- | 34 | | REACT_APP_API_ENDPOINT | Backend API Endpoint URL | http://localhost:5000/api/ | 35 | | REACT_APP_API_VERSION | Backend API Endpoint Version | v1 | 36 | | REACT_APP_AUTH0_DOMAIN | Auth0 Domain | N/A | 37 | | REACT_APP_AUTH0_CLIENT_ID | Auth0 Single Page Application Client ID | N/A | 38 | | REACT_APP_SELF_API_AUDIENCE | NTUCourse-Neo API Identifier | N/A | 39 | | REACT_APP_RECAPTCHA_CLIENT_KEY | reCAPTCHA Service Client Key | N/A | 40 | | REACT_APP_GA_TRACKING_ID | Google Analytics Tracking ID (Started with `UA-`) | N/A | 41 | 42 | 3. Install Docker on your device. 43 | 44 | Please refer to this [guide](https://docs.docker.com/engine/install/). 45 | 46 | 4. Build docker image 47 | 48 | ```bash 49 | docker build -f Dockerfile -t ncn-frontend . 50 | ``` 51 | 52 | 5. Run the built image in container 53 | 54 | ```bash 55 | docker run --env-file .env -p 3000:3000 ncn-frontend 56 | ``` 57 | 58 | 6. Open the browser and go to http://localhost:3000/ 59 | and you should see the website running. 60 | 7. Have fun! 🎉 61 | 62 | ### 💻 Run in local 63 | 64 | 1. Clone the repository 65 | ```bash 66 | git clone https://github.com/NTUCourse-Neo/ncn-frontend.git 67 | cd ncn-frontend 68 | ``` 69 | 2. Prepare your `.env` file 70 | 71 | Run command below to create a `.env` file 72 | 73 | ```bash 74 | cp .env.defaults .env 75 | ``` 76 | 77 | Then paste your keys into the file. Please refer to the table below. 78 | 79 | | KEY | Description | Default Value | 80 | | ------------------------------ | ------------------------------------------------- | -------------------------- | 81 | | REACT_APP_API_ENDPOINT | Backend API Endpoint URL | http://localhost:5000/api/ | 82 | | REACT_APP_API_VERSION | Backend API Endpoint Version | v1 | 83 | | REACT_APP_AUTH0_DOMAIN | Auth0 Domain | | 84 | | REACT_APP_AUTH0_CLIENT_ID | Auth0 Single Page Application Client ID | | 85 | | REACT_APP_SELF_API_AUDIENCE | NTUCourse-Neo API Identifier | | 86 | | REACT_APP_RECAPTCHA_CLIENT_KEY | reCAPTCHA Service Client Key | | 87 | | REACT_APP_GA_TRACKING_ID | Google Analytics Tracking ID (Started with `UA-`) | | 88 | 89 | 3. Install required dependencies 90 | 91 | ```bash 92 | yarn 93 | ``` 94 | 95 | 4. Run the server 96 | ```bash 97 | yarn start 98 | ``` 99 | 5. Open the browser and go to http://localhost:3000/ 100 | 101 | and you should see the website running. 102 | 103 | 6. Have fun! 🎉 104 | 105 | ## 📦 Packages 106 | 107 | - babel 108 | - dotenv-defaults 109 | - chakra-ui/react 110 | - react-icons 111 | - react-router-dom 112 | - Redux 113 | - axios 114 | - react-ga 115 | - array-move 116 | - react-sortable-hoc 117 | - auth0-react 118 | - react-spinners 119 | - react-table-drag-select 120 | - react-scroll 121 | - react-focus-lock 122 | - react-google-recaptcha 123 | - react-countdown-hook 124 | - color-hash 125 | - randomcolor 126 | -------------------------------------------------------------------------------- /cypress.config.js: -------------------------------------------------------------------------------- 1 | const { defineConfig } = require("cypress"); 2 | 3 | module.exports = defineConfig({ 4 | viewportWidth: 1500, 5 | viewportHeight: 900, 6 | projectId: "79x2jm", 7 | env: { 8 | API_ENDPOINT: "", 9 | }, 10 | e2e: { 11 | // We've imported your old cypress plugins here. 12 | // You may want to clean this up later by importing these. 13 | setupNodeEvents(on, config) { 14 | return require("./cypress/plugins/index.js")(on, config); 15 | }, 16 | baseUrl: "http://localhost:3000/", 17 | specPattern: "cypress/e2e/**/*.{js,jsx,ts,tsx}", 18 | }, 19 | }); 20 | -------------------------------------------------------------------------------- /cypress.env.defaults.json: -------------------------------------------------------------------------------- 1 | { 2 | "API_ENDPOINT": "" 3 | } 4 | -------------------------------------------------------------------------------- /cypress/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "plugin:cypress/recommended" 4 | ] 5 | } -------------------------------------------------------------------------------- /cypress/README.md: -------------------------------------------------------------------------------- 1 | ## Local env setup 2 | create `cypress.env.json` in the root directory. 3 | 4 | copy and paste the .env file inside and change to `json` format. 5 | 6 | ## Open Cypress GUI 7 | ``` 8 | npx cypress open 9 | ``` 10 | 11 | ## Modify cypress secret 12 | > https://docs.cypress.io/guides/guides/environment-variables#Option-1-configuration-file 13 | > 14 | > We use option #2 in the article 15 | 16 | If you want to modify env variables for cypress testing, first, modify `cypress.json` and add key value pair in env field. (you can leave it as empty string if you want to specify value in `cypress.env.json`) 17 | 18 | Then, modify your `cypress.env.json` 19 | 20 | At last, remember to update `cypress-e2e.yml` and corresponding github secrets. 21 | -------------------------------------------------------------------------------- /cypress/e2e/e2e/course.js: -------------------------------------------------------------------------------- 1 | describe("Course related functionalties test", () => { 2 | it("Navigate to /course page", () => { 3 | cy.visit("/"); 4 | cy.get("button").contains("開始使用").click(); 5 | cy.url().should("include", "/course"); 6 | }); 7 | it("Search without typing anything", () => { 8 | cy.intercept("POST", `${Cypress.env("API_ENDPOINT")}/v2/courses/search`).as( 9 | "search-courses" 10 | ); 11 | cy.get(".css-bs7b3k").contains("搜尋").click(); 12 | 13 | // cy.wait(["@search-courses"]); 14 | cy.get(".css-1xcdwtr").contains("共找到 10935 筆結果"); 15 | }); 16 | }); 17 | -------------------------------------------------------------------------------- /cypress/e2e/e2e/e2e_home.js: -------------------------------------------------------------------------------- 1 | describe("Home page e2e test", () => { 2 | it("Display home page title", () => { 3 | cy.visit("/"); 4 | cy.contains("Course Schedule"); 5 | cy.contains("Re-imagined."); 6 | }); 7 | it("Navigate to course page", () => { 8 | cy.visit("/"); 9 | cy.get("button").contains("開始使用").click(); 10 | cy.url().should("include", "/course"); 11 | cy.go(-1); 12 | cy.get("button").contains("課程").click(); 13 | cy.url().should("include", "/course"); 14 | }); 15 | it("Navigate to about page", () => { 16 | cy.visit("/"); 17 | cy.get(".css-jhyrsx").contains("了解更多").click(); 18 | // cy.get(".css-5tagoc", { timeout: 30000 }); // wait for page load in dev mode 19 | cy.url().should("include", "/about"); 20 | cy.go(-1); 21 | cy.get("button").contains("關於").click(); 22 | cy.url().should("include", "/about"); 23 | }); 24 | }); 25 | -------------------------------------------------------------------------------- /cypress/plugins/index.js: -------------------------------------------------------------------------------- 1 | /// 2 | // *********************************************************** 3 | // This example plugins/index.js can be used to load plugins 4 | // 5 | // You can change the location of this file or turn off loading 6 | // the plugins file with the 'pluginsFile' configuration option. 7 | // 8 | // You can read more here: 9 | // https://on.cypress.io/plugins-guide 10 | // *********************************************************** 11 | 12 | // This function is called when a project is opened or re-opened (e.g. due to 13 | // the project's config changing) 14 | 15 | /** 16 | * @type {Cypress.PluginConfig} 17 | */ 18 | // eslint-disable-next-line no-unused-vars 19 | module.exports = (on, config) => { 20 | // `on` is used to hook into various events Cypress emits 21 | // `config` is the resolved Cypress config 22 | }; 23 | -------------------------------------------------------------------------------- /cypress/support/commands.js: -------------------------------------------------------------------------------- 1 | // *********************************************** 2 | // This example commands.js shows you how to 3 | // create various custom commands and overwrite 4 | // existing commands. 5 | // 6 | // For more comprehensive examples of custom 7 | // commands please read more here: 8 | // https://on.cypress.io/custom-commands 9 | // *********************************************** 10 | // 11 | // 12 | // -- This is a parent command -- 13 | // Cypress.Commands.add('login', (email, password) => { ... }) 14 | // 15 | // 16 | // -- This is a child command -- 17 | // Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... }) 18 | // 19 | // 20 | // -- This is a dual command -- 21 | // Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... }) 22 | // 23 | // 24 | // -- This will overwrite an existing command -- 25 | // Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) 26 | -------------------------------------------------------------------------------- /cypress/support/e2e.js: -------------------------------------------------------------------------------- 1 | // *********************************************************** 2 | // This example support/index.js is processed and 3 | // loaded automatically before your test files. 4 | // 5 | // This is a great place to put global configuration and 6 | // behavior that modifies Cypress. 7 | // 8 | // You can change the location of this file or turn off 9 | // automatically serving support files with the 10 | // 'supportFile' configuration option. 11 | // 12 | // You can read more here: 13 | // https://on.cypress.io/configuration 14 | // *********************************************************** 15 | 16 | // Import commands.js using ES2015 syntax: 17 | import "./commands"; 18 | 19 | // Alternatively you can use CommonJS syntax: 20 | // require('./commands') 21 | -------------------------------------------------------------------------------- /next-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | 4 | // NOTE: This file should not be edited 5 | // see https://nextjs.org/docs/basic-features/typescript for more information. 6 | -------------------------------------------------------------------------------- /next.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('next').NextConfig} */ 2 | const withBundleAnalyzer = require("@next/bundle-analyzer")({ 3 | enabled: process.env.ANALYZE === "true", 4 | }); 5 | 6 | module.exports = withBundleAnalyzer({ 7 | reactStrictMode: true, 8 | }); 9 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ncn-frontend-v2", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "dev": "next dev", 7 | "build": "next build", 8 | "start": "node_modules/next/dist/bin/next start -p $PORT", 9 | "postinstall": "next build", 10 | "lint": "next lint", 11 | "lint-fix": "next lint . --cache --fix", 12 | "e2e": "npx cypress run --spec 'cypress/e2e/e2e/*'", 13 | "next:start": "next start", 14 | "analyze": "cross-env ANALYZE=true next build" 15 | }, 16 | "lint-staged": { 17 | "*.{js,jsx,ts,tsx}": "eslint --cache --fix" 18 | }, 19 | "dependencies": { 20 | "@auth0/nextjs-auth0": "^1.9.1", 21 | "@chakra-ui/icons": "^2.0.2", 22 | "@chakra-ui/react": "^2.2.1", 23 | "@dnd-kit/core": "^6.0.5", 24 | "@dnd-kit/modifiers": "^6.0.0", 25 | "@dnd-kit/sortable": "^7.0.1", 26 | "@emotion/react": "^11", 27 | "@emotion/styled": "^11", 28 | "axios": "^0.27.2", 29 | "color-hash": "^2.0.1", 30 | "crypto-js": "^4.1.1", 31 | "date-fns": "^2.29.1", 32 | "focus-visible": "^5.2.0", 33 | "framer-motion": "^6", 34 | "lodash": "^4.17.21", 35 | "moment": "^2.29.3", 36 | "next": "12.2.0", 37 | "nprogress": "^0.2.0", 38 | "randomcolor": "^0.6.2", 39 | "react": "18.2.0", 40 | "react-copy-to-clipboard": "^5.1.0", 41 | "react-dom": "18.2.0", 42 | "react-icons": "^4.4.0", 43 | "react-intersection-observer": "^9.3.5", 44 | "react-minimal-pie-chart": "^8.3.0", 45 | "react-scroll": "^1.8.7", 46 | "react-select": "^5.4.0", 47 | "react-spinners": "^0.13.3", 48 | "react-table-drag-select": "^0.3.1", 49 | "react-use": "^17.4.0", 50 | "sharp": "^0.30.7", 51 | "swr": "^1.3.0", 52 | "uuid": "^8.3.2", 53 | "valtio": "^1.6.1" 54 | }, 55 | "devDependencies": { 56 | "@next/bundle-analyzer": "^12.2.3", 57 | "@types/auth0": "^2.35.3", 58 | "@types/color-hash": "^1.0.2", 59 | "@types/crypto-js": "^4.1.1", 60 | "@types/gtag.js": "^0.0.10", 61 | "@types/lodash": "^4.14.182", 62 | "@types/node": "^18.6.3", 63 | "@types/nprogress": "^0.2.0", 64 | "@types/randomcolor": "^0.5.6", 65 | "@types/react": "^18.0.15", 66 | "@types/react-copy-to-clipboard": "^5.0.4", 67 | "@types/react-dom": "^18.0.6", 68 | "@types/react-scroll": "^1.8.4", 69 | "@types/uuid": "^8.3.4", 70 | "@typescript-eslint/eslint-plugin": "^5.32.0", 71 | "cross-env": "^7.0.3", 72 | "cypress": "^10.3.0", 73 | "eslint": "^8.19.0", 74 | "eslint-config-next": "12.2.0", 75 | "eslint-config-prettier": "^8.5.0", 76 | "eslint-plugin-cypress": "^2.12.1", 77 | "eslint-plugin-prettier": "^4.2.1", 78 | "eslint-plugin-react": "^7.30.1", 79 | "eslint-plugin-react-hooks": "^4.6.0", 80 | "eslint-plugin-unused-imports": "^2.0.0", 81 | "husky": "^8.0.1", 82 | "lint-staged": "^13.0.3", 83 | "prettier": "^2.7.1", 84 | "typescript": "^4.7.4" 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /public/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NTUCourse-Neo/ncn-frontend/34354eca4c1ee4a1068507cb581d40797f7ae3ef/public/apple-touch-icon.png -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NTUCourse-Neo/ncn-frontend/34354eca4c1ee4a1068507cb581d40797f7ae3ef/public/favicon.ico -------------------------------------------------------------------------------- /public/img/home_cards/course_table.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /public/img/home_cards/selection.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /public/img/ncn_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NTUCourse-Neo/ncn-frontend/34354eca4c1ee4a1068507cb581d40797f7ae3ef/public/img/ncn_logo.png -------------------------------------------------------------------------------- /public/img/parrot/parrot.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NTUCourse-Neo/ncn-frontend/34354eca4c1ee4a1068507cb581d40797f7ae3ef/public/img/parrot/parrot.gif -------------------------------------------------------------------------------- /public/img/parrot/ultrafastparrot.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NTUCourse-Neo/ncn-frontend/34354eca4c1ee4a1068507cb581d40797f7ae3ef/public/img/parrot/ultrafastparrot.gif -------------------------------------------------------------------------------- /public/img/team_avatar/jc-hiroto.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NTUCourse-Neo/ncn-frontend/34354eca4c1ee4a1068507cb581d40797f7ae3ef/public/img/team_avatar/jc-hiroto.png -------------------------------------------------------------------------------- /public/img/team_avatar/swh00tw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NTUCourse-Neo/ncn-frontend/34354eca4c1ee4a1068507cb581d40797f7ae3ef/public/img/team_avatar/swh00tw.png -------------------------------------------------------------------------------- /public/img/team_avatar/wil0408.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NTUCourse-Neo/ncn-frontend/34354eca4c1ee4a1068507cb581d40797f7ae3ef/public/img/team_avatar/wil0408.png -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "NTUCourse Neo", 3 | "name": "NTUCourse Neo", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "apple-touch-icon.png", 12 | "type": "image/png", 13 | "sizes": "180x180" 14 | }, 15 | { 16 | "src": "og.png", 17 | "type": "image/png", 18 | "sizes": "1200x630" 19 | } 20 | ], 21 | "start_url": "/", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /public/og.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NTUCourse-Neo/ncn-frontend/34354eca4c1ee4a1068507cb581d40797f7ae3ef/public/og.png -------------------------------------------------------------------------------- /public/vercel.svg: -------------------------------------------------------------------------------- 1 | 3 | 4 | -------------------------------------------------------------------------------- /src/components/BetaBadge.tsx: -------------------------------------------------------------------------------- 1 | import { Text } from "@chakra-ui/react"; 2 | function BetaBadge({ 3 | content, 4 | size, 5 | }: { 6 | readonly content: string; 7 | readonly size?: "sm" | "md" | "lg"; 8 | }) { 9 | return ( 10 | 18 | {content ? content : "beta"} 19 | 20 | ); 21 | } 22 | 23 | export default BetaBadge; 24 | -------------------------------------------------------------------------------- /src/components/CourseInfo/PTTContentRowContainer.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { 3 | Badge, 4 | Flex, 5 | Spacer, 6 | Text, 7 | VStack, 8 | Icon, 9 | useColorModeValue, 10 | FlexProps, 11 | } from "@chakra-ui/react"; 12 | import { IoMdOpen } from "react-icons/io"; 13 | import { reportEvent } from "utils/ga"; 14 | import type { PTTData } from "types/course"; 15 | 16 | export interface PTTContentRowContainerProps extends FlexProps { 17 | readonly info: PTTData; 18 | } 19 | 20 | function PTTContentRowContainer(props: PTTContentRowContainerProps) { 21 | const { info, ...restProps } = props; 22 | const rowColor = useColorModeValue("blue.50", "#2B6CB030"); 23 | const textColor = useColorModeValue("text.light", "text.dark"); 24 | return ( 25 | 26 | 27 | {info.map((data) => ( 28 | { 40 | window.open(data.url, "_blank"); 41 | reportEvent("ptt_panel", "click_external", data.url); 42 | }} 43 | > 44 | 45 | {data.date} 46 | 47 | 57 | {data.title} 58 | 59 | 69 | - {data.author} 70 | 71 | 72 | 78 | 79 | ))} 80 | 81 | 82 | ); 83 | } 84 | 85 | export default PTTContentRowContainer; 86 | -------------------------------------------------------------------------------- /src/components/CourseInfoRowContainer.tsx: -------------------------------------------------------------------------------- 1 | import { useMemo } from "react"; 2 | import CourseInfoRow from "components/CourseInfoRow"; 3 | import { 4 | Box, 5 | Flex, 6 | Spacer, 7 | Accordion, 8 | useBreakpointValue, 9 | } from "@chakra-ui/react"; 10 | import useUserInfo from "hooks/useUserInfo"; 11 | import { useCourseSearchingContext } from "components/Providers/CourseSearchingProvider"; 12 | import { setHoveredCourseData } from "utils/hoverCourse"; 13 | import useCourseTable from "hooks/useCourseTable"; 14 | import { useUser } from "@auth0/nextjs-auth0"; 15 | import useNeoLocalStorage from "hooks/useNeoLocalStorage"; 16 | import useSearchResult from "hooks/useSearchResult"; 17 | 18 | interface CourseInfoRowPageProps { 19 | readonly displayTable: boolean; 20 | readonly pageIndex: number; 21 | } 22 | function CourseInfoRowPage({ 23 | displayTable, 24 | pageIndex, 25 | }: CourseInfoRowPageProps): JSX.Element | null { 26 | const { search } = useCourseSearchingContext(); 27 | const { courses, isLoading, error } = useSearchResult(search, pageIndex); 28 | const { neoLocalCourseTableKey } = useNeoLocalStorage(); 29 | const { user } = useUser(); 30 | const { userInfo } = useUserInfo(user?.sub ?? null); 31 | const courseTableKey = userInfo 32 | ? userInfo?.course_tables?.[0] ?? null 33 | : neoLocalCourseTableKey; 34 | const { courseTable } = useCourseTable(courseTableKey); 35 | const selectedCourses = useMemo(() => { 36 | return courseTable?.courses ? courseTable?.courses.map((c) => c.id) : []; 37 | }, [courseTable]); 38 | const isDesktop = useBreakpointValue({ base: false, lg: true }); 39 | 40 | if (isLoading || error) { 41 | return null; 42 | } 43 | return ( 44 | <> 45 | {courses.map((course, index) => ( 46 | { 51 | if (displayTable && isDesktop) { 52 | setHoveredCourseData(course); 53 | } 54 | }} 55 | onMouseLeave={() => { 56 | if (displayTable && isDesktop) { 57 | setHoveredCourseData(null); 58 | } 59 | }} 60 | > 61 | 66 | 67 | 68 | ))} 69 | 70 | ); 71 | } 72 | 73 | function CourseInfoRowContainer({ 74 | displayTable, 75 | }: { 76 | readonly displayTable: boolean; 77 | }) { 78 | const { pageNumber } = useCourseSearchingContext(); 79 | 80 | const pages: JSX.Element[] = useMemo(() => { 81 | const res = []; 82 | for (let i = 0; i < pageNumber; i++) { 83 | res.push( 84 | 85 | ); 86 | } 87 | return res; 88 | }, [pageNumber, displayTable]); 89 | 90 | return ( 91 | 92 | 93 | {pages} 94 | 95 | 96 | ); 97 | } 98 | export default CourseInfoRowContainer; 99 | -------------------------------------------------------------------------------- /src/components/CourseTable/CourseTableCard/SortablePopover.tsx: -------------------------------------------------------------------------------- 1 | import { MdDragHandle } from "react-icons/md"; 2 | import { 3 | Flex, 4 | Text, 5 | Badge, 6 | Spacer, 7 | IconButton, 8 | Button, 9 | useColorModeValue, 10 | } from "@chakra-ui/react"; 11 | import { hash_to_color_hex } from "utils/colorAgent"; 12 | import { FaTrashAlt } from "react-icons/fa"; 13 | import { useRouter } from "next/router"; 14 | import { FaInfoCircle } from "react-icons/fa"; 15 | import { reportEvent } from "utils/ga"; 16 | import React from "react"; 17 | import { Course } from "types/course"; 18 | import { 19 | useSortable, 20 | arrayMove, 21 | SortableContext, 22 | sortableKeyboardCoordinates, 23 | verticalListSortingStrategy, 24 | } from "@dnd-kit/sortable"; 25 | import { 26 | DndContext, 27 | closestCenter, 28 | KeyboardSensor, 29 | MouseSensor, 30 | TouchSensor, 31 | useSensor, 32 | useSensors, 33 | } from "@dnd-kit/core"; 34 | import { CSS } from "@dnd-kit/utilities"; 35 | import { 36 | restrictToVerticalAxis, 37 | restrictToParentElement, 38 | } from "@dnd-kit/modifiers"; 39 | 40 | interface SortableElementProps { 41 | readonly course: Course; 42 | readonly prepareToRemoveCourseId: string[]; 43 | readonly handlePrepareToDelete: (courseId: string) => void; 44 | } 45 | 46 | function SortableElement(props: SortableElementProps) { 47 | const { course, prepareToRemoveCourseId, handlePrepareToDelete } = props; 48 | const router = useRouter(); 49 | const badgeColor = useColorModeValue( 50 | hash_to_color_hex(course.id ?? "", 0.9, 0.8), 51 | hash_to_color_hex(course.id ?? "", 0.3, 0.3) 52 | ); 53 | const textColor = useColorModeValue("gray.500", "gray.200"); 54 | const removeColor = useColorModeValue("red.700", "red.300"); 55 | const { 56 | attributes, 57 | listeners, 58 | setNodeRef, 59 | transform, 60 | transition, 61 | isDragging, 62 | } = useSortable({ id: course.id }); 63 | const style = { 64 | transform: CSS.Transform.toString(transform), 65 | transition, 66 | position: "relative", 67 | zIndex: isDragging ? 1000 : undefined, 68 | }; 69 | return ( 70 | 79 |
85 | 86 |
87 | 88 | {course.serial} 89 | 90 | 100 | {course.name} 101 | 102 | 58 | 59 | ); 60 | } 61 | 62 | function CourseTableContainer(props: { 63 | readonly courses: { 64 | readonly [key: string]: Course; 65 | }; 66 | readonly loading: boolean; 67 | readonly courseTimeMap: TimeMap; 68 | }) { 69 | const { courses, loading, courseTimeMap } = props; 70 | const days: Weekday[] = ["1", "2", "3", "4", "5"]; 71 | const intervalTextColor = useColorModeValue("gray.300", "gray.600"); 72 | 73 | const [activeDayCol, setActiveDayCol] = useState<"0" | Weekday>("0"); 74 | const { hoveredCourse, hoveredCourseTimeMap } = useSnapshot(hoverCourseState); 75 | const renderIntervalContent = useCallback( 76 | (days: Weekday[], interval: Interval, i: number) => { 77 | const fullWidth = days.length === 1; 78 | return days.map((day, j) => { 79 | const intervalCourseIds = courseTimeMap?.[day]?.[interval]; 80 | const intervalHoveredCourseIds = 81 | hoveredCourse && hoveredCourseTimeMap?.[day]?.[interval]; 82 | // hover course has been in courseTable already, show solid border in this case 83 | const isOverlapped = intervalCourseIds 84 | ? (courseTimeMap?.[day]?.[interval] ?? []).includes( 85 | hoveredCourseTimeMap?.[day]?.[interval]?.[0] ?? "" 86 | ) 87 | : false; 88 | if (loading) { 89 | return ( 90 | 91 | 92 | 93 | 94 | 95 | ); 96 | } 97 | // no courses & hoverCourse 98 | if (!intervalCourseIds && !intervalHoveredCourseIds) { 99 | return ( 100 | 101 | 110 | 111 | {" "} 112 | {interval} 113 | 114 | 115 | 116 | ); 117 | } 118 | return ( 119 | 120 | 128 | {intervalHoveredCourseIds && !isOverlapped ? ( 129 | 130 | ) : null} 131 | {intervalCourseIds ? ( 132 | 143 | ) : null} 144 | 145 | 146 | ); 147 | }); 148 | }, 149 | [ 150 | courseTimeMap, 151 | courses, 152 | hoveredCourse, 153 | hoveredCourseTimeMap, 154 | loading, 155 | intervalTextColor, 156 | ] 157 | ); 158 | 159 | return ( 160 | 161 | 162 | {activeDayCol === "0" ? ( 163 | 164 | {days.map((day, j) => { 165 | return ( 166 | 186 | ); 187 | })} 188 | 189 | ) : ( 190 | 191 | 208 | 209 | )} 210 | 211 | 212 | {intervals.map((interval, i) => { 213 | if (activeDayCol === "0") { 214 | return ( 215 | 216 | {renderIntervalContent(days, interval, i)} 217 | 218 | ); 219 | } 220 | return ( 221 | 222 | {renderIntervalContent([activeDayCol], interval, i)} 223 | 224 | ); 225 | })} 226 | 227 |
{ 168 | setActiveDayCol(day); 169 | reportEvent("course_table", "click", "expand_day"); 170 | }} 171 | cursor="pointer" 172 | key={`${day}-${j}`} 173 | > 174 | 181 |
182 | {weekdays_map[day]} 183 |
184 |
185 |
{ 193 | setActiveDayCol("0"); 194 | reportEvent("course_table", "click", "collapse_day"); 195 | }} 196 | cursor="pointer" 197 | > 198 | 205 |
{weekdays_map[activeDayCol]}
206 |
207 |
228 | ); 229 | } 230 | 231 | export default CourseTableContainer; 232 | -------------------------------------------------------------------------------- /src/components/CustomIcons.tsx: -------------------------------------------------------------------------------- 1 | import { Icon, IconProps } from "@chakra-ui/react"; 2 | 3 | const DiscordIcon = (props: IconProps) => ( 4 | 5 | 9 | 10 | ); 11 | export { DiscordIcon }; 12 | -------------------------------------------------------------------------------- /src/components/DeadlineCountdown.tsx: -------------------------------------------------------------------------------- 1 | import { 2 | Text, 3 | Flex, 4 | Progress, 5 | HStack, 6 | Button, 7 | LightMode, 8 | } from "@chakra-ui/react"; 9 | import { FaClock } from "react-icons/fa"; 10 | import { differenceInDays, differenceInHours } from "date-fns"; 11 | 12 | const status_map = [ 13 | { 14 | name: "即將開始", 15 | emoji: "⏰", 16 | color: "blue.200", 17 | }, 18 | { 19 | name: "已開始", 20 | emoji: "🏎️", 21 | color: "green.200", 22 | }, 23 | { 24 | name: "快結束啦!", 25 | emoji: "🏃", 26 | color: "yellow.200", 27 | }, 28 | { 29 | name: "剩不到一天了", 30 | emoji: "🥵", 31 | color: "red.200", 32 | }, 33 | ]; 34 | 35 | const ntu_course_select_url = [ 36 | "https://if192.aca.ntu.edu.tw/index.php", 37 | "https://if177.aca.ntu.edu.tw/index.php", 38 | ]; 39 | 40 | interface CourseSelectionSchedule { 41 | start: number; 42 | end: number; 43 | name: string; 44 | label: string; 45 | } 46 | 47 | const course_select_schedule: CourseSelectionSchedule[] = [ 48 | { 49 | name: "初選第一階段", 50 | label: "初選 一階", 51 | start: 1660698000000, 52 | end: 1660935600000, 53 | }, 54 | { 55 | name: "初選第二階段", 56 | label: "二階", 57 | start: 1661302800000, 58 | end: 1661454000000, 59 | }, 60 | { 61 | name: "第一週加退選", 62 | label: "加退選 W1", 63 | start: 1662339600000, 64 | end: 1662782400000, 65 | }, 66 | { 67 | name: "第二週加退選", 68 | label: "W2", 69 | start: 1662944400000, 70 | end: 1663408800000, 71 | }, 72 | { 73 | name: "第三週加退選", 74 | label: "W3", 75 | start: 1663549200000, 76 | end: 1663923600000, 77 | }, 78 | ]; 79 | 80 | const msInDay = 86400000; 81 | 82 | export const getCourseSelectSchedule = (timestamp: number) => { 83 | if (timestamp < course_select_schedule[0].start) { 84 | return { status_idx: 0, schedule_idx: 0 }; 85 | } 86 | for (let i = 0; i < course_select_schedule.length; i++) { 87 | if ( 88 | timestamp >= course_select_schedule[i].start && 89 | timestamp <= course_select_schedule[i].end 90 | ) { 91 | if (course_select_schedule[i].end - timestamp <= msInDay) { 92 | return { status_idx: 3, schedule_idx: i }; 93 | } else if (course_select_schedule[i].end - timestamp <= msInDay * 2) { 94 | return { status_idx: 2, schedule_idx: i }; 95 | } 96 | return { status_idx: 1, schedule_idx: i }; 97 | } 98 | if ( 99 | i < course_select_schedule.length - 1 && 100 | timestamp <= course_select_schedule[i + 1].start && 101 | timestamp >= course_select_schedule[i].end 102 | ) { 103 | return { status_idx: 0, schedule_idx: i + 1 }; 104 | } 105 | } 106 | return { status_idx: -1, schedule_idx: -1 }; 107 | }; 108 | 109 | function DeadlineCountdown() { 110 | const curr_ts = new Date().getTime(); 111 | const { status_idx, schedule_idx } = getCourseSelectSchedule(curr_ts); 112 | if (status_idx === -1) { 113 | return null; 114 | } 115 | const elaspedDays = differenceInDays( 116 | status_idx === 0 117 | ? course_select_schedule[schedule_idx].start 118 | : course_select_schedule[schedule_idx].end, 119 | curr_ts 120 | ); 121 | const elapsedHours = 122 | differenceInHours( 123 | status_idx === 0 124 | ? course_select_schedule[schedule_idx].start 125 | : course_select_schedule[schedule_idx].end, 126 | curr_ts 127 | ) % 24; 128 | const time_percent = 129 | status_idx === 0 130 | ? 0 131 | : (curr_ts - course_select_schedule[schedule_idx].start) / 132 | (course_select_schedule[schedule_idx].end - 133 | course_select_schedule[schedule_idx].start); 134 | const process_percent = 135 | ((time_percent + schedule_idx) / (course_select_schedule.length - 1)) * 100; 136 | 137 | return ( 138 | 139 | 150 | 157 | 158 | {status_map[status_idx].emoji}{" "} 159 | {course_select_schedule[schedule_idx].name}{" "} 160 | {status_map[status_idx].name} 161 | 162 | 163 | 164 | 165 | {" "} 166 | 尚餘 {elaspedDays} 天 {elapsedHours} 時 167 | 168 | 169 | 170 | 179 | 180 | {course_select_schedule.map((item, idx) => { 181 | return ( 182 | 189 | {item.label} 190 | 191 | ); 192 | })} 193 | 194 | 195 | 206 | 216 | 217 | 218 | 219 | ); 220 | } 221 | 222 | export default DeadlineCountdown; 223 | -------------------------------------------------------------------------------- /src/components/FilterModals/CategoryFilterModal.tsx: -------------------------------------------------------------------------------- 1 | import { 2 | useDisclosure, 3 | Modal, 4 | ModalOverlay, 5 | ModalContent, 6 | ModalHeader, 7 | ModalFooter, 8 | ModalBody, 9 | ModalCloseButton, 10 | Button, 11 | Heading, 12 | Divider, 13 | Flex, 14 | useBreakpointValue, 15 | useColorModeValue, 16 | } from "@chakra-ui/react"; 17 | import { type_list, code_map } from "data/course_type"; 18 | import FilterElement from "components/FilterModals/components/FilterElement"; 19 | import React, { useMemo } from "react"; 20 | import { useCourseSearchingContext } from "components/Providers/CourseSearchingProvider"; 21 | import { reportEvent } from "utils/ga"; 22 | 23 | export interface CategoryFilterModalProps { 24 | readonly title: string; 25 | readonly isEnabled: boolean; 26 | readonly selectedType: string[]; 27 | readonly setSelectedType: (time: string[]) => void; 28 | } 29 | 30 | function CategoryFilterModal({ 31 | title, 32 | isEnabled, 33 | selectedType, 34 | setSelectedType, 35 | }: CategoryFilterModalProps) { 36 | const headingColor = useColorModeValue("heading.light", "heading.dark"); 37 | const { searchFilters, setSearchFilters } = useCourseSearchingContext(); 38 | const { isOpen, onOpen, onClose } = useDisclosure(); 39 | const modalBgColor = useColorModeValue("white", "gray.700"); 40 | 41 | const onOpenModal = () => { 42 | // overwrite local states by redux store 43 | setSelectedType(searchFilters.category); 44 | onOpen(); 45 | }; 46 | 47 | const onCancelEditing = () => { 48 | // fire when click "X" or outside of modal 49 | // overwrite local state by redux state 50 | onClose(); 51 | setSelectedType(searchFilters.category); 52 | }; 53 | 54 | const onSaveEditing = () => { 55 | // fire when click "Save" 56 | // overwrite redux state by local state 57 | setSearchFilters({ ...searchFilters, category: selectedType }); 58 | onClose(); 59 | }; 60 | 61 | const onResetEditing = () => { 62 | // fire when click "Reset" 63 | // set local state to empty array 64 | setSelectedType([]); 65 | }; 66 | 67 | const modalBody = useMemo( 68 | () => ( 69 | 70 | {Object.keys(code_map).map((code_map_key, index) => { 71 | const categories = type_list.filter( 72 | (type) => type.code[0] === code_map_key 73 | ); 74 | return ( 75 | 76 | 87 | 88 | {code_map[code_map_key].name} 89 | 90 | 91 | 92 | {categories 93 | .filter((type) => !selectedType.includes(type.id)) 94 | .map((type, typeIdx) => ( 95 | { 101 | setSelectedType([...selectedType, type.id]); 102 | reportEvent("filter_category", "click", type.id); 103 | }} 104 | /> 105 | ))} 106 | 107 | ); 108 | })} 109 | 110 | ), 111 | [selectedType, setSelectedType, headingColor, modalBgColor] 112 | ); 113 | 114 | return ( 115 | <> 116 | 126 | { 129 | onCancelEditing(); 130 | }} 131 | size={useBreakpointValue({ base: "full", md: "xl" }) ?? "xl"} 132 | scrollBehavior="inside" 133 | > 134 | 135 | 136 | 137 | {title} 138 | 145 | 156 | 166 | 167 | 168 | 169 | 170 | {type_list 171 | .filter((type) => selectedType.includes(type.id)) 172 | .map((type, index) => ( 173 | { 179 | setSelectedType( 180 | selectedType.filter((id) => id !== type.id) 181 | ); 182 | reportEvent("filter_category", "click", type.id); 183 | }} 184 | /> 185 | ))} 186 | 187 | {modalBody} 188 | 189 | 190 | 200 | 209 | 210 | 211 | 212 | 213 | ); 214 | } 215 | 216 | export default CategoryFilterModal; 217 | -------------------------------------------------------------------------------- /src/components/FilterModals/DeptFilterModal.tsx: -------------------------------------------------------------------------------- 1 | import { 2 | useDisclosure, 3 | Modal, 4 | ModalOverlay, 5 | ModalContent, 6 | ModalHeader, 7 | ModalFooter, 8 | ModalBody, 9 | ModalCloseButton, 10 | Button, 11 | Heading, 12 | Divider, 13 | Flex, 14 | useBreakpointValue, 15 | useColorModeValue, 16 | } from "@chakra-ui/react"; 17 | import React, { useMemo } from "react"; 18 | import { college_map } from "data/college"; 19 | import { deptList } from "data/department"; 20 | import FilterElement from "components/FilterModals/components/FilterElement"; 21 | import { useCourseSearchingContext } from "components/Providers/CourseSearchingProvider"; 22 | import { reportEvent } from "utils/ga"; 23 | 24 | export interface DeptFilterModalProps { 25 | readonly title: string; 26 | readonly isEnabled: boolean; 27 | readonly selectedDept: string[]; 28 | readonly setSelectedDept: (time: string[]) => void; 29 | } 30 | 31 | function DeptFilterModal({ 32 | title, 33 | isEnabled, 34 | selectedDept, 35 | setSelectedDept, 36 | }: DeptFilterModalProps) { 37 | const headingColor = useColorModeValue("heading.light", "heading.dark"); 38 | const { searchFilters, setSearchFilters } = useCourseSearchingContext(); 39 | const { isOpen, onOpen, onClose } = useDisclosure(); 40 | const modalBgColor = useColorModeValue("white", "gray.700"); 41 | 42 | const onOpenModal = () => { 43 | // overwrite local states by redux store 44 | setSelectedDept(searchFilters.department); 45 | onOpen(); 46 | }; 47 | 48 | const onCancelEditing = () => { 49 | // fire when click "X" or outside of modal 50 | // overwrite local state by redux state 51 | onClose(); 52 | setSelectedDept(searchFilters.department); 53 | }; 54 | 55 | const onSaveEditing = () => { 56 | // fire when click "Save" 57 | // overwrite redux state by local state 58 | setSearchFilters({ ...searchFilters, department: selectedDept }); 59 | onClose(); 60 | }; 61 | 62 | const onResetEditing = () => { 63 | // fire when click "Reset" 64 | // set local state to empty array 65 | setSelectedDept([]); 66 | }; 67 | 68 | const modalBody = useMemo( 69 | () => ( 70 | <> 71 | {Object.keys(college_map).map((college_key, index) => { 72 | const departments = deptList.filter( 73 | (dept) => dept.college_id === college_key 74 | ); 75 | if (departments.length === 0) { 76 | return null; 77 | } 78 | return ( 79 | 80 | 91 | 92 | {college_key + " " + college_map[college_key].name} 93 | 94 | 95 | 96 | {departments 97 | .filter((dept) => !selectedDept.includes(dept.id)) 98 | .map((dept, dept_index) => ( 99 | { 105 | setSelectedDept([...selectedDept, dept.id]); 106 | reportEvent("filter_department", "click", dept.id); 107 | }} 108 | /> 109 | ))} 110 | 111 | ); 112 | })} 113 | 114 | ), 115 | [selectedDept, setSelectedDept, headingColor, modalBgColor] 116 | ); 117 | 118 | return ( 119 | <> 120 | 130 | { 133 | onCancelEditing(); 134 | }} 135 | size={useBreakpointValue({ base: "full", md: "xl" }) ?? "xl"} 136 | scrollBehavior="inside" 137 | > 138 | 139 | 140 | 141 | {title} 142 | 149 | 160 | 170 | 171 | 172 | 173 | 174 | {deptList 175 | .filter((dept) => selectedDept.includes(dept.id)) 176 | .map((dept, index) => ( 177 | { 183 | setSelectedDept( 184 | selectedDept.filter((code) => code !== dept.id) 185 | ); 186 | reportEvent("filter_department", "click", dept.id); 187 | }} 188 | /> 189 | ))} 190 | 191 | {modalBody} 192 | 193 | 194 | 204 | 213 | 214 | 215 | 216 | 217 | ); 218 | } 219 | 220 | export default DeptFilterModal; 221 | -------------------------------------------------------------------------------- /src/components/FilterModals/TimeFilterModal.tsx: -------------------------------------------------------------------------------- 1 | import { 2 | useDisclosure, 3 | Modal, 4 | ModalOverlay, 5 | ModalContent, 6 | ModalHeader, 7 | ModalFooter, 8 | ModalBody, 9 | ModalCloseButton, 10 | Button, 11 | Flex, 12 | useBreakpointValue, 13 | } from "@chakra-ui/react"; 14 | import TimetableSelector from "components/FilterModals/components/TimetableSelector"; 15 | import { mapStateToTimeTable } from "utils/timeTableConverter"; 16 | import { useCourseSearchingContext } from "components/Providers/CourseSearchingProvider"; 17 | import { reportEvent } from "utils/ga"; 18 | import type { Interval } from "types/course"; 19 | import { intervals } from "constant"; 20 | 21 | export interface TimeFilterModalProps { 22 | readonly title: string; 23 | readonly isEnabled: boolean; 24 | readonly selectedTime: boolean[][]; 25 | readonly setSelectedTime: (time: boolean[][]) => void; 26 | } 27 | 28 | function TimeFilterModal(props: TimeFilterModalProps) { 29 | const { selectedTime, setSelectedTime, isEnabled, title } = props; 30 | const { searchFilters, setSearchFilters } = useCourseSearchingContext(); 31 | const { isOpen, onOpen, onClose } = useDisclosure(); 32 | 33 | const saveSelectedTime = () => { 34 | // turn 15x7 2D array (selectedTime) to 7x15 array 35 | const timeTable: Interval[][] = [[], [], [], [], [], [], []]; 36 | for (let i = 0; i < intervals.length; i++) { 37 | const interval = intervals[i]; 38 | for (let j = 0; j < 7; j++) { 39 | if (selectedTime[i][j] === true) { 40 | timeTable[j].push(interval); 41 | } 42 | } 43 | } 44 | setSearchFilters({ ...searchFilters, time: timeTable }); 45 | }; 46 | 47 | const resetSelectedTime = () => { 48 | setSelectedTime([ 49 | [false, false, false, false, false, false, false], 50 | [false, false, false, false, false, false, false], 51 | [false, false, false, false, false, false, false], 52 | [false, false, false, false, false, false, false], 53 | [false, false, false, false, false, false, false], 54 | [false, false, false, false, false, false, false], 55 | [false, false, false, false, false, false, false], 56 | [false, false, false, false, false, false, false], 57 | [false, false, false, false, false, false, false], 58 | [false, false, false, false, false, false, false], 59 | [false, false, false, false, false, false, false], 60 | [false, false, false, false, false, false, false], 61 | [false, false, false, false, false, false, false], 62 | [false, false, false, false, false, false, false], 63 | [false, false, false, false, false, false, false], 64 | ]); 65 | }; 66 | 67 | return ( 68 | <> 69 | 80 | { 83 | onClose(); 84 | }} 85 | size={useBreakpointValue({ base: "full", md: "xl" }) ?? "xl"} 86 | scrollBehavior="inside" 87 | > 88 | 89 | 90 | 91 | {title} 92 | 99 | 111 | 121 | 122 | 123 | 124 | 125 | 129 | 130 | 131 | 142 | 151 | 152 | 153 | 154 | 155 | ); 156 | } 157 | 158 | export default TimeFilterModal; 159 | -------------------------------------------------------------------------------- /src/components/FilterModals/components/FilterElement.tsx: -------------------------------------------------------------------------------- 1 | import { 2 | Button, 3 | Badge, 4 | useColorModeValue, 5 | ButtonProps, 6 | } from "@chakra-ui/react"; 7 | 8 | export interface FilterElementProps extends ButtonProps { 9 | readonly id: string; 10 | readonly name: string; 11 | readonly selected: boolean; 12 | } 13 | 14 | // Buttons in filter modal 15 | function FilterElement(props: FilterElementProps) { 16 | const { id, name, selected, onClick } = props; 17 | return ( 18 | 32 | ); 33 | } 34 | export default FilterElement; 35 | -------------------------------------------------------------------------------- /src/components/FilterModals/components/TimetableSelector.tsx: -------------------------------------------------------------------------------- 1 | import TableDragSelect from "react-table-drag-select"; 2 | import "react-table-drag-select/style.css"; 3 | import { Flex, Text } from "@chakra-ui/react"; 4 | import { intervals } from "constant"; 5 | 6 | function TimetableSelector({ 7 | selectedTime, 8 | setSelectedTime, 9 | }: { 10 | readonly selectedTime: boolean[][]; 11 | readonly setSelectedTime: (time: boolean[][]) => void; 12 | }) { 13 | const days = ["一", "二", "三", "四", "五", "六", "日"]; 14 | 15 | return ( 16 | 17 | 22 | {days.map((day, j) => { 23 | return ( 24 | 30 | {day} 31 | 32 | ); 33 | })} 34 | 35 | 36 | 43 | {intervals.map((interval, j) => { 44 | return ( 45 | 51 | {interval} 52 | 53 | ); 54 | })} 55 | 56 | 59 | setSelectedTime(new_time_table) 60 | } 61 | > 62 | {intervals.map((day, i) => { 63 | return ( 64 | 65 | {days.map((interval, j) => { 66 | return ; 67 | })} 68 | 69 | ); 70 | })} 71 | 72 | 79 | {intervals.map((interval, j) => { 80 | return ( 81 | 87 | {interval} 88 | 89 | ); 90 | })} 91 | 92 | 93 | 94 | ); 95 | } 96 | export default TimetableSelector; 97 | -------------------------------------------------------------------------------- /src/components/Footer.tsx: -------------------------------------------------------------------------------- 1 | import { 2 | Flex, 3 | Spacer, 4 | Text, 5 | Button, 6 | ButtonGroup, 7 | HStack, 8 | Icon, 9 | Center, 10 | useColorModeValue, 11 | } from "@chakra-ui/react"; 12 | import { FaCodeBranch, FaGithub, FaHeartbeat } from "react-icons/fa"; 13 | import Link from "next/link"; 14 | import { DiscordIcon } from "components/CustomIcons"; 15 | import Image from "next/image"; 16 | import { reportEvent } from "utils/ga"; 17 | 18 | function Footer() { 19 | const ver = "beta (20220721)"; 20 | const secondaryColor = useColorModeValue("gray.400", "gray.500"); 21 | const handleOpenPage = (page: string) => { 22 | window.open(page, "_blank"); 23 | }; 24 | return ( 25 | 38 | 39 |
40 | ncnLogo 47 |
48 | 49 | 50 | 51 | 52 | {ver} 53 | 54 | 55 | 56 | 57 | 84 | 111 | 138 | 139 |
140 | ); 141 | } 142 | export default Footer; 143 | -------------------------------------------------------------------------------- /src/components/GoogleAnalytics.tsx: -------------------------------------------------------------------------------- 1 | import Script from "next/script"; 2 | import { useEffect } from "react"; 3 | import { useRouter } from "next/router"; 4 | 5 | const GA_ID = process.env.NEXT_PUBLIC_GA_ID; 6 | 7 | function GoogleAnalytics() { 8 | const router = useRouter(); 9 | useEffect(() => { 10 | const handleRouteChange = (url: string) => { 11 | if (GA_ID) { 12 | window.gtag("config", GA_ID, { page_path: url }); 13 | } 14 | }; 15 | router.events.on("routeChangeComplete", handleRouteChange); 16 | return () => { 17 | router.events.off("routeChangeComplete", handleRouteChange); 18 | }; 19 | }, [router.events]); 20 | 21 | return ( 22 | <> 23 |