Skip to content

Commit 0955007

Browse files
authored
feat: landing page (#83)
1 parent 6fec50a commit 0955007

27 files changed

+261
-181
lines changed

src/App.routes.tsx

Lines changed: 39 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { AccountPage, accountPageTitle } from './features/accounts/pages/account
1212
import { AssetPage, assetPageTitle } from './features/assets/pages/asset-page'
1313
import { ApplicationPage, applicationPageTitle } from './features/applications/pages/application-page'
1414
import { SettingsPage } from './features/settings/pages/settings-page'
15+
import { TxPage } from './features/transactions/pages/tx-page'
1516

1617
export const routes = evalTemplates([
1718
{
@@ -25,67 +26,53 @@ export const routes = evalTemplates([
2526
children: [
2627
{
2728
template: Urls.Index,
28-
element: (
29-
<div>
30-
<h1 className="font-bold">Home</h1>
31-
</div>
32-
),
29+
element: <ExplorePage />,
30+
errorElement: <ErrorPage title={explorePageTitle} />,
3331
},
3432
{
35-
template: Urls.Explore,
36-
errorElement: <ErrorPage />,
33+
template: Urls.Transaction.ById,
34+
errorElement: <ErrorPage title={transactionPageTitle} />,
3735
children: [
3836
{
39-
template: Urls.Explore,
40-
element: <ExplorePage />,
41-
errorElement: <ErrorPage title={explorePageTitle} />,
37+
template: Urls.Transaction.ById,
38+
element: <TransactionPage />,
4239
},
4340
{
44-
template: Urls.Explore.Transaction.ById,
45-
errorElement: <ErrorPage title={transactionPageTitle} />,
46-
children: [
47-
{
48-
template: Urls.Explore.Transaction.ById,
49-
element: <TransactionPage />,
50-
},
51-
{
52-
template: Urls.Explore.Transaction.ById.Inner.ById,
53-
element: <InnerTransactionPage />,
54-
},
55-
],
56-
},
57-
{
58-
template: Urls.Explore.Block.ByRound,
59-
children: [
60-
{
61-
template: Urls.Explore.Block.ByRound,
62-
errorElement: <ErrorPage title={blockPageTitle} />,
63-
element: <BlockPage />,
64-
},
65-
{
66-
template: Urls.Explore.Block.ByRound.Group.ById,
67-
errorElement: <ErrorPage title={groupPageTitle} />,
68-
element: <GroupPage />,
69-
},
70-
],
71-
},
72-
{
73-
template: Urls.Explore.Account.ByAddress,
74-
element: <AccountPage />,
75-
errorElement: <ErrorPage title={accountPageTitle} />,
41+
template: Urls.Transaction.ById.Inner.ById,
42+
element: <InnerTransactionPage />,
7643
},
44+
],
45+
},
46+
{
47+
template: Urls.Block.ByRound,
48+
children: [
7749
{
78-
template: Urls.Explore.Asset.ById,
79-
element: <AssetPage />,
80-
errorElement: <ErrorPage title={assetPageTitle} />,
50+
template: Urls.Block.ByRound,
51+
errorElement: <ErrorPage title={blockPageTitle} />,
52+
element: <BlockPage />,
8153
},
8254
{
83-
template: Urls.Explore.Application.ById,
84-
errorElement: <ErrorPage title={applicationPageTitle} />,
85-
element: <ApplicationPage />,
55+
template: Urls.Block.ByRound.Group.ById,
56+
errorElement: <ErrorPage title={groupPageTitle} />,
57+
element: <GroupPage />,
8658
},
8759
],
8860
},
61+
{
62+
template: Urls.Account.ByAddress,
63+
element: <AccountPage />,
64+
errorElement: <ErrorPage title={accountPageTitle} />,
65+
},
66+
{
67+
template: Urls.Asset.ById,
68+
element: <AssetPage />,
69+
errorElement: <ErrorPage title={assetPageTitle} />,
70+
},
71+
{
72+
template: Urls.Application.ById,
73+
errorElement: <ErrorPage title={applicationPageTitle} />,
74+
element: <ApplicationPage />,
75+
},
8976
{
9077
template: Urls.AppStudio,
9178
element: <div>App Studio</div>,
@@ -94,6 +81,10 @@ export const routes = evalTemplates([
9481
template: Urls.Settings,
9582
element: <SettingsPage />,
9683
},
84+
{
85+
template: Urls.Tx,
86+
element: <TxPage />,
87+
},
9788
],
9889
},
9990
])

src/features/accounts/components/account-link.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const AccountLink = fixedForwardRef(
2424
<>
2525
<TemplatedNavLink
2626
className={cn(!children && 'text-primary underline', className)}
27-
urlTemplate={Urls.Explore.Account.ByAddress}
27+
urlTemplate={Urls.Account.ByAddress}
2828
urlParams={{ address }}
2929
ref={ref}
3030
{...rest}

src/features/applications/components/application-link.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export function ApplicationLink({ applicationId, className, children }: Props) {
1313
return (
1414
<TemplatedNavLink
1515
className={cn(!children && 'text-primary underline', className)}
16-
urlTemplate={Urls.Explore.Application.ById}
16+
urlTemplate={Urls.Application.ById}
1717
urlParams={{ applicationId: applicationId.toString() }}
1818
>
1919
{children ? children : applicationId}

src/features/assets/components/asset-link.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function Link(props: AssetIdLinkProps | AssetIdAndNameLinkProps) {
4242
<>
4343
<TemplatedNavLink
4444
className={cn(!props.children && 'text-primary underline', props.className)}
45-
urlTemplate={Urls.Explore.Asset.ById}
45+
urlTemplate={Urls.Asset.ById}
4646
urlParams={{ assetId: props.assetId.toString() }}
4747
>
4848
{props.children ? props.children : props.assetId}

src/features/blocks/components/block-link.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export function BlockLink({ round, className, children }: Props) {
1212
return (
1313
<TemplatedNavLink
1414
className={cn(!children && 'text-primary underline', className)}
15-
urlTemplate={Urls.Explore.Block.ByRound}
15+
urlTemplate={Urls.Block.ByRound}
1616
urlParams={{ round: round.toString() }}
1717
>
1818
{children ? children : round}

src/features/common/data/algo-client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Config, getAlgoClient, getAlgoIndexerClient, getAlgoKmdClient } from '@algorandfoundation/algokit-utils'
2-
import { NetworkConfig, localnetConfig, networkConfigAtom } from '../../settings/data/network'
2+
import { NetworkConfig, localnetConfig, networkConfigAtom } from '@/features/settings/data'
33
import { settingsStore } from '@/features/settings/data'
44
import algosdk from 'algosdk'
55

src/features/deep-link/hooks/use-deep-link.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ export function useDeepLink() {
1616
if (options) {
1717
await setSelectedNetwork(options.networkId)
1818
if (options.transactionId) {
19-
navigate(Urls.Explore.Transaction.ById.build({ transactionId: options.transactionId }))
19+
navigate(Urls.Transaction.ById.build({ transactionId: options.transactionId }))
2020
} else {
21-
navigate(Urls.Explore.build({}))
21+
navigate(Urls.Index.build({}))
2222
}
2323
}
2424
},

src/features/explore/pages/explorer-page.test.tsx renamed to src/features/explore/pages/explore-page.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { executeComponentTest } from '@/tests/test-component'
22
import { getAllByRole, getByRole, queryAllByRole, render, waitFor } from '@/tests/testing-library'
33
import { Atom, createStore } from 'jotai'
44
import { describe, expect, it } from 'vitest'
5-
import { ExplorePage } from './explore-page'
5+
import { ExplorePage } from './explore-page.tsx'
66
import { latestBlocksTitle } from '@/features/blocks/components/latest-blocks'
77
import { latestTransactionsTitle } from '@/features/transactions/components/latest-transactions'
88
import { blockResultsAtom, syncedRoundAtom } from '@/features/blocks/data'
@@ -25,7 +25,7 @@ describe('explore-page', () => {
2525
return executeComponentTest(
2626
() => render(<ExplorePage />, undefined, myStore),
2727
async (component) => {
28-
waitFor(() => {
28+
await waitFor(() => {
2929
const latestBlocks = getByRole(component.container, 'heading', { name: latestBlocksTitle })
3030
expect(latestBlocks).toBeDefined()
3131
const container = latestBlocks.parentElement!
@@ -82,7 +82,7 @@ describe('explore-page', () => {
8282
return executeComponentTest(
8383
() => render(<ExplorePage />, undefined, myStore),
8484
async (component) => {
85-
waitFor(() => {
85+
await waitFor(() => {
8686
const latestTransactions = getByRole(component.container, 'heading', { name: latestTransactionsTitle })
8787
expect(latestTransactions).toBeDefined()
8888
const container = latestTransactions.parentElement!

src/features/groups/components/group-link.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export function GroupLink({ round, groupId, short = false, className, children }
1717
return (
1818
<TemplatedNavLink
1919
className={cn(!children && 'text-primary underline', className)}
20-
urlTemplate={Urls.Explore.Block.ByRound.Group.ById}
20+
urlTemplate={Urls.Block.ByRound.Group.ById}
2121
urlParams={{ round: round.toString(), groupId: encodeURIComponent(groupId) }}
2222
>
2323
{children ? children : short ? <abbr title={groupId}>{ellipseId(groupId)}</abbr> : groupId}

src/features/layout/components/left-side-bar-menu.tsx

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import { TemplatedNavLink } from '../../routing/components/templated-nav-link/te
22
import { Urls } from '../../../routes/urls'
33
import { NavigationMenu, NavigationMenuItem, NavigationMenuLink, NavigationMenuList } from '@/features/common/components/navigation-menu'
44
import { cn } from '@/features/common/utils'
5-
import SvgWallet from '@/features/common/components/icons/wallet'
65
import SvgCodeBlock from '@/features/common/components/icons/code-block'
76
import SvgHome from '@/features/common/components/icons/home'
87
import { Button } from '@/features/common/components/button'
98
import SvgChevronLeft from '@/features/common/components/icons/chevron-left'
10-
import { useCallback } from 'react'
9+
import { useCallback, useMemo } from 'react'
1110
import SvgChevronRight from '@/features/common/components/icons/chevron-right'
1211
import SvgCog from '@/features/common/components/icons/cog'
1312
import { useLayout } from '@/features/settings/data'
13+
import { useLocation } from 'react-router-dom'
1414

1515
type Props = {
1616
className?: string
@@ -19,7 +19,6 @@ type Props = {
1919
export function LeftSideBarMenu({ className }: Props) {
2020
const menuItems = [
2121
{ urlTemplate: Urls.Index, icon: <SvgHome />, text: 'Home' },
22-
{ urlTemplate: Urls.Explore, icon: <SvgWallet />, text: 'Explore' },
2322
{ urlTemplate: Urls.AppStudio, icon: <SvgCodeBlock />, text: 'App Studio' },
2423
{ urlTemplate: Urls.Settings, icon: <SvgCog />, text: 'Settings' },
2524
]
@@ -30,6 +29,21 @@ export function LeftSideBarMenu({ className }: Props) {
3029
[setLayout]
3130
)
3231

32+
// The little hack to make the index (root) menu item active when transaction, block, account, asset, application are viewed
33+
// This needs to be done because React router doesn't match the root URL with any sub-path
34+
// The doc: https://reactrouter.com/en/main/components/nav-link#end
35+
const location = useLocation()
36+
const isIndexActive = useMemo(() => {
37+
const forceMatchWithIndex = [
38+
Urls.Transaction.build({}),
39+
Urls.Block.build({}),
40+
Urls.Account.build({}),
41+
Urls.Asset.build({}),
42+
Urls.Application.build({}),
43+
]
44+
return forceMatchWithIndex.some((path) => location.pathname.startsWith(path))
45+
}, [location.pathname])
46+
3347
return (
3448
<NavigationMenu
3549
className={cn('bg-card transition-all duration-300 min-h-screen', className, layout.isLeftSideBarExpanded ? 'w-52' : 'w-10')}
@@ -45,7 +59,10 @@ export function LeftSideBarMenu({ className }: Props) {
4559
<NavigationMenuLink asChild>
4660
<TemplatedNavLink
4761
urlTemplate={menuItem.urlTemplate}
48-
className={cn('[&.active]:text-primary flex items-center p-2 gap-2 min-h-10 pl-3 whitespace-nowrap')}
62+
className={cn(
63+
'[&.active]:text-primary flex items-center p-2 gap-2 min-h-10 pl-3 whitespace-nowrap',
64+
menuItem.urlTemplate === Urls.Index && isIndexActive ? 'active' : ''
65+
)}
4966
>
5067
<div className={cn('text-primary')}>{menuItem.icon}</div>
5168
<div className={cn(layout.isLeftSideBarExpanded ? 'visible delay-100' : 'invisible delay-100')}>{menuItem.text}</div>

0 commit comments

Comments
 (0)