Skip to content

Commit

Permalink
feat: save currently open budget in browser history
Browse files Browse the repository at this point in the history
Signed-off-by: rare-magma <[email protected]>
  • Loading branch information
rare-magma committed Aug 27, 2024
1 parent a1e036e commit 94c7bad
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/components/Budget/BudgetPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ import {
undoMock,
} from "../../setupTests";
import { BudgetPage } from "./BudgetPage";
import { BrowserRouter } from "react-router-dom";

describe("BudgetPage", () => {
const comp = <BudgetPage />;
const comp = (
<BrowserRouter>
<BudgetPage />
</BrowserRouter>
);

it("matches snapshot", () => {
render(comp);
Expand Down
6 changes: 5 additions & 1 deletion src/components/Budget/__snapshots__/BudgetPage.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`BudgetPage > matches snapshot 1`] = `<BudgetPage />`;
exports[`BudgetPage > matches snapshot 1`] = `
<BrowserRouter>
<BudgetPage />
</BrowserRouter>
`;
7 changes: 6 additions & 1 deletion src/components/NavBar/NavBar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ import {
testEmptyBudgetContext,
} from "../../setupTests";
import { NavBar } from "./NavBar";
import { BrowserRouter } from "react-router-dom";

describe("NavBar", () => {
const comp = <NavBar />;
const comp = (
<BrowserRouter>
<NavBar />
</BrowserRouter>
);

it("matches snapshot", () => {
render(comp);
Expand Down
6 changes: 5 additions & 1 deletion src/components/NavBar/__snapshots__/NavBar.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`NavBar > matches snapshot 1`] = `<NavBar />`;
exports[`NavBar > matches snapshot 1`] = `
<BrowserRouter>
<NavBar />
</BrowserRouter>
`;
3 changes: 3 additions & 0 deletions src/hooks/useMove.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -22,6 +24,7 @@ export function useMove() {
}
}
}, 100);
navigate(`/${selectedBudget[0].name}`);
}
}

Expand Down

0 comments on commit 94c7bad

Please sign in to comment.