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

UI Scroll layout for the graphs #242

Merged
merged 7 commits into from
Jan 9, 2025
Merged

Conversation

gabrielegranello
Copy link
Collaborator

What does this PR do?

It sets a series of scrollable layouts for where the graphs are going to live.
The scrolling occurs between GraphCard1 and GraphCard6, which will show the different graphs and text.

Screen.Recording.2025-01-08.at.15.41.38.mov

Copy link

vercel bot commented Jan 8, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
fairhold-dashboard ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 9, 2025 8:57am

Copy link
Contributor

@DafyddLlyr DafyddLlyr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Video looks great! 👏

In terms of implementation, if we want to make a change to layout or styling we now need to make it in 6 places and keep things in parallel - this is super hard and an easy way to introduce mistakes and inconsistencies.

I'd recommend having a crack at pattern like this -

  • A single GraphCard component
  • It accepts a title prop
  • It accepts children (ie the "content" / graphs - have a look at React.PropsWithChildren)
  • It's responsible for layout, next button, scroll, title etc - but not the actual content

import { Household } from "@/app/models/Household";

interface DashboardProps {
data: Household;
}

const Dashboard: React.FC<DashboardProps> = ({ data }) => {
const handleNext = () => {
const container = document.querySelector(".snap-scroll") as HTMLElement;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be aiming to use ref in React instead of calling native DOM functionality like this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this version look better? Sorry I wasn't familiar with the children concept , it seems pretty powerful.
If I understand it correctly, it means I can pass other optional React components to the card. For example, I could pass a title AND a graph, or a title AND a section. So the basically the GraphCard component should provide the 'scrollability feature' and render the content that is passed to it, is that correct?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect! Super quick turnaround 🏅

Copy link
Contributor

@DafyddLlyr DafyddLlyr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One small question about identity() - but this is great!

Comment on lines 20 to 24
// Dummy identity function to avoid linting errors
const identity = (data: Household) => {
return data;
};
identity(data);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really follow what this is for sorry!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry, it was a trick to avoid listing errors. We are passing data to the Dashboard component. That makes sense because data will be necessary to generate the plots in the future.
The problem is that right now we are doing nothing with it, so it flags an error of a variable not being used. So I created a function that returns itself for the moment to get around it. I considered passing a plot to one of the Card, but I figured it would be better to be a separate PR

Copy link
Contributor

@DafyddLlyr DafyddLlyr Jan 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right! That makes sense - thanks for the explanation 👍

There's an easy option here! We can add // eslint-disable-next-line <RULE_NAME> as a comment to the line above an unused variable we want to keep and it should resolve this issue.

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const someUnusedVariable = 123

Docs: https://eslint.org/docs/latest/use/configure/rules#disabling-rules

import { Household } from "@/app/models/Household";

interface DashboardProps {
data: Household;
}

const Dashboard: React.FC<DashboardProps> = ({ data }) => {
const handleNext = () => {
const container = document.querySelector(".snap-scroll") as HTMLElement;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect! Super quick turnaround 🏅

Copy link
Contributor

@DafyddLlyr DafyddLlyr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry just noticed one small thing!

Comment on lines 43 to 48
<button
onClick={handleNext}
className="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600"
>
Next
</button>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just realised - this currently remains visible on the final card.

A few ways we could handle this - a quick/simple version might be to just to track the index of the pages on handleNext(), and hide for the final one.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion! Hopefully this will do

Copy link
Collaborator Author

@gabrielegranello gabrielegranello Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screen.Recording.2025-01-09.at.09.57.41.mov

Copy link
Contributor

@DafyddLlyr DafyddLlyr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

@gabrielegranello gabrielegranello merged commit 5313afb into main Jan 9, 2025
5 checks passed
@gabrielegranello gabrielegranello deleted the gg/ui-graph-layout branch January 9, 2025 09:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants