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

Use Next.js link to prevent page reload while safe being reloaded #1319

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions app/daos/[daoAddress]/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client';

import { Button, Center, Text, VStack } from '@chakra-ui/react';
import { useRouter } from 'next/navigation';
import { ReactNode } from 'react';
import { useTranslation } from 'react-i18next';
import { useNetwork } from 'wagmi';
Expand All @@ -16,6 +17,7 @@ import {
function InvalidSafe() {
const { chain } = useNetwork();
const { t } = useTranslation('common');
const router = useRouter();
return (
<Center
padding="3rem"
Expand All @@ -30,13 +32,7 @@ function InvalidSafe() {
</Text>
<Text>{t('invalidSafe1', { chain: chain ? chain.name : disconnectedChain.name })}</Text>
<Text paddingBottom="1rem">{t('invalidSafe2')}</Text>
<Button
onClick={() => {
window.location.reload();
}}
>
{t('refresh')}
</Button>
<Button onClick={router.refresh}>{t('refresh')}</Button>
</VStack>
</Center>
);
Expand Down
2 changes: 2 additions & 0 deletions src/components/pages/DaoDashboard/Info/ParentLink.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Link, HStack, Image, Text, LinkProps } from '@chakra-ui/react';
import NextLink from 'next/link';
import { useTranslation } from 'react-i18next';
import { DAO_ROUTES } from '../../../../constants/routes';
import { useFractal } from '../../../../providers/App/AppProvider';
Expand All @@ -22,6 +23,7 @@ export function ParentLink({ ...rest }: LinkProps) {
_hover={{ textDecoration: 'none', color: 'gold.500-hover' }}
href={DAO_ROUTES.dao.relative(nodeHierarchy.parentAddress)}
marginBottom="1rem"
as={NextLink}
{...rest}
>
<HStack>
Expand Down
7 changes: 6 additions & 1 deletion src/components/ui/cards/DAOInfoCard.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Box, Flex, Text, Spacer, HStack, FlexProps, Link, Center } from '@chakra-ui/react';
import NextLink from 'next/link';
import { DAO_ROUTES } from '../../../constants/routes';
import useDisplayName from '../../../hooks/utils/useDisplayName';
import { useFractal } from '../../../providers/App/AppProvider';
Expand Down Expand Up @@ -74,6 +75,7 @@ export function DAOInfoCard({
>
<HStack>
<Link
as={NextLink}
pointerEvents={isCurrentDAO ? 'none' : undefined}
href={DAO_ROUTES.dao.relative(displayedAddress)}
_hover={{ textDecoration: 'none' }}
Expand Down Expand Up @@ -101,7 +103,10 @@ export function DAOInfoCard({
data-testid="DAOInfo-favorite"
/>
{childCount && childCount > 0 && (
<Link href={DAO_ROUTES.hierarchy.relative(displayedAddress)}>
<Link
href={DAO_ROUTES.hierarchy.relative(displayedAddress)}
as={NextLink}
>
<Box
bg="chocolate.500"
borderRadius="4px"
Expand Down
4 changes: 3 additions & 1 deletion src/components/ui/utils/ErrorFallback.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { Link } from '@chakra-ui/next-js';
import { Box, Button, Center, Flex, Text } from '@chakra-ui/react';
import { Alert } from '@decent-org/fractal-ui';
import { useRouter } from 'next/navigation';
import { Trans, useTranslation } from 'react-i18next';
import { CONTENT_HEIGHT } from '../../../constants/common';
import { URL_DISCORD } from '../../../constants/url';
import { InfoBox } from '../containers/InfoBox';

export function ErrorFallback() {
const { t } = useTranslation();
const router = useRouter();
return (
<Center h={CONTENT_HEIGHT}>
<Box maxWidth="fit-content">
Expand Down Expand Up @@ -36,7 +38,7 @@ export function ErrorFallback() {
/>
</Trans>
</Text>
<Button onClick={() => window.location.reload()}>{t('reload')}</Button>
<Button onClick={router.refresh}>{t('reload')}</Button>
</Flex>
</InfoBox>
</Box>
Expand Down