Skip to content

Commit

Permalink
AK-14 - Added page titles
Browse files Browse the repository at this point in the history
  • Loading branch information
lempira committed Oct 30, 2024
1 parent 794eba8 commit aea00cd
Show file tree
Hide file tree
Showing 14 changed files with 76 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/features/accounts/pages/account-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { AccountDetails } from '../components/account-details'
import { useCallback } from 'react'
import { PageTitle } from '@/features/common/components/page-title'
import { PageLoader } from '@/features/common/components/page-loader'
import { useTitle } from '@/utils/use-title'

export const accountPageTitle = 'Account'
export const accountInvalidAddressMessage = 'Address is invalid'
Expand All @@ -29,6 +30,7 @@ export function AccountPage() {
const { address } = useRequiredParam(UrlParams.Address)
invariant(isAddress(address), accountInvalidAddressMessage)
const [loadableAccount, refreshAccount, isStale] = useLoadableAccount(address)
useTitle()

const refresh = useCallback(() => {
refreshAccount()
Expand Down
2 changes: 2 additions & 0 deletions src/features/app-interfaces/pages/create-app-interface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { useCreateAppInterface } from '../data'
import { FromAppIdCard } from '../components/create/from-app-id-card'
import { FromDeploymentCard } from '../components/create/from-deployment-card'
import { asError } from '@/utils/error'
import { useTitle } from '@/utils/use-title'

export const createAppInterfacePageTitle = 'Create App Interface'

Expand Down Expand Up @@ -103,6 +104,7 @@ function CreateAppInterfaceInner() {
}

export function CreateAppInterface() {
useTitle('Create App Interface')
return (
<>
<PageTitle title={createAppInterfacePageTitle} />
Expand Down
2 changes: 2 additions & 0 deletions src/features/app-lab/pages/app-lab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import { useAppInterfaces } from '@/features/app-interfaces/data'
import { RenderLoadable } from '@/features/common/components/render-loadable'
import { PageLoader } from '@/features/common/components/page-loader'
import { AppInterfaces } from '@/features/app-interfaces/components/app-interfaces'
import { useTitle } from '@/utils/use-title'

export const appLabPageTitle = 'App Lab'

export function AppLab() {
const [appInterfaces, refreshAppInterfaces] = useAppInterfaces()
useTitle('App Lab')

return (
<>
Expand Down
2 changes: 2 additions & 0 deletions src/features/applications/pages/application-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { is404 } from '@/utils/error'
import { useCallback } from 'react'
import { PageTitle } from '@/features/common/components/page-title'
import { PageLoader } from '@/features/common/components/page-loader'
import { useTitle } from '@/utils/use-title'

const transformError = (e: Error) => {
if (is404(e)) {
Expand All @@ -31,6 +32,7 @@ export function ApplicationPage() {

const applicationId = parseInt(_applicationId, 10)
const [loadableApplication, refreshApplication, isStale] = useLoadableApplication(applicationId)
useTitle()

const refresh = useCallback(() => {
refreshApplication()
Expand Down
2 changes: 2 additions & 0 deletions src/features/assets/pages/asset-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useLoadableAsset } from '../data'
import { useCallback } from 'react'
import { PageTitle } from '@/features/common/components/page-title'
import { PageLoader } from '@/features/common/components/page-loader'
import { useTitle } from '@/utils/use-title'

const transformError = (e: Error) => {
if (is404(e)) {
Expand All @@ -31,6 +32,7 @@ export function AssetPage() {

const assetId = parseInt(_assetId, 10)
const [loadableAsset, refreshAsset, isStale] = useLoadableAsset(assetId)
useTitle()

const refresh = useCallback(() => {
refreshAsset()
Expand Down
2 changes: 2 additions & 0 deletions src/features/blocks/pages/block-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useLoadableBlock } from '../data'
import { isInteger } from '@/utils/is-integer'
import { PageTitle } from '@/features/common/components/page-title'
import { PageLoader } from '@/features/common/components/page-loader'
import { useTitle } from '@/utils/use-title'

const transformError = (e: Error) => {
if (is404(e)) {
Expand All @@ -25,6 +26,7 @@ export const blockInvalidRoundMessage = 'Round is invalid'
export const blockFailedToLoadMessage = 'Block failed to load'

export function BlockPage() {
useTitle()
const { round: _round } = useRequiredParam(UrlParams.Round)
invariant(isInteger(_round), blockInvalidRoundMessage)
const round = parseInt(_round, 10)
Expand Down
5 changes: 5 additions & 0 deletions src/features/explore/pages/explore-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ import { LatestTransactions } from '@/features/transactions/components/latest-tr
import { Switch } from '@/features/common/components/switch'
import { Label } from '@/features/common/components/label'
import { useLiveExplorer } from '@/features/explore/data/live-explorer'
import { useTitle } from '@/utils/use-title'
import { useParams } from 'react-router-dom'
import { Urls } from '@/routes/urls'

Check warning on line 10 in src/features/explore/pages/explore-page.tsx

View workflow job for this annotation

GitHub Actions / Run PR checks / node-ci

'Urls' is defined but never used

export const explorePageTitle = 'Explore'

export function ExplorePage() {
const { showLiveUpdates, setShowLiveUpdates, latestTransactions, latestBlocks } = useLiveExplorer()
const params = useParams()
useTitle('Explore', params)

return (
<>
Expand Down
2 changes: 2 additions & 0 deletions src/features/fund/fund-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import { PageTitle } from '@/features/common/components/page-title'
import { localnetId, useNetworkConfig } from '@/features/network/data'
import { LocalnetFunding } from './components/localnet-funding'
import { DispenserApiFunding } from './components/dispenser-api-funding'
import { useTitle } from '@/utils/use-title'

export const fundPageTitle = 'Fund'
export const fundingNotAvailableMessage = 'Funding is not available on this network.'

export function FundPage() {
const networkConfig = useNetworkConfig()
useTitle('Fund')

const inner =
networkConfig.id === localnetId ? (
Expand Down
2 changes: 2 additions & 0 deletions src/features/groups/pages/group-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { invariant } from '@/utils/invariant'
import { isInteger } from '@/utils/is-integer'
import { PageTitle } from '@/features/common/components/page-title'
import { PageLoader } from '@/features/common/components/page-loader'
import { useTitle } from '@/utils/use-title'

export const groupPageTitle = 'Transaction Group'
export const groupNotFoundMessage = 'Transaction group not found'
Expand All @@ -28,6 +29,7 @@ export function GroupPage() {
const { round: _round } = useRequiredParam(UrlParams.Round)
invariant(isInteger(_round), blockInvalidRoundMessage)
const { groupId } = useRequiredParam(UrlParams.GroupId)
useTitle()

const round = parseInt(_round, 10)
const loadableGroup = useLoadableGroup(groupId, round)
Expand Down
2 changes: 2 additions & 0 deletions src/features/settings/pages/settings-page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { useTitle } from '@/utils/use-title'
import { Settings } from '../components/settings'
import { PageTitle } from '@/features/common/components/page-title'

export const settingsPageTitle = 'Settings'

export function SettingsPage() {
useTitle('Settings')
return (
<>
<PageTitle title={settingsPageTitle} />
Expand Down
2 changes: 2 additions & 0 deletions src/features/transaction-wizard/transaction-wizard-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import { SendTransactionResults } from '@algorandfoundation/algokit-utils/types/
import { AppCallTransaction, TransactionType } from '../transactions/models'
import { GroupSendResults, SendResults } from './components/group-send-results'
import algosdk from 'algosdk'
import { useTitle } from '@/utils/use-title'

export const transactionWizardPageTitle = 'Transaction Wizard'
export const transactionTypeLabel = 'Transaction type'
export const sendButtonLabel = 'Send'

export function TransactionWizardPage() {
const [sendResults, setSendResults] = useState<SendResults | undefined>(undefined)
useTitle('Transaction Wizard')

const renderTransactionResults = useCallback((result: SendTransactionResults, simulateResponse?: algosdk.modelsv2.SimulateResponse) => {
const sentTransactions = asTransactionFromSendResult(result)
Expand Down
2 changes: 2 additions & 0 deletions src/features/transactions/pages/inner-transaction-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { is404 } from '@/utils/error'
import { PageTitle } from '@/features/common/components/page-title'
import { PageLoader } from '@/features/common/components/page-loader'
import { useSplatParam } from '@/features/common/hooks/use-splat-param'
import { useTitle } from '@/utils/use-title'

const transformError = (e: Error) => {
if (is404(e)) {
Expand All @@ -34,6 +35,7 @@ export function InnerTransactionPage() {
invariant(isValidInnerTransactionId(innerTransactionId), `Invalid inner transaction id: ${innerTransactionId}`)

const loadableTransaction = useLoadableInnerTransactionAtom(transactionId, innerTransactionId)
useTitle()

return (
<>
Expand Down
2 changes: 2 additions & 0 deletions src/features/transactions/pages/transaction-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useLoadableTransactionAtom } from '../data'
import { isTransactionId } from '@/utils/is-transaction-id'
import { PageTitle } from '@/features/common/components/page-title'
import { PageLoader } from '@/features/common/components/page-loader'
import { useTitle } from '@/utils/use-title'

const transformError = (e: Error) => {
if (is404(e)) {
Expand All @@ -28,6 +29,7 @@ export function TransactionPage() {
const { transactionId } = useRequiredParam(UrlParams.TransactionId)
invariant(isTransactionId(transactionId), transactionInvalidIdMessage)
const loadableTransaction = useLoadableTransactionAtom(transactionId)
useTitle()

return (
<>
Expand Down
47 changes: 47 additions & 0 deletions src/utils/use-title.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { useEffect } from 'react'
import { useParams } from 'react-router-dom'

const setTitle = (title: string) => {
document.title = title
}

export const useTitle = (customString?: string) => {
const urlParams = useParams()
useEffect(() => {
const currentTitle = document.title
let pageTitle = `Lora`
if (customString) {
pageTitle += ` ${customString}`
}
if (urlParams.transactionId) {
pageTitle += ` - TxnId:${urlParams.transactionId}`
}
if (urlParams.transactionId && urlParams['*']) {
pageTitle += `, Inner:${urlParams['*']}`
}
if (urlParams.round) {
pageTitle += ` - Block:${urlParams.round}`
}
if (urlParams?.groupId) {
pageTitle += ` - Group:${urlParams.groupId}`
}
if (urlParams?.address) {
pageTitle += ` - Addr:${urlParams.address}`
}
if (urlParams?.applicationId) {
pageTitle += ` - AppId:${urlParams.applicationId}`
}
if (urlParams?.assetId) {
pageTitle += ` - AssetId:${urlParams.assetId}`
}
if (urlParams?.networkId) {
pageTitle += ` - ${urlParams.networkId}`
}

setTitle(pageTitle)

return () => {
setTitle(currentTitle)
}
}, [customString, urlParams])
}

0 comments on commit aea00cd

Please sign in to comment.