Skip to content

Commit

Permalink
fix: virtuoso list fixed height
Browse files Browse the repository at this point in the history
  • Loading branch information
alter-eggo committed Nov 24, 2024
1 parent e096ff2 commit f1d2dc8
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 173 deletions.
67 changes: 0 additions & 67 deletions src/app/components/item-hover.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { memo } from 'react';
import { Virtuoso } from 'react-virtuoso';

import { Box } from 'leather-styles/jsx';
import { Box, Flex } from 'leather-styles/jsx';

import { Button, Sheet, SheetHeader } from '@leather.io/ui';

Expand All @@ -10,7 +10,7 @@ import { useWalletType } from '@app/common/use-wallet-type';
import { useCurrentAccountIndex } from '@app/store/accounts/account';
import { useFilteredBitcoinAccounts } from '@app/store/accounts/blockchain/bitcoin/bitcoin.ledger';
import { useStacksAccounts } from '@app/store/accounts/blockchain/stacks/stacks-account.hooks';
import { VirtuosoWrapper } from '@app/ui/components/virtuoso';
import { VirtuosoWrapperSheet } from '@app/ui/components/virtuoso-wrapper-sheet';

import { AccountListUnavailable } from './components/account-list-unavailable';
import { SwitchAccountListItem } from './components/switch-account-list-item';
Expand Down Expand Up @@ -50,33 +50,39 @@ export const SwitchAccountSheet = memo(({ isShowing, onClose }: SwitchAccountShe
isShowing={isShowing}
onClose={onClose}
wrapChildren={false}
footer={whenWallet({
software: (
<Button fullWidth onClick={() => onCreateAccount()}>
Create new account
</Button>
),
ledger: null,
})}
>
<VirtuosoWrapper hasFooter={whenWallet({ ledger: false, software: true })}>
<Virtuoso
style={{
height: '100%',
}}
initialTopMostItemIndex={whenWallet({ ledger: 0, software: currentAccountIndex })}
totalCount={accountNum}
itemContent={index => (
<Box key={index} py="space.03" px="space.05">
<SwitchAccountListItem
handleClose={onClose}
currentAccountIndex={currentAccountIndex}
index={index}
/>
</Box>
)}
/>
</VirtuosoWrapper>
<VirtuosoWrapperSheet>
<Box flex="1">
<Virtuoso
initialTopMostItemIndex={whenWallet({ ledger: 0, software: currentAccountIndex })}
totalCount={accountNum}
itemContent={index => (
<Box key={index} py="space.03" px="space.05">
<SwitchAccountListItem
handleClose={onClose}
currentAccountIndex={currentAccountIndex}
index={index}
/>
</Box>
)}
/>
</Box>
{whenWallet({
software: (
<Flex
borderBottomRadius="md"
bg="ink.background-primary"
borderTop="default"
p="space.05"
>
<Button fullWidth onClick={() => onCreateAccount()}>
Create new account
</Button>
</Flex>
),
ledger: null,
})}
</VirtuosoWrapperSheet>
</Sheet>
);
});
2 changes: 1 addition & 1 deletion src/app/pages/choose-account/choose-account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function ChooseAccount() {

return (
<>
<Flex alignItems="center" flexDirection="column" pt="space.07" width="100%">
<Flex alignItems="center" flexDirection="column" pt="space.07" width="100%" height="100%">
<Stack gap="space.05" textAlign="center" alignItems="center">
{url && <RequesterFlag requester={url.toString()} />}
<LeatherLogomarkIcon height={58} width={248} />
Expand Down
39 changes: 15 additions & 24 deletions src/app/pages/choose-account/components/accounts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import { Suspense, memo, useMemo, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { Virtuoso } from 'react-virtuoso';

import { Box, FlexProps, HStack, styled } from 'leather-styles/jsx';
import { token } from 'leather-styles/tokens';
import { Box, Flex, FlexProps, HStack, Stack, styled } from 'leather-styles/jsx';

import { PlusIcon } from '@leather.io/ui';
import { PlusIcon, Pressable } from '@leather.io/ui';

import { RouteUrls } from '@shared/route-urls';

Expand All @@ -17,12 +16,10 @@ import { slugify } from '@app/common/utils';
import { AccountTotalBalance } from '@app/components/account-total-balance';
import { AcccountAddresses } from '@app/components/account/account-addresses';
import { AccountListItemLayout } from '@app/components/account/account-list-item.layout';
import { usePressable } from '@app/components/item-hover';
import { useNativeSegwitAccountIndexAddressIndexZero } from '@app/store/accounts/blockchain/bitcoin/native-segwit-account.hooks';
import { useStacksAccounts } from '@app/store/accounts/blockchain/stacks/stacks-account.hooks';
import { StacksAccount } from '@app/store/accounts/blockchain/stacks/stacks-account.models';
import { AccountAvatar } from '@app/ui/components/account/account-avatar/account-avatar';
import { VirtuosoWrapper } from '@app/ui/components/virtuoso';

interface AccountTitlePlaceholderProps {
account: StacksAccount;
Expand Down Expand Up @@ -74,21 +71,17 @@ const ChooseAccountItem = memo(
);

function AddAccountAction() {
const [component, bind] = usePressable(true);
const createAccount = useCreateAccount();

const onCreateAccount = () => {
createAccount();
};

return (
<Box mx="space.05" py="space.02" onClick={onCreateAccount} {...bind}>
<HStack alignItems="center">
<PlusIcon />
Generate new account
</HStack>
{component}
</Box>
<Flex mx="space.05">
<Pressable onClick={createAccount} py="space.02">
<HStack alignItems="center">
<PlusIcon />
<styled.span textStyle="label.02">Generate new account</styled.span>
</HStack>
</Pressable>
</Flex>
);
}

Expand All @@ -114,13 +107,11 @@ export function ChooseAccountsList() {
if (!accounts) return null;

return (
<Box mt="space.05" mb="space.06" width="100%">
<Stack width="100%" height="100%" mt="space.05">
{whenWallet({ software: <AddAccountAction />, ledger: <></> })}
<VirtuosoWrapper isPopup>

<Box height="100%">
<Virtuoso
style={{
background: token('colors.ink.background-primary'),
}}
data={accounts}
itemContent={(index, account) => (
<Box key={index} my="space.05" px="space.05">
Expand All @@ -132,7 +123,7 @@ export function ChooseAccountsList() {
</Box>
)}
/>
</VirtuosoWrapper>
</Box>
</Box>
</Stack>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Sheet, SheetHeader } from '@leather.io/ui';

import { useFilteredBitcoinAccounts } from '@app/store/accounts/blockchain/bitcoin/bitcoin.ledger';
import { useStacksAccounts } from '@app/store/accounts/blockchain/stacks/stacks-account.hooks';
import { VirtuosoWrapper } from '@app/ui/components/virtuoso';
import { VirtuosoWrapperSheet } from '@app/ui/components/virtuoso-wrapper-sheet';

import { AccountListItem } from './account-list-item';

Expand All @@ -31,13 +31,10 @@ export function RecipientAccountsSheet() {
onClose={onGoBack}
wrapChildren={false}
>
<VirtuosoWrapper>
<VirtuosoWrapperSheet>
<Virtuoso
style={{
height: '100%',
}}
itemContent={index => (
<Box key={index} my="space.05" px="space.05">
<Box key={index} py="space.03" px="space.05">
<AccountListItem
stacksAccount={stacksAccounts[index]}
onClose={onGoBack}
Expand All @@ -47,7 +44,7 @@ export function RecipientAccountsSheet() {
)}
totalCount={accountNum}
/>
</VirtuosoWrapper>
</VirtuosoWrapperSheet>
</Sheet>
);
}
27 changes: 27 additions & 0 deletions src/app/ui/components/virtuoso-wrapper-sheet.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { ReactNode, useState } from 'react';

import { Stack } from 'leather-styles/jsx';

import { useViewportMinWidth } from '@app/common/hooks/use-media-query';
import { useOnResizeListener } from '@app/common/hooks/use-on-resize-listener';

interface VirtuosoWrapperSheetProps {
children: ReactNode;
}

export function VirtuosoWrapperSheet({ children }: VirtuosoWrapperSheetProps) {
const [key, setKey] = useState(0);
const isAtLeastMd = useViewportMinWidth('md');
const height = isAtLeastMd ? '70vh' : '100vh';

const onResize = () => {
setKey(Date.now());
};

useOnResizeListener(onResize);
return (
<Stack gap="0" key={key} height={height}>
{children}
</Stack>
);
}
46 changes: 0 additions & 46 deletions src/app/ui/components/virtuoso.tsx

This file was deleted.

3 changes: 3 additions & 0 deletions theme/global/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ export const globalCss = defineGlobalStyles({
maxWidth: tokens.sizes.popupMaxWidth.value,
margin: '0 auto',
},
'#app, .radix-themes': {
height: '100%',
},
},
'.mode__action-popup': {
'html,body': {
Expand Down

0 comments on commit f1d2dc8

Please sign in to comment.