Closed selankon closed 4 months ago
🚀 Deployed on https://667aecf105f2362afbb7a43f--vocdoni-app-dev.netlify.app
🚀 Deployed on https://667aecef3ba8772ec7773f4c--onvote-stg.netlify.app
🚀 Deployed on https://667aecf305f2362afbb7a447--vocdoni-app-stg.netlify.app
FTR if we would like to centraliza all on an only one hook/component that just change the title, and dinamically check if is inside an election context or organization context to set the title, i did this approach which is not finished but can be used as inspiration if we need to do it on the future
export function useDocumentTitle(title?: string) {
const defaultTitleRef = useRef(document.title)
const electionCtx = useContext(ElectionContext)
const orgCtx = useContext(OrganizationContext)
useEffect(() => {
const isOnvote = import.meta.env.theme === 'onvote'
let prepend = 'Vocdoni'
// Vocdoni - The voice of digital voting
// Anonymous Gasless and Modular voting for Web3
let title = 'The voice of digital voting'
if (isOnvote) {
title = defaultTitleRef.current
prepend = 'OnVote'
}
if (electionCtx && electionCtx.election instanceof PublishedElection) {
title = electionCtx.election?.title.default
} else if (orgCtx && orgCtx.organization) {
title = orgCtx.organization?.account.name.default ?? orgCtx.organization?.address ?? ''
}
document.title = `${prepend} - ${title}`
return () => {
document.title = defaultTitleRef.current
}
}, [electionCtx, orgCtx, title])
}
I see a problem here... navigating through pages maintains one of the first titles set (?)
To reproduce:
* Go to your organization, you'll se the title change * Access a process, the title changes again * Go to the home page, the title remains with the election name (?)
I can still reproduce this 😕
Edit: I do now realize this is normal considering how you've done the logic... IMHO the original title should be hardcoded and used when no other options are there, rather than trying to store the current page title, which is causing these weird behaviors.
Fixes https://github.com/vocdoni/ui-scaffold/issues/614
It changes the document title on certain pages using the
useDocumentTitle
hook.When the hook is unmounted it goes back to the default page title