Computer Science Club of the University of Waterloo's website. https://csclub.uwaterloo.ca
Go to file
Shahan Nedadahandeh bb78a3d53d
continuous-integration/drone/push Build is passing Details
Warning Header (Closes #205) (#394)
Update:
In order to solve the issues discussed below, we decided to put the warnings in a json file, since they can be easily imported into a javascript file and webpack automatically bundles them with the client side app, so no static props is needed.

__________

To get the warning data, since it is something that needs to be on all pages, it makes sense for the component to go in the app.js file (similar to the nav bar). However, next.js has a cumbersome issue that it does not support getStaticProps in the app.ts file (and getStaticProps only works in page files), thus we have no way of requesting the warning data easily in the \<WarningHeader\> Component. (https://github.com/vercel/next.js/discussions/10949)

Here is my solution:
- Request the warning data on the client side through the use of an api.
    - I made a warning api (/api/currentWarning) which sends a json of the current warning
    - Advantage: warnings will always be up to date since it is recalculated on every request
    - Advantage: It can potentially incorporate with other CSC services who might need to know about the warning (eg linktree?)
    - Disadvantage: can get expensive if we have a lot of warnings, to fix this I can cache the current warning and only re-read the files every 24h if this is a problem, but if we don’t have that many warnings I think it should be fine
    - Disadvantage: listed below:

The current problem with what I implemented is that it doesn’t build in the production environment:
- The way we build the website, when we call “next export” that disables any api endpoints.
- According to this https://github.com/vercel/vercel/discussions/6551, if we want to allow api endpoints, we have to just do “next build”. This has implications that the site won’t be completely static anymore, but the other solutions also have similar problems  ( though the GitHub post says that next will still optimize for static with only next build).

Another advantage of allowing api’s is that maybe in the future we will implement other features where an api might be useful.

If you want to try it out, my branch works fine locally (when just running npm run dev or npm run build”)

Other possible solutions:
- Use getInitialProps inside _app.js, but this has the downside that it will “disable Automatic Static Optimization in pages without Static Generation.” (https://nextjs.org/docs/advanced-features/custom-app), which I believe will slow the whole site down, but, we will be able to still use the old build command I think, I am not sure of the full effect of this.
	- However, implementing this would also be relatively simple.

- Add the warning request to the getStaticProps of every single page, possibly through some wrapper component around every single page, this has the disadvantage that we need to do a lot of refactoring of all the pages of the site and cant use the intended “_app.ts” wrapper.

- Add warning header only to the homepage (or maybe one or two other important pages).

Co-authored-by: shahanneda <shahan.neda@gmail.com>
Reviewed-on: #394
Reviewed-by: Amy <a258wang@csclub.uwaterloo.ca>
2022-02-22 23:29:53 -05:00
.vscode Fix constitution formatting (#216) 2021-08-30 09:12:39 -04:00
components Warning Header (Closes #205) (#394) 2022-02-22 23:29:53 -05:00
content Warning Header (Closes #205) (#394) 2022-02-22 23:29:53 -05:00
hooks Meet the Team page (#94) 2021-08-23 11:11:42 -04:00
images Create SeshanRavikumar.jpg 2022-02-14 17:44:22 -05:00
lib Warning Header (Closes #205) (#394) 2022-02-22 23:29:53 -05:00
pages Warning Header (Closes #205) (#394) 2022-02-22 23:29:53 -05:00
public Image Optimization Script (#348) 2021-10-31 16:58:14 -04:00
scripts Warning Header (Closes #205) (#394) 2022-02-22 23:29:53 -05:00
.drone.yml Generate members list (#354) 2021-11-22 12:47:00 -05:00
.eslintignore Add mdx support and playground 2021-04-26 19:16:55 -04:00
.eslintrc.js Use eslint-plugin-import to bring some order to the mess (#132) 2021-08-13 04:16:37 -04:00
.gitignore Image Optimization Script (#348) 2021-10-31 16:58:14 -04:00
README.md Final changes for deploying (#279) 2021-09-03 18:34:56 -04:00
deploy-demo.bash Script to deploy site to your CSC website (#99) 2021-08-03 19:17:08 -04:00
deploy.sh Generate members list (#354) 2021-11-22 12:47:00 -05:00
next-env.d.ts Upgrade Next, React, TypeScript (#91) 2021-08-01 17:54:25 -04:00
next.config.js Update content for advice pages (#299) 2021-09-11 16:00:22 -04:00
package-lock.json Update dependency @next/mdx to v11.1.3 (#143) 2022-01-20 01:03:24 -05:00
package.json Update dependency @next/mdx to v11.1.3 (#143) 2022-01-20 01:03:24 -05:00
postcss.config.json Convert rems to px and use calc to convert on build time 2021-05-24 18:58:28 +00:00
renovate.json Force node 16+ and npm 7+ in renovate (#192) 2021-08-28 00:05:56 -04:00
tsconfig.json Dynamically generate event calendar (#332) 2021-09-27 16:20:18 -04:00
types.d.ts Add permalink in event card (#316) 2021-09-12 20:15:31 -04:00
utils.ts Warning Header (Closes #205) (#394) 2022-02-22 23:29:53 -05:00

README.md

Development

Dependencies

Make sure that you have node >= 14 and npm >= 7. Node 14 ships with npm v6, so if you're using node 14, you would need to upgrade npm. Alternatively you could also upgrade to node 16, which ships with npm 7.

How to upgrade npm: npm i -g npm

Local

Production

  • npm install to install project dependencies
  • npm run build to generate html/css/js
  • npm run export to move the built files (along with assets in the public directory) to the /out directory
  • Use your favourite web server to host the files in the /out directory. (A very simple one would be python -m http.server - not sure if it should actually be used for production :P)

Deploy

  • groups (make sure you're in the www group)
  • curl -o- https://git.csclub.uwaterloo.ca/www/www-new/raw/branch/main/deploy.sh | bash (run on caffeine)