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

Refactor controls into separate components #59

Merged
merged 13 commits into from
Apr 3, 2024

Conversation

aganders3
Copy link
Collaborator

@aganders3 aganders3 commented Mar 30, 2024

This is a big refactor, but I think it will help with implementing @clarsen-czi's designs.

I think this has feature-parity with main, but could definitely use some testing. Obviously the appearance is slightly different, but if anything I think this already removes some irrelevant code (updating render width/height) and is a bit closer to the behavior we want (canvas fills its allotted space).

To make things more palatable I propose refining and merging this, then we can use the mui classes like Grid or Drawer to move the control groups into place for the new design.

Copy link

vercel bot commented Mar 30, 2024

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

Name Status Preview Comments Updated (UTC)
points-web-viewer ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 3, 2024 4:12pm

@aganders3
Copy link
Collaborator Author

I'm marking this ready for review, given it has been helpful for me in #60.

@aganders3 aganders3 requested a review from andy-sweet April 2, 2024 16:58
@aganders3 aganders3 changed the title [WIP] Refactor controls into separate components Refactor controls into separate components Apr 2, 2024
@aganders3 aganders3 requested a review from codemonkey800 April 2, 2024 16:58
@aganders3 aganders3 linked an issue Apr 2, 2024 that may be closed by this pull request
}

export default function PlaybackControls(props: PlaybackControlsProps) {
return (
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this an example of a dumb component? I.e. state is passed through, it uses it for rendering/presentation, and it calls the necessary setters. But it doesn't contain any logic/effects of its own?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah I think so! Now that you mention that though I feel perhaps this should take (optional?) props for onClick, etc. instead of requiring specific value setters. What do you think? I can try to look if there's some convention for this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

As a general rule, I tend to prefer avoiding optionals if possible. Do you think this might make it easier to reuse?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, and it would be more flexible. The parent (smart component) would be able to take additional actions in onClick aside from just setting a value.

My thinking on being optional is that it would be closer to how a basic <Button/> might work, but I'm okay either way on that. I don't think they need to be optional without a specific use case in mind.

Choose a reason for hiding this comment

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

this looks really good for a "dumb" component, nice job 🫡

as for whether a prop should be optional, I think it entirely depends on if the component is meant to work in a context where it doesn't need that prop

for example, buttons can be used for submitting forms using the type="submit" prop, so it wouldn't need an onclick event handler in that context. additionally, Material UI buttons can also function as links, so it's not required if passing in a href prop:

<Button href="#text-buttons">Link</Button>

src/components/app.tsx Outdated Show resolved Hide resolved
src/components/scene.tsx Outdated Show resolved Hide resolved
Copy link
Collaborator

@andy-sweet andy-sweet left a comment

Choose a reason for hiding this comment

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

Generally love how these changes look. Plus it's nice to take a step towards the desired layout.

The only reason that I'm requesting changes is that selection seems to be broken.

@andy-sweet
Copy link
Collaborator

I also get a healthy horizontal scroll bar in Chrome and Safari regardless of window size or display.

Screenshot 2024-04-02 at 14 36 28

Copy link
Collaborator

@andy-sweet andy-sweet left a comment

Choose a reason for hiding this comment

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

This looks good enough to merge now. Overall, it feels a lot more organized and understandable than main too. I just had a couple of minor optional comments.

Also, good catch on finding the problem with using refs in useEffect! Ideally, I'd still like PointCanvas to be non-nullable in which case it doesn't need to be React state at all, but still not sure how best to do that, so let's leave that for the future.

@aganders3
Copy link
Collaborator Author

Thanks! I'll merge this shortly and rebase #60 on main after.

I'd still like PointCanvas to be non-nullable in which case it doesn't need to be React state at all, but still not sure how best to do that, so let's leave that for the future.

I agree - I'll give this some thought. I think there's probably a way to get rid of the onMount style useEffects we have. Maybe this can be fixed as part of changing the selection method.

@aganders3 aganders3 force-pushed the refactor-component-structure branch from be507a9 to c87b62d Compare April 3, 2024 16:11
@aganders3 aganders3 merged commit 603334c into main Apr 3, 2024
3 checks passed
Copy link

@codemonkey800 codemonkey800 left a comment

Choose a reason for hiding this comment

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

left a couple of comments but overall LGTM so awesome work 💪

}

export default function PlaybackControls(props: PlaybackControlsProps) {
return (

Choose a reason for hiding this comment

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

this looks really good for a "dumb" component, nice job 🫡

as for whether a prop should be optional, I think it entirely depends on if the component is meant to work in a context where it doesn't need that prop

for example, buttons can be used for submitting forms using the type="submit" prop, so it wouldn't need an onclick event handler in that context. additionally, Material UI buttons can also function as links, so it's not required if passing in a href prop:

<Button href="#text-buttons">Link</Button>

const numTimes = props.trackManager?.points.shape[0] ?? 0;
const trackLengthPct = numTimes ? (props.trackHighlightLength / 2 / numTimes) * 100 : 0;

console.log("trackLengthPct: %s", props.trackManager?.maxPointsPerTimepoint);

Choose a reason for hiding this comment

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

nit: remove console.log unless you want to keep it here 🤣

Copy link
Collaborator Author

@aganders3 aganders3 Apr 3, 2024

Choose a reason for hiding this comment

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

Good point. I should make a whole PR to clean up our logging or at least move it to debug 😵‍💫.

@aganders3 aganders3 deleted the refactor-component-structure branch April 17, 2024 18:14
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.

Loading indicator causes layout shift
3 participants