Skip to content

Commit

Permalink
fix: multiple page title display fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nicov-iov committed Oct 10, 2024
1 parent 8352193 commit 855236d
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
47 changes: 46 additions & 1 deletion src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,54 @@ function isAddressPath ({ path }, address) {
return `/${r.address}/${address}` === path
}

function addHashTag (str) {
return `#${str}`
}

function formatParam (paramName, value) {
console.log({ paramName, value })
let formattedParam = value
const isNumber = paramName === 'number'
const isHash = typeof value === 'string' && value.includes('0x')

if (isNumber) {
// prexix hashtag # to numbers
formattedParam = addHashTag(formattedParam)
console.log({ addHashTagAplied: true, formattedParam })
} else if (isHash) {
// shorten hashes
formattedParam = shortenHash(formattedParam)
console.log({ shortenHashAplied: true, formattedParam })
}

return formattedParam
}

function shortenHash (input) {
// works for addresses, blockHashes and txHashes
const regex = /(0x[a-fA-F0-9]{40,64})/g

if (regex.test(input)) {
// return shortened hash
return input.replace(regex, function (match) {
return match.substr(0, 6) + '...' + match.substr(-4)
})
} else {
// If no matches, return original input
return input
}
}

function getPageTitleFromRoute (route) {
const { name, params } = route
return name + ' - ' + Object.values(params).join(',')
const paramsEntries = Object.entries(params)

if (paramsEntries.length) {
const formattedParams = paramsEntries.map(([paramName, value]) => formatParam(paramName, value))
return `${name} ${formattedParams.join(' - ')}`
} else {
return name
}
}

export default router
2 changes: 1 addition & 1 deletion src/router/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default [
},
{
path: '/apps',
name: 'apps',
name: 'Apps',
component: AppsView
}
]
4 changes: 3 additions & 1 deletion src/store/getters.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ export const getPageTitle = (state, getters) => page => {
title = appName
}

if (page) title += ` - ${page}`
if (page && !page.includes('Home')) {
title = `${page} | ${title}`
}
return title
}

0 comments on commit 855236d

Please sign in to comment.