feat: add support for return back home (#435)
This commit is contained in:
parent
e7d1b1d7d8
commit
b811993b35
|
|
@ -1,5 +1,5 @@
|
|||
import { useRouter } from "next/router"
|
||||
import { useEffect } from "react"
|
||||
import { useEffect, useRef } from "react"
|
||||
|
||||
import {
|
||||
useAccountState,
|
||||
|
|
@ -19,14 +19,38 @@ export default function Dashboard() {
|
|||
])
|
||||
const connectModal = useConnectModal()
|
||||
|
||||
const isConnectModalShown = useRef(false)
|
||||
const isMintCharacterModalShown = useRef(false)
|
||||
|
||||
useEffect(() => {
|
||||
if (ssrReady) {
|
||||
// Wait till SSR is ready
|
||||
if (!isConnected) {
|
||||
connectModal.show()
|
||||
// Wallet not connected
|
||||
if (!isConnectModalShown.current) {
|
||||
// Not shown
|
||||
isConnectModalShown.current = true
|
||||
connectModal.show()
|
||||
} else if (!connectModal.isActive) {
|
||||
// Shown, but closed by user
|
||||
router.push("/") // Go back home
|
||||
}
|
||||
} else if (userSites.isSuccess) {
|
||||
// Wallet is connected, wait till site is ready
|
||||
// Reset connect wallet status to prevent unexpected redirect
|
||||
isConnectModalShown.current = false
|
||||
if (!userSites.data?.length) {
|
||||
walletMintNewCharacterModal.show()
|
||||
// No character found, prompt to mint one
|
||||
if (!isMintCharacterModalShown.current) {
|
||||
// Not shown
|
||||
isMintCharacterModalShown.current = true
|
||||
walletMintNewCharacterModal.show()
|
||||
} else if (!walletMintNewCharacterModal.isActive) {
|
||||
// Shown, but closed by user
|
||||
router.push("/") // Go back home
|
||||
}
|
||||
} else {
|
||||
// Already have characters, redirect to primary
|
||||
router.push(`/dashboard/${userSites.data[0].username}`)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue