Skip to content

Commit

Permalink
replace instead of push route when changing tabs for more intuitive n…
Browse files Browse the repository at this point in the history
…avigation
  • Loading branch information
geekflyer committed Jun 30, 2023
1 parent d7b3fe0 commit 06d46fc
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 15 deletions.
11 changes: 2 additions & 9 deletions src/components/GoBack.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as React from "react";
import Button from "@mui/material/Button";
import ArrowBackRoundedIcon from "@mui/icons-material/ArrowBackRounded";
import {useNavigate} from "../routing";
Expand Down Expand Up @@ -29,20 +28,14 @@ type GoBackProps = {
to?: string;
};

export default function GoBack({to}: GoBackProps): JSX.Element | null {
export default function GoBack(): JSX.Element | null {
const navigate = useNavigate();

if (window.history.state && window.history.state.idx > 0) {
return BackButton(() => {
navigate(-1);
});
} else {
if (to != null) {
return BackButton(() => {
navigate(to);
});
} else {
return null;
}
return null;
}
}
2 changes: 1 addition & 1 deletion src/pages/Account/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export default function AccountTabs({
}

const handleChange = (event: React.SyntheticEvent, newValue: TabValue) => {
navigate(`/account/${address}/${newValue}`);
navigate(`/account/${address}/${newValue}`, {replace: true});
};

return (
Expand Down
1 change: 1 addition & 0 deletions src/pages/Account/Tabs/ModulesTab/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ function ModulesTabs({address}: {address: string}): JSX.Element {
navigate(
`/account/${address}/modules/${newValue}/${selectedModuleName}` +
(selectedFnName ? `/${selectedFnName}` : ``),
{replace: true},
);
};

Expand Down
2 changes: 1 addition & 1 deletion src/pages/Block/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default function BlockTabs({
const value = tab === undefined ? TAB_VALUES[0] : (tab as TabValue);

const handleChange = (event: React.SyntheticEvent, newValue: TabValue) => {
navigate(`/block/${height}/${newValue}`);
navigate(`/block/${height}/${newValue}`, {replace: true});
};

return (
Expand Down
1 change: 0 additions & 1 deletion src/pages/Token/Index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {useParams} from "react-router-dom";
import {gql, useQuery} from "@apollo/client";
import {Stack, Grid} from "@mui/material";
import React from "react";
import TokenTitle from "./Title";
import TokenTabs from "./Tabs";
import PageHeader from "../layout/PageHeader";
Expand Down
4 changes: 3 additions & 1 deletion src/pages/Token/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ export default function TokenTabs({
const value = tab === undefined ? TAB_VALUES[0] : (tab as TabValue);

const handleChange = (event: React.SyntheticEvent, newValue: TabValue) => {
navigate(`/token/${tokenId}/${propertyVersion}/${newValue}`);
navigate(`/token/${tokenId}/${propertyVersion}/${newValue}`, {
replace: true,
});
};

return (
Expand Down
1 change: 0 additions & 1 deletion src/pages/Transaction/Index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from "react";
import {Stack, Grid, Alert} from "@mui/material";
import {Types} from "aptos";
import {useGlobalState} from "../../global-config/GlobalConfig";
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Transaction/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export default function TransactionTabs({
tab === undefined ? getTabValues(transaction)[0] : (tab as TabValue);

const handleChange = (event: React.SyntheticEvent, newValue: TabValue) => {
navigate(`/txn/${txnHashOrVersion}/${newValue}`);
navigate(`/txn/${txnHashOrVersion}/${newValue}`, {replace: true});
};

return (
Expand Down

0 comments on commit 06d46fc

Please sign in to comment.