Skip to content

Commit

Permalink
feat(dcellar-web-ui): remove drawer close btn & add debounce refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
aiden-cao committed Aug 30, 2023
1 parent cd92cfa commit 04a2d8d
Show file tree
Hide file tree
Showing 20 changed files with 141 additions and 136 deletions.
5 changes: 5 additions & 0 deletions apps/dcellar-web-ui/src/base/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ export const theme = {
top: 65,
maxW: '500px',
},
'.ui-drawer .ui-drawer-body': {
width: 'calc(100% + 48px)',
marginLeft: -24,
padding: '0 24px',
},
},
},
},
Expand Down
14 changes: 12 additions & 2 deletions apps/dcellar-web-ui/src/components/common/DCDrawer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
import React from 'react';
import { QDrawer, QDrawerProps } from '@totejs/uikit';
import { QDrawer, QDrawerCloseButton, QDrawerProps } from '@totejs/uikit';
import { reportEvent } from '@/utils/reportEvent';
import { GAShow } from '../GATracker';
export interface DCDrawerProps extends QDrawerProps {
gaShowName?: string;
gaShowData?: Record<string, any>;
gaClickCloseName?: string;
showCloseBtn?: boolean;
}
export const DCDrawer = (props: DCDrawerProps) => {
const { children, gaShowName, gaShowData, gaClickCloseName, onClose, ...restProps } = props;
const {
children,
gaShowName,
gaShowData,
gaClickCloseName,
onClose,
showCloseBtn = true,
...restProps
} = props;

const onBeforeClose = () => {
if (gaClickCloseName) {
Expand All @@ -30,6 +39,7 @@ export const DCDrawer = (props: DCDrawerProps) => {
rootProps={{ top: 64.5 }}
{...restProps}
>
{showCloseBtn && <QDrawerCloseButton top={16} right={24} color="readable.tertiary" />}
{children}
</QDrawer>
</GAShow>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
import { useAppSelector } from '@/store';
import {
Box,
Divider,
Flex,
Image,
Link,
QDrawerBody,
QDrawerCloseButton,
QDrawerHeader,
Text,
} from '@totejs/uikit';
import { Box, Divider, Flex, Image, Link, QDrawerBody, QDrawerHeader, Text } from '@totejs/uikit';
import React from 'react';
import { GREENFIELD_CHAIN_EXPLORER_URL, assetPrefix } from '@/base/env';
import { trimAddress } from '@/utils/string';
Expand All @@ -26,7 +16,7 @@ import { getNumInDigits } from '@/utils/wallet';
export const AccountDetail = ({ loading, title, accountDetail, lockFee }: any) => {
const bnbPrice = useAppSelector(selectBnbPrice);
const isOwnerAccount = accountDetail?.name?.toLowerCase() === 'owner account';
const {bankBalance} = useAppSelector(root=> root.accounts);
const { bankBalance } = useAppSelector((root) => root.accounts);
const balance = isOwnerAccount
? BigNumber(accountDetail?.staticBalance || 0)
.plus(BigNumber(bankBalance))
Expand Down Expand Up @@ -120,7 +110,6 @@ export const AccountDetail = ({ loading, title, accountDetail, lockFee }: any) =
<QDrawerHeader fontWeight={600} fontSize={24} lineHeight="32px">
{title}
</QDrawerHeader>
<QDrawerCloseButton top={16} right={24} color="readable.tertiary" />
<QDrawerBody>
<Flex alignItems={'flex-start'}>
<Image
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
import React, { memo, useEffect, useMemo } from 'react';
import {
QDrawerCloseButton,
QDrawerHeader,
QDrawerBody,
Flex,
Text,
Link,
Box,
Divider,
} from '@totejs/uikit';
import { QDrawerHeader, QDrawerBody, Flex, Text, Link, Box, Divider } from '@totejs/uikit';
import { useAppDispatch, useAppSelector } from '@/store';
import { BucketItem, setEditDetail, setupBucketQuota } from '@/store/slices/bucket';
import { formatFullTime, getMillisecond } from '@/utils/time';
Expand Down Expand Up @@ -197,7 +188,6 @@ export const DetailDrawer = memo<DetailDrawerProps>(function DetailDrawer() {

return (
<DCDrawer isOpen={isOpen} onClose={onClose}>
<QDrawerCloseButton />
<QDrawerHeader>Bucket Detail</QDrawerHeader>
<QDrawerBody>
<Flex my={32}>
Expand Down
12 changes: 8 additions & 4 deletions apps/dcellar-web-ui/src/modules/bucket/components/NewBucket.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { memo } from 'react';
import { memo, useCallback } from 'react';
import { CreateBucketButton } from '@/modules/bucket/bucket.style';
import { AddIcon } from '@totejs/icons';
import { useAppDispatch, useAppSelector } from '@/store';
import { setEditCreate, setupBuckets } from '@/store/slices/bucket';
import { Flex } from '@totejs/uikit';
import RefreshIcon from '@/public/images/icons/refresh.svg';
import { debounce } from 'lodash-es';

interface NewBucketProps {
showRefresh?: boolean;
Expand All @@ -14,9 +15,12 @@ export const NewBucket = memo<NewBucketProps>(function NewBucket({ showRefresh =
const dispatch = useAppDispatch();
const { loginAccount } = useAppSelector((root) => root.persist);

const onRefresh = () => {
dispatch(setupBuckets(loginAccount, true));
};
const onRefresh = useCallback(
debounce(() => {
dispatch(setupBuckets(loginAccount, true));
}, 300),
[loginAccount],
);

return (
<Flex gap={12}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
InputRightElement,
Link,
QDrawerBody,
QDrawerCloseButton,
QDrawerFooter,
QDrawerHeader,
Text,
Expand Down Expand Up @@ -423,7 +422,6 @@ export const CreateBucket = ({ isOpen, onClose, refetch }: Props) => {
<CreateBucketFailed errorMsg={submitErrorMsg} onClose={() => setStatus('pending')} />
)}
<DCDrawer isOpen={isOpen} onClose={onClose}>
<QDrawerCloseButton />
<QDrawerHeader>Create a Bucket</QDrawerHeader>
<QDrawerBody mt={0}>
<Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from '@/modules/file/constant';
import { useUnmount, useUpdateEffect } from 'ahooks';
import { DCDrawer } from '@/components/common/DCDrawer';
import { Flex, QDrawerBody, QDrawerCloseButton, QDrawerHeader, Text, toast } from '@totejs/uikit';
import { Flex, QDrawerBody, QDrawerHeader, Text, toast } from '@totejs/uikit';
import { DCComboBox } from '@/components/common/DCComboBox';
import { DCButton } from '@/components/common/DCButton';
import ComingSoon from '@/components/common/SvgIcon/members.svg';
Expand Down Expand Up @@ -86,10 +86,10 @@ export const AddGroupMember = memo<AddMemberProps>(function AddMember() {
const curTimeStamp = await getUtcZeroTimestamp();
const expirationTimestamp = Math.floor(curTimeStamp + 10 * 60 * 60 * 1000);
const expirationDate = new Date(expirationTimestamp);
const membersToAdd = values.map(item => ({
const membersToAdd = values.map((item) => ({
member: item,
expirationTime: toTimestamp(expirationDate),
}))
}));

const payload = {
operator: loginAccount,
Expand Down Expand Up @@ -118,7 +118,6 @@ export const AddGroupMember = memo<AddMemberProps>(function AddMember() {

return (
<DCDrawer isOpen={!!addGroupMember.groupName} onClose={onClose}>
<QDrawerCloseButton />
<QDrawerHeader flexDirection="column">Add Members</QDrawerHeader>
<QDrawerBody>
<Flex gap={12}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
FormControl,
FormLabel,
QDrawerBody,
QDrawerCloseButton,
QDrawerFooter,
QDrawerHeader,
Text,
Expand Down Expand Up @@ -136,7 +135,6 @@ export const CreateGroup = memo<CreateGroupProps>(function CreateGroup() {

return (
<DCDrawer isOpen={creatingGroup} onClose={onClose}>
<QDrawerCloseButton />
<QDrawerHeader flexDirection="column">
Create a Group
<Text fontSize={14} lineHeight="17px" fontWeight={400} color="#76808F">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
FormControl,
FormLabel,
QDrawerBody,
QDrawerCloseButton,
QDrawerFooter,
QDrawerHeader,
Text,
Expand Down Expand Up @@ -135,7 +134,6 @@ export const EditGroup = memo<EditGroupProps>(function CreateGroup() {

return (
<DCDrawer isOpen={!!editGroup.groupName} onClose={onClose}>
<QDrawerCloseButton />
<QDrawerHeader flexDirection="column">Edit Description</QDrawerHeader>
<QDrawerBody>
<FormControl mb={16} isInvalid={!!error.name}>
Expand Down
12 changes: 8 additions & 4 deletions apps/dcellar-web-ui/src/modules/group/components/NewGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { memo } from 'react';
import { memo, useCallback } from 'react';
import { Flex } from '@totejs/uikit';
import { useAppDispatch, useAppSelector } from '@/store';
import { setCreatingGroup, setupGroups } from '@/store/slices/group';
import RefreshIcon from '@/public/images/icons/refresh.svg';
import { DCButton } from '@/components/common/DCButton';
import { debounce } from 'lodash-es';

interface NewGroupProps {
showRefresh?: boolean;
Expand All @@ -13,9 +14,12 @@ export const NewGroup = memo<NewGroupProps>(function NewGroup({ showRefresh = tr
const dispatch = useAppDispatch();
const { loginAccount } = useAppSelector((root) => root.persist);

const onRefresh = () => {
dispatch(setupGroups(loginAccount, true));
};
const onRefresh = useCallback(
debounce(() => {
dispatch(setupGroups(loginAccount, true));
}, 300),
[loginAccount],
);

const onCreate = () => {
dispatch(setCreatingGroup(true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from '@/modules/file/constant';
import { useUnmount, useUpdateEffect } from 'ahooks';
import { DCDrawer } from '@/components/common/DCDrawer';
import { Flex, QDrawerBody, QDrawerCloseButton, QDrawerHeader, Text, toast } from '@totejs/uikit';
import { Flex, QDrawerBody, QDrawerHeader, Text, toast } from '@totejs/uikit';
import { DCComboBox } from '@/components/common/DCComboBox';
import { DCButton } from '@/components/common/DCButton';
import ComingSoon from '@/components/common/SvgIcon/members.svg';
Expand Down Expand Up @@ -107,7 +107,6 @@ export const RemoveGroupMember = memo<RemoveGroupMemberProps>(function RemoveGro

return (
<DCDrawer isOpen={!!removeGroupMember.groupName} onClose={onClose}>
<QDrawerCloseButton />
<QDrawerHeader flexDirection="column">Remove Members</QDrawerHeader>
<QDrawerBody>
<Flex gap={12}>
Expand Down
27 changes: 17 additions & 10 deletions apps/dcellar-web-ui/src/modules/object/components/CreateFolder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ import {
FormControl,
Link,
QDrawerBody,
QDrawerCloseButton,
QDrawerFooter,
QDrawerHeader,
Text,
toast,
useDisclosure,
} from '@totejs/uikit';
import { InputItem } from '@/components/formitems/InputItem';
import { Fees } from '@/modules/file/components/Fees';
Expand Down Expand Up @@ -282,7 +280,9 @@ export const CreateFolder = memo<modalProps>(function CreateFolderDrawer({ refet
) => {
const fullPath = getPath(folderName, folders);
const file = new File([], fullPath, { type: 'text/plain' });
const { seedString } = await dispatch(getSpOffChainData(loginAccount, primarySp.operatorAddress));
const { seedString } = await dispatch(
getSpOffChainData(loginAccount, primarySp.operatorAddress),
);
const hashResult = await checksumWorkerApi?.generateCheckSumV2(file);
const createObjectPayload: TBaseGetCreateObject = {
bucketName,
Expand Down Expand Up @@ -326,22 +326,30 @@ export const CreateFolder = memo<modalProps>(function CreateFolderDrawer({ refet

useEffect(() => {
if (isEmpty(preLockFeeObject)) {
return
return;
}
const nGasFee = BigNumber(gasFee);
console.log('isOwnerAccount', isOwnerAccount, preLockFee, payLockFeeAccount.staticBalance, bankBalance)
console.log(
'isOwnerAccount',
isOwnerAccount,
preLockFee,
payLockFeeAccount.staticBalance,
bankBalance,
);
if (isOwnerAccount) {
if (BigNumber(preLockFee).gt(BigNumber(payLockFeeAccount.staticBalance).plus(bankBalance))) {
setTimeout(() => setFormErrors([GET_GAS_FEE_LACK_BALANCE_ERROR]), 100);
}
} else {
if (BigNumber(preLockFee).gt(BigNumber(payLockFeeAccount.staticBalance)) || nGasFee.gt(BigNumber(bankBalance))) {
console.log('2131232131221')
if (
BigNumber(preLockFee).gt(BigNumber(payLockFeeAccount.staticBalance)) ||
nGasFee.gt(BigNumber(bankBalance))
) {
console.log('2131232131221');
setTimeout(() => setFormErrors([LOCK_FEE_LACK_BALANCE_ERROR]), 100);
}
}

}, [gasFee, bankBalance, preLockFee, payLockFeeAccount.staticBalance, preLockFeeObject, loginAccount, isOwnerAccount]);
}, [gasFee, bankBalance, preLockFee, payLockFeeAccount.staticBalance, preLockFeeObject, loginAccount, isOwnerAccount]);

useEffect(() => {
setFormErrors([]);
Expand All @@ -357,7 +365,6 @@ export const CreateFolder = memo<modalProps>(function CreateFolderDrawer({ refet
gaShowName="dc.file.create_folder_m.0.show"
gaClickCloseName="dc.file.create_folder_m.close.click"
>
<QDrawerCloseButton />
<QDrawerHeader>Create a Folder</QDrawerHeader>
<QDrawerBody>
<Text
Expand Down
Loading

0 comments on commit 04a2d8d

Please sign in to comment.