Commit 20785776 authored by isstuev's avatar isstuev

review fixes

parent 0e9a61e4
...@@ -4,7 +4,12 @@ import * as cookies from 'lib/cookies'; ...@@ -4,7 +4,12 @@ import * as cookies from 'lib/cookies';
export default function useHasAccount() { export default function useHasAccount() {
const appProps = useAppContext(); const appProps = useAppContext();
if (!appConfig.isAccountSupported) {
return false;
}
const cookiesString = appProps.cookies; const cookiesString = appProps.cookies;
const hasAuth = Boolean(cookies.get(cookies.NAMES.API_TOKEN, cookiesString)); const hasAuth = Boolean(cookies.get(cookies.NAMES.API_TOKEN, cookiesString));
return hasAuth && appConfig.isAccountSupported; return hasAuth;
} }
...@@ -11,6 +11,7 @@ const LatestTxsItemSkeleton = () => { ...@@ -11,6 +11,7 @@ const LatestTxsItemSkeleton = () => {
return ( return (
<Box <Box
width="100%" width="100%"
minW="700px"
borderTop="1px solid" borderTop="1px solid"
borderColor="divider" borderColor="divider"
py={ 4 } py={ 4 }
......
...@@ -2,7 +2,7 @@ import type { ChakraProps, ThemingProps } from '@chakra-ui/react'; ...@@ -2,7 +2,7 @@ import type { ChakraProps, ThemingProps } from '@chakra-ui/react';
import { chakra } from '@chakra-ui/react'; import { chakra } from '@chakra-ui/react';
import _pickBy from 'lodash/pickBy'; import _pickBy from 'lodash/pickBy';
import { useRouter } from 'next/router'; import { useRouter } from 'next/router';
import React, { useEffect, useRef, useState } from 'react'; import React, { useEffect, useRef } from 'react';
import type { RoutedTab } from './types'; import type { RoutedTab } from './types';
...@@ -18,7 +18,15 @@ interface Props extends ThemingProps<'Tabs'> { ...@@ -18,7 +18,15 @@ interface Props extends ThemingProps<'Tabs'> {
const RoutedTabs = ({ tabs, tabListProps, rightSlot, stickyEnabled, className, ...themeProps }: Props) => { const RoutedTabs = ({ tabs, tabListProps, rightSlot, stickyEnabled, className, ...themeProps }: Props) => {
const router = useRouter(); const router = useRouter();
const [ activeTabIndex, setActiveTabIndex ] = useState<number>(tabs.length + 1);
let tabIndex = 0;
const tabFromRoute = router.query.tab;
if (tabFromRoute) {
tabIndex = tabs.findIndex(({ id, subTabs }) => id === tabFromRoute || subTabs?.some((id) => id === tabFromRoute));
if (tabIndex < 0) {
tabIndex = 0;
}
}
const tabsRef = useRef<HTMLDivElement>(null); const tabsRef = useRef<HTMLDivElement>(null);
...@@ -50,21 +58,6 @@ const RoutedTabs = ({ tabs, tabListProps, rightSlot, stickyEnabled, className, . ...@@ -50,21 +58,6 @@ const RoutedTabs = ({ tabs, tabListProps, rightSlot, stickyEnabled, className, .
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, []); }, []);
useEffect(() => {
if (router.isReady) {
let tabIndex = 0;
const tabFromRoute = router.query.tab;
if (tabFromRoute) {
tabIndex = tabs.findIndex(({ id, subTabs }) => id === tabFromRoute || subTabs?.some((id) => id === tabFromRoute));
if (tabIndex < 0) {
tabIndex = 0;
}
}
setActiveTabIndex(tabIndex);
}
}, [ tabs, router, activeTabIndex ]);
return ( return (
<TabsWithScroll <TabsWithScroll
tabs={ tabs } tabs={ tabs }
...@@ -72,7 +65,7 @@ const RoutedTabs = ({ tabs, tabListProps, rightSlot, stickyEnabled, className, . ...@@ -72,7 +65,7 @@ const RoutedTabs = ({ tabs, tabListProps, rightSlot, stickyEnabled, className, .
rightSlot={ rightSlot } rightSlot={ rightSlot }
stickyEnabled={ stickyEnabled } stickyEnabled={ stickyEnabled }
onTabChange={ handleTabChange } onTabChange={ handleTabChange }
activeTabIndex={ activeTabIndex } defaultTabIndex={ tabIndex }
{ ...themeProps } { ...themeProps }
/> />
); );
......
...@@ -10,13 +10,13 @@ import { Popover, ...@@ -10,13 +10,13 @@ import { Popover,
import type { StyleProps } from '@chakra-ui/styled-system'; import type { StyleProps } from '@chakra-ui/styled-system';
import React from 'react'; import React from 'react';
import type { MenuButton, RoutedTab } from './types'; import type { MenuButton, TabItem } from './types';
import { menuButton } from './utils'; import { menuButton } from './utils';
interface Props { interface Props {
tabs: Array<RoutedTab | MenuButton>; tabs: Array<TabItem | MenuButton>;
activeTab?: RoutedTab; activeTab?: TabItem;
tabsCut: number; tabsCut: number;
isActive: boolean; isActive: boolean;
styles?: StyleProps; styles?: StyleProps;
...@@ -25,7 +25,7 @@ interface Props { ...@@ -25,7 +25,7 @@ interface Props {
size: ButtonProps['size']; size: ButtonProps['size'];
} }
const RoutedTabsMenu = ({ tabs, tabsCut, isActive, styles, onItemClick, buttonRef, activeTab, size }: Props) => { const TabsMenu = ({ tabs, tabsCut, isActive, styles, onItemClick, buttonRef, activeTab, size }: Props) => {
const { isOpen, onClose, onOpen } = useDisclosure(); const { isOpen, onClose, onOpen } = useDisclosure();
const handleItemClick = React.useCallback((event: React.MouseEvent<HTMLButtonElement>) => { const handleItemClick = React.useCallback((event: React.MouseEvent<HTMLButtonElement>) => {
...@@ -69,4 +69,4 @@ const RoutedTabsMenu = ({ tabs, tabsCut, isActive, styles, onItemClick, buttonRe ...@@ -69,4 +69,4 @@ const RoutedTabsMenu = ({ tabs, tabsCut, isActive, styles, onItemClick, buttonRe
); );
}; };
export default React.memo(RoutedTabsMenu); export default React.memo(TabsMenu);
...@@ -19,7 +19,7 @@ import { useScrollDirection } from 'lib/contexts/scrollDirection'; ...@@ -19,7 +19,7 @@ import { useScrollDirection } from 'lib/contexts/scrollDirection';
import useIsMobile from 'lib/hooks/useIsMobile'; import useIsMobile from 'lib/hooks/useIsMobile';
import useIsSticky from 'lib/hooks/useIsSticky'; import useIsSticky from 'lib/hooks/useIsSticky';
import RoutedTabsMenu from './RoutedTabsMenu'; import TabsMenu from './TabsMenu';
import useAdaptiveTabs from './useAdaptiveTabs'; import useAdaptiveTabs from './useAdaptiveTabs';
const hiddenItemStyles: StyleProps = { const hiddenItemStyles: StyleProps = {
...@@ -36,7 +36,7 @@ interface Props extends ThemingProps<'Tabs'> { ...@@ -36,7 +36,7 @@ interface Props extends ThemingProps<'Tabs'> {
rightSlot?: React.ReactNode; rightSlot?: React.ReactNode;
stickyEnabled?: boolean; stickyEnabled?: boolean;
onTabChange?: (index: number) => void; onTabChange?: (index: number) => void;
activeTabIndex?: number; defaultTabIndex?: number;
className?: string; className?: string;
} }
...@@ -47,12 +47,12 @@ const TabsWithScroll = ({ ...@@ -47,12 +47,12 @@ const TabsWithScroll = ({
rightSlot, rightSlot,
stickyEnabled, stickyEnabled,
onTabChange, onTabChange,
activeTabIndex: activeTabIndexProps, defaultTabIndex,
className, className,
...themeProps ...themeProps
}: Props) => { }: Props) => {
const scrollDirection = useScrollDirection(); const scrollDirection = useScrollDirection();
const [ activeTabIndex, setActiveTabIndex ] = useState<number>(activeTabIndexProps || 0); const [ activeTabIndex, setActiveTabIndex ] = useState<number>(defaultTabIndex || 0);
const isMobile = useIsMobile(); const isMobile = useIsMobile();
const tabsRef = useRef<HTMLDivElement>(null); const tabsRef = useRef<HTMLDivElement>(null);
const { tabsCut, tabsList, tabsRefs, listRef, rightSlotRef } = useAdaptiveTabs(tabs, isMobile); const { tabsCut, tabsList, tabsRefs, listRef, rightSlotRef } = useAdaptiveTabs(tabs, isMobile);
...@@ -64,10 +64,10 @@ const TabsWithScroll = ({ ...@@ -64,10 +64,10 @@ const TabsWithScroll = ({
}, [ onTabChange ]); }, [ onTabChange ]);
useEffect(() => { useEffect(() => {
if (activeTabIndexProps !== undefined) { if (defaultTabIndex !== undefined) {
setActiveTabIndex(activeTabIndexProps); setActiveTabIndex(defaultTabIndex);
} }
}, [ activeTabIndexProps ]); }, [ defaultTabIndex ]);
useEffect(() => { useEffect(() => {
if (activeTabIndex < tabs.length && isMobile) { if (activeTabIndex < tabs.length && isMobile) {
...@@ -138,7 +138,7 @@ const TabsWithScroll = ({ ...@@ -138,7 +138,7 @@ const TabsWithScroll = ({
{ tabsList.map((tab, index) => { { tabsList.map((tab, index) => {
if (!tab.id) { if (!tab.id) {
return ( return (
<RoutedTabsMenu <TabsMenu
key="menu" key="menu"
tabs={ tabs } tabs={ tabs }
activeTab={ tabs[activeTabIndex] } activeTab={ tabs[activeTabIndex] }
......
import { Flex, Skeleton, chakra } from '@chakra-ui/react'; import { Flex, Skeleton, chakra } from '@chakra-ui/react';
import React from 'react'; import React from 'react';
import type { RoutedTab } from '../RoutedTabs/types'; import type { RoutedTab } from '../Tabs/types';
interface Props { interface Props {
className?: string; className?: string;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment