Add /events/[year]/[term] page #158

Merged
a3thakra merged 46 commits from feat/events-term into main 2021-08-27 16:14:55 -04:00
Member

Closes #113

Closes #113
j285he added 36 commits 2021-08-18 17:54:03 -04:00
continuous-integration/drone/push Build is passing Details
b733acd156
Add lib file
continuous-integration/drone/push Build is passing Details
bfcbf5c687
Fix type error
continuous-integration/drone/push Build is passing Details
9f7d40b426
Merge branch 'main' into feat/events-lib
continuous-integration/drone/push Build is passing Details
c39b0036ad
Correct Dirents
continuous-integration/drone/push Build is failing Details
590b2554c0
Fixes for dirents
continuous-integration/drone/push Build is passing Details
d237621d14
ESLint fixes
continuous-integration/drone/push Build is passing Details
3a697c09c0
Add sorting
continuous-integration/drone/push Build is passing Details
b32fd53d95
Remove unneeded dirent conversion
continuous-integration/drone/push Build is failing Details
40d37c4aea
Fix lint problems
continuous-integration/drone/push Build is passing Details
fecd3bf3e0
Rename functions
continuous-integration/drone/push Build is failing Details
2798efc221
Function renaming
continuous-integration/drone/push Build is passing Details
5dd258ec86
Merge branch 'main' into feat/events-year
continuous-integration/drone/push Build is passing Details
408275e8cf
Remove temp page
continuous-integration/drone/push Build is failing Details
10449e921e
Remove events
continuous-integration/drone/push Build is passing Details
6f429d20bf
Add events
continuous-integration/drone/push Build is passing Details
29f2c3208c
Fix build error
continuous-integration/drone/push Build is passing Details
50c2f08769
Simplify types
continuous-integration/drone/push Build is passing Details
a23a10d8e4
Fix for Fall 2018
continuous-integration/drone/push Build is failing Details
416e027ebb
Add futureEvents pastEvents EventCard logic
continuous-integration/drone/push Build is failing Details
e971c85afc
Create events/index.tsx
continuous-integration/drone/push Build is passing Details
5631217681
Add time detection for current time
continuous-integration/drone/push Build is passing Details
3e61407643
Remove events
j285he requested review from a3thakra 2021-08-18 18:00:36 -04:00
a3thakra reviewed 2021-08-18 18:41:23 -04:00
@ -0,0 +2,4 @@
import React from "react";
import { EventCard } from "../../../../components/EventCard";
import { MiniEventCard } from "../../../../components/MiniEventCard";
Owner

Use "@/components/..." instead of "../../../../components/..."

Use "@/components/..." instead of "../../../../components/..."
j285he marked this conversation as resolved
a3thakra reviewed 2021-08-18 18:41:48 -04:00
@ -0,0 +9,4 @@
getEventsByTerm,
getEventBySlug,
Event,
} from "../../../../lib/events";
Owner

use "@/lib/events" instead of "../../../lib/events"

use "@/lib/events" instead of "../../../lib/events"
j285he marked this conversation as resolved
a3thakra reviewed 2021-08-18 18:43:39 -04:00
@ -0,0 +13,4 @@
import styles from "./term.module.css";
export async function getStaticPaths(): Promise<{
Owner

This is not the correct way to type out getStaticPaths. You should do something like the news archive files.

export const getStaticPaths: GetStaticPaths = async () => {...} something like this

This is not the correct way to type out `getStaticPaths`. You should do something like the news archive files. `export const getStaticPaths: GetStaticPaths = async () => {...}` something like this
j285he marked this conversation as resolved
a3thakra reviewed 2021-08-18 18:44:34 -04:00
@ -0,0 +25,4 @@
const years = await getEventYears();
const paths = [];
for (const year of years) {
const terms = await getEventTermsByYear(year);
Owner

This is inefficient. It always wait for 1 year to complete before proceeding to the next. You should use Promise.all here.

This is inefficient. It always wait for 1 year to complete before proceeding to the next. You should use Promise.all here.
Author
Member

I'm a little confused here. The problem is that await getEventTermsByYear(year) forces the function to stop until getEventTermsByYear returns, right?

But on the next line I am getting an error with being unable to map on a type of Promise<string[]>. How can I resolve this?

Thanks!

I'm a little confused here. The problem is that `await getEventTermsByYear(year)` forces the function to stop until `getEventTermsByYear` returns, right? But on the next line I am getting an error with being unable to map on a type of `Promise<string[]>`. How can I resolve this? Thanks!
Owner

yes.

you can await on a Promise.all to map over it.

so something like:

const paths = (await Promise.all(
  years.map(async (year) => {
    const terms = await getEventTermsByYear(year);
    return terms.map((curTerm) => ({ params: { year: year, term: curTerm } }))
  })
)).flat()
yes. you can `await` on a Promise.all to map over it. so something like: ```ts const paths = (await Promise.all( years.map(async (year) => { const terms = await getEventTermsByYear(year); return terms.map((curTerm) => ({ params: { year: year, term: curTerm } })) }) )).flat() ```
Author
Member

Would the use of await getEventTermsByYear here still force the async function on line 2 to wait until getEventTermsByYear returns?

Is the difference here that years.map can map each element asynchronously, whereas in my original function for (const year of years) cannot?

Would the use of `await getEventTermsByYear` here still force the async function on line 2 to wait until `getEventTermsByYear` returns? Is the difference here that `years.map` can map each element asynchronously, whereas in my original function `for (const year of years)` cannot?
Owner

the for loop is going to wait for each year to be completed before the next can start.

But with this approach, all years start simultaneously.

Within each year, we are still waiting for terms, that doesn't change in both cases.

2020
  - winter
  - spring
  - fall
2021
  - winter
  - spring
  - fall

vs

2020               | 2021
  - winter         |   - winter
  - spring         |   - spring
  - fall           |   - fall
the for loop is going to wait for each year to be completed before the next can start. But with this approach, all years start simultaneously. Within each year, we are still waiting for terms, that doesn't change in both cases. ``` 2020 - winter - spring - fall 2021 - winter - spring - fall ``` vs ``` 2020 | 2021 - winter | - winter - spring | - spring - fall | - fall ```
Author
Member

Ah that makes sense, thank you!

Ah that makes sense, thank you!
j285he marked this conversation as resolved
a3thakra reviewed 2021-08-18 18:46:22 -04:00
@ -0,0 +58,4 @@
const events = (
await Promise.all(
(
await getEventsByTerm(context.params.year, context.params.term)
Owner

This is a lot of nesting, can you move this to a separate line, and bind that to a variable?

This is a lot of nesting, can you move this to a separate line, and bind that to a variable?
j285he marked this conversation as resolved
a3thakra reviewed 2021-08-18 18:49:46 -04:00
@ -0,0 +2,4 @@
margin: auto;
margin-top: 7rem;
margin-bottom: 14rem;
width: 50rem;
Owner

Can you convert these rem values to pixels? Using the calc(<value in px>rem / 16) method that we use everywhere.

Can you convert these rem values to pixels? Using the `calc(<value in px>rem / 16)` method that we use everywhere.
j285he marked this conversation as resolved
a3thakra reviewed 2021-08-18 18:50:00 -04:00
@ -0,0 +16,4 @@
}
.miniEventCards {
margin-top: 30px;
Owner

This should be in rems

This should be in rems
j285he marked this conversation as resolved
a3thakra reviewed 2021-08-18 18:51:31 -04:00
@ -0,0 +86,4 @@
};
}
const Term = (props: Props) => {
Owner

In all the other files, we place the react component at the top of the file, we should do that here too, for consistency. Also you can use export default function Term(props: Props) {...} syntax here, instead of the anonymous function.

In all the other files, we place the react component at the top of the file, we should do that here too, for consistency. Also you can use `export default function Term(props: Props) {...}` syntax here, instead of the anonymous function.
j285he marked this conversation as resolved
j285he added 2 commits 2021-08-19 11:04:37 -04:00
j285he added 2 commits 2021-08-22 15:05:36 -04:00
continuous-integration/drone/push Build is passing Details
3a6f799538
Optimize getStaticPaths
j285he added 2 commits 2021-08-23 20:16:08 -04:00
j285he added 1 commit 2021-08-23 20:20:29 -04:00
continuous-integration/drone/push Build is passing Details
24885e5185
Add margin-bottom for terms
a3thakra added 1 commit 2021-08-23 22:21:30 -04:00
continuous-integration/drone/push Build is passing Details
2abc7e75c1
PR fixes
j285he added 1 commit 2021-08-23 23:31:29 -04:00
continuous-integration/drone/push Build is failing Details
8d59ae1692
Add getNextTerm, getPreviousTerm
a3thakra added 1 commit 2021-08-27 16:04:33 -04:00
continuous-integration/drone/push Build is passing Details
24a237a8c6
Add header functionality (#183)
Co-authored-by: Jared He <66887902+jaredjhe@users.noreply.github.com>
Co-authored-by: Aditya Thakral <a3thakra@csclub.uwaterloo.ca>
Reviewed-on: #183
Co-authored-by: j285he <j285he@localhost>
Co-committed-by: j285he <j285he@localhost>
a3thakra approved these changes 2021-08-27 16:11:36 -04:00
a3thakra merged commit e548bd9c5a into main 2021-08-27 16:14:55 -04:00
a3thakra deleted branch feat/events-term 2021-08-27 16:15:33 -04:00
j285he referenced this issue from a commit 2021-08-27 18:37:44 -04:00
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: www/www-new#158
No description provided.