Skip to content

Commit

Permalink
fix(STK-256): My Stacks not updating correctly (#199)
Browse files Browse the repository at this point in the history
* refactor: update hrefs to consume the pathnames abstraction as SSOT
* feat: reset the stackbox form values and its search params only if the user is on the landing page
* feat: persist chain ID search param on page navigation
  • Loading branch information
ElRodrigote authored Aug 22, 2024
1 parent 6ddb80a commit b48fa30
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 15 deletions.
6 changes: 4 additions & 2 deletions packages/app/app/not-found.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"use client";

import { ButtonLink, HeadingText } from "@/ui";
import Link from "next/link";

import { ButtonLink, HeadingText } from "@/ui";
import { PATHNAMES } from "@/constants";
import StacksImg from "@/public/assets/images/stacks.svg";

export default function NotFound() {
Expand All @@ -24,7 +26,7 @@ export default function NotFound() {
.
</HeadingText>
<div>
<ButtonLink href="/">Go back to homepage</ButtonLink>
<ButtonLink href={PATHNAMES.HOME}>Go back to homepage</ButtonLink>
</div>
</div>
);
Expand Down
3 changes: 2 additions & 1 deletion packages/app/app/stacks/empty-state.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ButtonLink, HeadingText } from "@/ui";
import { EmptyStateStacksImg } from "@/public/assets";
import { PATHNAMES } from "@/constants";

export default function EmptyState() {
return (
Expand All @@ -16,7 +17,7 @@ export default function EmptyState() {
</div>
</div>
<div className="mx-auto w-fit">
<ButtonLink size="lg" href="/" iconLeft="plus">
<ButtonLink size="lg" href={PATHNAMES.HOME} iconLeft="plus">
Create new stack
</ButtonLink>
</div>
Expand Down
7 changes: 6 additions & 1 deletion packages/app/app/stacks/stacksOrders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { ButtonLink, HeadingText } from "@/ui";
import { EmptyState, StacksTable, tabButtonStyles } from "@/components";
import EmptyStatePage from "./empty-state";
import { currentTimestampInSeconds } from "@/utils";
import { PATHNAMES } from "@/constants";

type SortTime = "startTime" | "endTime" | "cancelledAt";

Expand Down Expand Up @@ -183,7 +184,11 @@ export const StackOrders = ({ chainId, address }: StackOrdersProps) => {
</div>
)}
</div>
<ButtonLink iconLeft="plus" href="/" className="hidden sm:flex">
<ButtonLink
iconLeft="plus"
href={PATHNAMES.HOME}
className="hidden sm:flex"
>
Create New Stack
</ButtonLink>
</div>
Expand Down
5 changes: 4 additions & 1 deletion packages/app/components/SelectNetwork.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@
import { Fragment } from "react";
import { ChainIcon } from "connectkit";
import { Listbox, Transition } from "@headlessui/react";
import { usePathname } from "next/navigation";

import { Button, Icon } from "@/ui";
import { useNetworkContext, useStackboxFormContext } from "@/contexts";
import { PATHNAMES } from "@/constants";

export const SelectNetwork = () => {
const { chains, changeNetwork, chainId, selectedChain } = useNetworkContext();
const { resetFormValues } = useStackboxFormContext();
const pathname = usePathname();

return (
<Listbox
value={chainId.toString()}
onChange={(chainId) => {
changeNetwork(parseInt(chainId));
resetFormValues(parseInt(chainId));
if (pathname === PATHNAMES.HOME) resetFormValues(parseInt(chainId));
}}
>
<div className="relative">
Expand Down
8 changes: 5 additions & 3 deletions packages/app/components/navbar/MobileMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"use client";

import { useState } from "react";
import { ConnectButton, SelectNetwork } from "@/components";

import Link from "next/link";

import { Button, Icon } from "@/ui";
import { STACKLY_LANDING_URL } from "@/constants";
import { ConnectButton, SelectNetwork } from "@/components";
import { PATHNAMES, STACKLY_LANDING_URL } from "@/constants";

export default function MobileMenu() {
const [isOpen, setIsOpen] = useState(false);
Expand All @@ -31,7 +33,7 @@ export default function MobileMenu() {
<div className="absolute left-0 w-full gap-2 px-6 py-2 border-b border-solid rounded-lg bg-surface-25 top-nav-height border-surface-75">
<Link
passHref
href="/stacks"
href={PATHNAMES.STACKS}
className="flex items-center py-3 text-em-med"
onClick={toggle}
>
Expand Down
17 changes: 13 additions & 4 deletions packages/app/components/navbar/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
"use client";

import Link from "next/link";
import MobileMenu from "./MobileMenu";
import Logo from "./Logo";

import { ButtonLink } from "@/ui";
import { ConnectButton, SelectNetwork } from "@/components";
import { useNetworkContext } from "@/contexts";
import { PATHNAMES } from "@/constants";

import Logo from "./Logo";
import MobileMenu from "./MobileMenu";

export function Navbar() {
const { chainId } = useNetworkContext();

return (
<header className="top-0 flex flex-col w-full px-4 border-b border-solid h-nav-height bg-surface-25 border-b-surface-75">
<nav className="flex items-center w-full h-full">
<div>
<Link
passHref
tabIndex={0}
href="/"
href={{
pathname: PATHNAMES.HOME,
query: `chainId=${chainId}`,
}}
title="Stackly Home"
className="flex items-center outline-none w-14 md:w-40"
>
Expand All @@ -27,7 +36,7 @@ export function Navbar() {
variant="quaternary"
size="sm"
iconLeft="blocks"
href="/stacks"
href={PATHNAMES.STACKS}
>
Your stacks
</ButtonLink>
Expand Down
3 changes: 2 additions & 1 deletion packages/app/components/stackbox/Stackbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
Token,
frequencySeconds,
} from "@/models";
import { PATHNAMES } from "@/constants";

interface SelectTokenButtonProps {
label: string;
Expand Down Expand Up @@ -619,7 +620,7 @@ export const Stackbox = () => {
<Link
passHref
className="flex items-center space-x-0.5 hover:border-em-low border-b-2 border-em-disabled group"
href="/stacks"
href={PATHNAMES.STACKS}
onClick={() => closeModal(ModalId.SUCCESS_STACK_TOAST)}
>
<BodyText className="text-em-med">View your stacks</BodyText>
Expand Down
1 change: 1 addition & 0 deletions packages/app/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./urls";
export * from "./pathnames";
4 changes: 4 additions & 0 deletions packages/app/constants/pathnames.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const PATHNAMES = {
HOME: "/",
STACKS: "/stacks",
};
12 changes: 10 additions & 2 deletions packages/app/ui/buttons/ButtonLink.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
"use client";

import Link from "next/link";
import { ButtonBaseProps, buttonStyles, getIconSize } from "./base";

import { Icon } from "@/ui/icon/Icon";
import { useNetworkContext } from "@/contexts";

import { ButtonBaseProps, buttonStyles, getIconSize } from "./base";

interface ButtonLinkProps extends ButtonBaseProps {
href: string;
Expand All @@ -25,10 +28,15 @@ export function ButtonLink({
passHref,
target,
}: ButtonLinkProps) {
const { chainId } = useNetworkContext();

return (
<Link
id={id}
href={href}
href={{
pathname: href,
query: `chainId=${chainId}`,
}}
tabIndex={0}
className={buttonStyles({
size,
Expand Down

0 comments on commit b48fa30

Please sign in to comment.