Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QOL for frontend, information-rich landing. #73

Merged
merged 6 commits into from
Mar 4, 2022
Merged

Conversation

krashanoff
Copy link
Collaborator

@krashanoff krashanoff commented Mar 3, 2022

Adds a new view to the frontend, <Me /> to summarize all information for both students and professors, conditionally rendering based on their permissions. It has some boilerplate in it right now, but if the database is populated, it should render right.

Additionally, fixes a bug in SignUpForm.tsx and makes a few small QOL changes to enforce some pet peeves with ESLint. Specifically, yoda, eqeqeq, and react/jsx-key.

Changes

  • Strict ESLint.
  • Flatten route declarations in App.tsx.
  • Add Me.tsx, combining the important bits of ClassView + ClassListView + AssignmentView. This page generates based on the /class/me endpoint.
  • Better API declarations. Generated dynamically through two handy functions in api.ts.

API Example

Writing a new API function is really easy. You just call either authorized<T, R>() or unauthorized<T, R>(). Both generate functions of the following forms, respectively:

export type AuthorizedEndpoint<P, R> = (
  token: string,
  params: P,
  onSuccess: (result: R) => void,
  onFailure: (error: Error) => void
) => void;

export type UnauthorizedEndpoint<P, R> = (
  params: P,
  onSuccess: (result: R) => void,
  onFailure: (error: Error) => void
) => void;

Here is the declaration of the createClass binding:

/**
 * Get information about a student.
 */
export const getMe = authorized<null, UserInformation>(
  () => [`/class/me`, null],
  200,
  true,
  "get"
);

And here's an example of using it from Me.tsx:

// Make a request on component mount to fetch user information.
useEffect(() => {
  getMe(
    cookies.jwt,
    null,
    (data) => setData(data),
    (newErr) => setErrors((errors) => [newErr, ...errors])
  );
}, [cookies.jwt]);

Screenshots

Student View

limited ui

Professor View

administrative ui

View

out.mp4

* Strict ESLint.
* Flatten route declarations in App.tsx.
* Add Me.tsx, combining the important bits of ClassView + ClassListView + AssignmentView.
* Make request against /class/me on load.
@krashanoff krashanoff added bug Something isn't working frontend labels Mar 3, 2022
@krashanoff krashanoff requested a review from cindyrzheng March 3, 2022 01:30
@krashanoff
Copy link
Collaborator Author

Alright, it's coding time.

@krashanoff krashanoff merged commit a4ba738 into main Mar 4, 2022
@krashanoff krashanoff deleted the leo/me-view branch March 4, 2022 10:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working frontend
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant