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

Improve Nav Bar & use Wasp Link components #311

Merged
merged 8 commits into from
Nov 15, 2024
Merged

Conversation

vincanger
Copy link
Collaborator

@vincanger vincanger commented Oct 27, 2024

TODO

  • fix navigation item item.to type
  • fix app_diff

Description

Fixes #264 & #181 as well as merges the landing page's navbar and the AppNavBar into one

Contributor Checklist

Make sure to do the following steps if they are applicable to your PR:

@vincanger vincanger marked this pull request as ready for review October 30, 2024 15:10
@vincanger vincanger requested a review from Martinsos October 30, 2024 15:10
@Martinsos
Copy link
Member

@vincanger maybe best to have @infomiho take a look at this since he is the author of Wasp Link stuff?

@vincanger vincanger requested a review from infomiho October 31, 2024 13:59
Copy link
Collaborator

@infomiho infomiho left a comment

Choose a reason for hiding this comment

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

Nice job Vinny, left some comments

import { useMemo } from 'react';
import { useLocation } from 'react-router-dom';

export const useIsLandingPage = () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice job on creating custom hooks :)

@@ -49,7 +53,9 @@ export default function App() {
<Outlet />
) : (
<>
{shouldDisplayAppNavBar && <AppNavBar />}
{shouldDisplayAppNavBar && (
<NavBar navigation={isLandingPage ? landingPageNavigationItems : appNavigationItems} />
Copy link
Collaborator

Choose a reason for hiding this comment

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

One thing you could do here is extract the ternary expresison:

const navigationItems = isLandingPage ? landingPageNavigationItems : appNavigationItems;
...
<NavBar navigation={navigationItems} />

That being said, it looks to me that the navigation prop should be named navigationItems since we are calling all the vars that way xNavigationItems.


const NavLogo = () => <img className='h-8 w-8' src={logo} alt='Your SaaS App' />;

export default function AppNavBar() {
export default function AppNavBar({ navigation }: { navigation: NavigationItem[] }) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd name the navigation prop as navigationItems so it matches the way we use it. navigation feels generic as opposed to navigationItems.

@@ -124,3 +112,28 @@ export default function AppNavBar() {
</header>
);
}

function renderNavigationItems(
navigation: NavigationItem[],
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
navigation: NavigationItem[],
navigationItems: NavigationItem[],


return navigation.map((item) => {
return (
<Link
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd maybe import both Link from wasp/client/router and react-router-dom and use them in different places.

  1. I'd use the import { Link as ReactRouterLink } from 'react-router-dom'; and <ReactRouterLink> component in places where we are having dynamic to prop (in this fn)
  2. I'd use the Wasp's Link elsewhere where we use the to prop explicitly - we get as much out of the type safe component as possible.


const shouldDisplayAppNavBar = useMemo(() => {
return location.pathname !== '/' && location.pathname !== '/login' && location.pathname !== '/signup';
return location.pathname !== '/login' && location.pathname !== '/signup';
Copy link
Collaborator

Choose a reason for hiding this comment

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

To avoid hard-coding values, you could use routes.LoginRoute.build() and routes.SignupRoute.build() to get the routes :)

Copy link
Collaborator

@infomiho infomiho left a comment

Choose a reason for hiding this comment

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

🚢 it!

@vincanger vincanger merged commit a8654e3 into main Nov 15, 2024
1 check 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