Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENG-3797 ENG-3736 fix(portal): lists and claims back button and hook #805

Merged
merged 9 commits into from
Aug 30, 2024
1 change: 1 addition & 0 deletions apps/portal/app/consts/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const PATHS = {
PROFILE_LISTS: '/app/profile/lists',
// Explore
EXPLORE_IDENTITIES: '/app/explore/identities',
EXPLORE_CLAIMS: '/app/explore/claims',
EXPLORE_LISTS: '/app/explore/lists',
// Activity
GLOBAL_ACTIVITY: '/app/activity/global',
Expand Down
23 changes: 23 additions & 0 deletions apps/portal/app/lib/hooks/useGoBack.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { useEffect, useRef } from 'react'

import { useLocation, useNavigate } from '@remix-run/react'

function useGoBack({ fallbackRoute }: { fallbackRoute: string }) {
const navigate = useNavigate()
const location = useLocation()
const hasNavigated = useRef(false)

useEffect(() => {
hasNavigated.current = true
}, [location])

return () => {
if (hasNavigated.current && window.history.length > 2) {
navigate(-1)
} else {
window.location.href = fallbackRoute
}
}
}

export { useGoBack }
10 changes: 9 additions & 1 deletion apps/portal/app/routes/app+/claim+/$id.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
import { ErrorPage } from '@components/error-page'
import NavigationButton from '@components/navigation-link'
import StakeModal from '@components/stake/stake-modal'
import { useGoBack } from '@lib/hooks/useGoBack'
import { useLiveLoader } from '@lib/hooks/useLiveLoader'
import { getClaimOrPending } from '@lib/services/claims'
import { stakeModalAtom } from '@lib/state/store'
Expand Down Expand Up @@ -147,9 +148,16 @@ export default function ClaimDetails() {
? 'FOR'
: 'AGAINST'

const handleGoBack = useGoBack({ fallbackRoute: PATHS.EXPLORE_CLAIMS })

const leftPanel = (
<div className="flex-col justify-start items-start gap-6 inline-flex w-full">
<NavigationButton variant="secondary" size="icon" to={'..'}>
<NavigationButton
variant="secondary"
size="icon"
to="#"
onClick={handleGoBack}
>
<Icon name="arrow-left" />
</NavigationButton>
<div className="flex-row flex m-auto md:hidden">
Expand Down
9 changes: 8 additions & 1 deletion apps/portal/app/routes/app+/list+/$id.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import AddIdentitiesListModal from '@components/list/add-identities-list-modal'
import { ListIdentityDisplayCard } from '@components/list/list-identity-display-card'
import NavigationButton from '@components/navigation-link'
import ImageModal from '@components/profile/image-modal'
import { useGoBack } from '@lib/hooks/useGoBack'
import { useLiveLoader } from '@lib/hooks/useLiveLoader'
import { addIdentitiesListModalAtom, imageModalAtom } from '@lib/state/store'
import logger from '@lib/utils/logger'
Expand Down Expand Up @@ -78,10 +79,16 @@ export default function ListDetails() {
useAtom(addIdentitiesListModalAtom)
const [imageModalActive, setImageModalActive] = useAtom(imageModalAtom)
const navigate = useNavigate()
const handleGoBack = useGoBack({ fallbackRoute: PATHS.EXPLORE_LISTS })

const leftPanel = (
<div className="flex-col justify-start items-start gap-6 inline-flex max-lg:w-full">
<NavigationButton variant="secondary" size="icon" to={'..'}>
<NavigationButton
variant="secondary"
size="icon"
to="#"
onClick={handleGoBack}
>
<Icon name="arrow-left" />
</NavigationButton>
<ProfileCard
Expand Down
Loading