From 94c7badb714fab998ecdd2a1733e2e1504a3e101 Mon Sep 17 00:00:00 2001 From: rare-magma Date: Tue, 27 Aug 2024 22:12:46 +0200 Subject: [PATCH] feat: save currently open budget in browser history Signed-off-by: rare-magma --- src/components/Budget/BudgetPage.test.tsx | 7 ++++++- .../Budget/__snapshots__/BudgetPage.test.tsx.snap | 6 +++++- src/components/NavBar/NavBar.test.tsx | 7 ++++++- src/components/NavBar/__snapshots__/NavBar.test.tsx.snap | 6 +++++- src/hooks/useMove.ts | 3 +++ 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/components/Budget/BudgetPage.test.tsx b/src/components/Budget/BudgetPage.test.tsx index 7f40be0a..cb1651fb 100644 --- a/src/components/Budget/BudgetPage.test.tsx +++ b/src/components/Budget/BudgetPage.test.tsx @@ -14,9 +14,14 @@ import { undoMock, } from "../../setupTests"; import { BudgetPage } from "./BudgetPage"; +import { BrowserRouter } from "react-router-dom"; describe("BudgetPage", () => { - const comp = ; + const comp = ( + + + + ); it("matches snapshot", () => { render(comp); diff --git a/src/components/Budget/__snapshots__/BudgetPage.test.tsx.snap b/src/components/Budget/__snapshots__/BudgetPage.test.tsx.snap index 28fd2458..082e1d09 100644 --- a/src/components/Budget/__snapshots__/BudgetPage.test.tsx.snap +++ b/src/components/Budget/__snapshots__/BudgetPage.test.tsx.snap @@ -1,3 +1,7 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`BudgetPage > matches snapshot 1`] = ``; +exports[`BudgetPage > matches snapshot 1`] = ` + + + +`; diff --git a/src/components/NavBar/NavBar.test.tsx b/src/components/NavBar/NavBar.test.tsx index 0bbd9f53..cac78230 100644 --- a/src/components/NavBar/NavBar.test.tsx +++ b/src/components/NavBar/NavBar.test.tsx @@ -9,9 +9,14 @@ import { testEmptyBudgetContext, } from "../../setupTests"; import { NavBar } from "./NavBar"; +import { BrowserRouter } from "react-router-dom"; describe("NavBar", () => { - const comp = ; + const comp = ( + + + + ); it("matches snapshot", () => { render(comp); diff --git a/src/components/NavBar/__snapshots__/NavBar.test.tsx.snap b/src/components/NavBar/__snapshots__/NavBar.test.tsx.snap index eea1f24a..09cd93c0 100644 --- a/src/components/NavBar/__snapshots__/NavBar.test.tsx.snap +++ b/src/components/NavBar/__snapshots__/NavBar.test.tsx.snap @@ -1,3 +1,7 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`NavBar > matches snapshot 1`] = ``; +exports[`NavBar > matches snapshot 1`] = ` + + + +`; diff --git a/src/hooks/useMove.ts b/src/hooks/useMove.ts index e1622fa8..31464f81 100644 --- a/src/hooks/useMove.ts +++ b/src/hooks/useMove.ts @@ -1,9 +1,11 @@ +import { useNavigate, useSearchParams } from "react-router-dom"; import { Budget } from "../components/Budget/Budget"; import { SearchOption } from "../components/NavBar/NavBar"; import { useBudget } from "../context/BudgetContext"; export function useMove() { const { budget, setBudget, budgetList } = useBudget(); + const navigate = useNavigate(); function select(selectedBudget: SearchOption[] | undefined) { if (selectedBudget && budgetList) { @@ -22,6 +24,7 @@ export function useMove() { } } }, 100); + navigate(`/${selectedBudget[0].name}`); } }