Skip to content

Commit

Permalink
refactor: remove "back" usage where not necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
heyqbnk committed Oct 12, 2024
1 parent bd4116d commit beac8b1
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 8 deletions.
8 changes: 5 additions & 3 deletions src/components/Page/Page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
type Component,
createEffect,
createMemo,
type JSX,
type ParentProps,
} from 'solid-js';
Expand All @@ -15,15 +16,17 @@ export interface PageProps extends ParentProps {
disclaimer?: JSX.Element;
/**
* True if it is allowed to go back from this page.
* @default true
*/
back?: boolean;
}

export const Page: Component<PageProps> = (props) => {
const navigate = useNavigate();
const back = createMemo(() => typeof props.back === 'boolean' ? props.back : true);

createEffect(() => {
if (props.back) {
if (back()) {
backButton.show();
return backButton.onClick(() => {
navigate(-1);
Expand All @@ -35,8 +38,7 @@ export const Page: Component<PageProps> = (props) => {
return (
<div class="page">
<h1>{props.title}</h1>
{props.disclaimer &&
<div class="page__disclaimer">{props.disclaimer}</div>}
{props.disclaimer && <div class="page__disclaimer">{props.disclaimer}</div>}
{props.children}
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion src/pages/IndexPage/IndexPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import './IndexPage.css';

export const IndexPage: Component = () => {
return (
<Page title="Home Page">
<Page title="Home Page" back={false}>
<p>
This page is a home page in this boilerplate. You can use the links below to visit other
pages with their own functionality.
Expand Down
1 change: 0 additions & 1 deletion src/pages/InitDataPage/InitDataPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ export const InitDataPage: Component = () => {

return (
<Page
back
title="Init Data"
disclaimer={(
<>
Expand Down
1 change: 0 additions & 1 deletion src/pages/LaunchParamsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export const LaunchParamsPage: Component = () => {

return (
<Page
back
title="Launch Params"
disclaimer={(
<>
Expand Down
1 change: 0 additions & 1 deletion src/pages/ThemeParamsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export const ThemeParamsPage: Component = () => {

return (
<Page
back
title="Theme Params"
disclaimer={(
<>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/TonConnectPage/TonConnectPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const TonConnectPage: Component = () => {
const wallet = useTonWallet();

return (
<Page title="TON Connect" back>
<Page title="TON Connect">
<Show
when={wallet()}
fallback={
Expand Down

0 comments on commit beac8b1

Please sign in to comment.