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

Managing listPath's impossible null state #37

Merged
merged 5 commits into from
Sep 27, 2024
Merged

Managing listPath's impossible null state #37

merged 5 commits into from
Sep 27, 2024

Conversation

tannaurus
Copy link
Collaborator

@tannaurus tannaurus commented Sep 22, 2024

Description

This fixes two things:

  1. We were handling listPath being string | null in places where it could have been prevented already (re: making impossible states impossible). These changes take the approach of ensuring listPath is not null at the parent route level so that all sub-components don't have to contend with handling an impossible null state.
  2. Fixes a bug where if no list was selected, the List page would render a component that suggested your list was just empty and redirect you to "add items to the list" which, upon being redirected, there was nothing to do (because there was no list to begin with)

Copy link

github-actions bot commented Sep 22, 2024

Visit the preview URL for this PR (updated for commit 74b3e38):

https://tcl-77-smart-shopping-list--pr37-tg-list-path-41vmk85i.web.app

(expires Mon, 30 Sep 2024 23:59:03 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: b77df24030dca7d8b6561cb24957d2273c5e9d72

@tannaurus tannaurus changed the title Managing listPath's possible null state Managing listPath's impossible null state Sep 22, 2024
);
};

if (!listPath) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I see that the Header handles the retruning early if listPath is null or falsy so that the components that require listPath to be defined don't have to do the checks themselves...

I think I am trying to wrap my head around why do that check here in the List & ManageList instead of higher in the App, would it have over complicated the logic or does it make conceptual sense to put it here for both of them?

Copy link
Collaborator Author

@tannaurus tannaurus Sep 23, 2024

Choose a reason for hiding this comment

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

We probably could have made those routes re-direct if listPath was null, but that would be changing existing behavior in the app. We've been displaying these routes + header if there was no listPath, and I didn't want to take the liberty of changing that because I think that should be the team's decision. It could be thought of as part of the project you had mentioned some interest in; there's a good amount of overlap between "what does this look like when you're not-signed in" and "what does it look like when you first sign in"

Might be something worth raising to the team!

Copy link
Collaborator

Choose a reason for hiding this comment

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

That makes total sense, I didn't think about how we have had specific functionality and how that could change the app. Thinking about how the overall process/usage flow of the app is a consideration in where the listPath can be null and can't be.

Copy link
Collaborator

@bbland1 bbland1 left a comment

Choose a reason for hiding this comment

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

I don't think I ever caught the bug in my testing with the list so it is awesome for it to be caught here!

I didn't really know where to put this just a random question: would us using the local storage of the listPath after it is set would this change how all of the passing of the listPath prop is handled?

@@ -8,11 +8,21 @@ interface Props {
}

export function ManageList({ listPath, data }: Props) {
return (
<div>
const Header = () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I like this like internal component usage in creating the header. I've never really done that usually just the full pull out of a component but this is a cool thing to keep top of mind.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I personally do things like this when it's a super simple thing, like a few lines that happen to repeated a few times in a given component. If it becomes any more complex, and especially if there are hooks invalid, it's much butter to move it out of the parent component. When it's this simple though, retaining the context of the parent is really nice (I don't have to name it "ManageListHeader" because it's defined inside "ManageList")

@tannaurus
Copy link
Collaborator Author

I don't think I ever caught the bug in my testing with the list so it is awesome for it to be caught here!

I didn't really know where to put this just a random question: would us using the local storage of the listPath after it is set would this change how all of the passing of the listPath prop is handled?

No sweat! That's actually how I discovered this bug in the first place, I was in the process of unraveling why listPath could be null in the first place. The problem there is "after it is set", we still have to deal with "before its set" which is just unavoidable

@tannaurus tannaurus merged commit 76e18e4 into main Sep 27, 2024
2 checks passed
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.

3 participants