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

feat: ui updates #1391

Merged
merged 1 commit into from
Dec 29, 2023
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## [1.136.2](https://github.com/hirosystems/explorer/compare/v1.136.1...v1.136.2) (2023-12-27)


### Bug Fixes

* api url search param ([d71b374](https://github.com/hirosystems/explorer/commit/d71b374f8cfc16298b34515c5588b3e454de194a))

## [1.136.1](https://github.com/hirosystems/explorer/compare/v1.136.0...v1.136.1) (2023-12-27)


Expand Down
38 changes: 0 additions & 38 deletions src/app/__loading.tsx

This file was deleted.

5 changes: 3 additions & 2 deletions src/app/_components/AppConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import { useAppSelector } from '../../common/state/hooks';
import { NetworkMode } from '../../common/types/network';
import { Text } from '../../ui/Text';

Check warning on line 10 in src/app/_components/AppConfig.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/AppConfig.tsx#L10

Added line #L10 was not covered by tests
import { selectUserSession } from '../sandbox/sandbox-slice';

export const AppConfig: React.FC<{
Expand All @@ -18,7 +19,7 @@
const userSession = useAppSelector(selectUserSession);
useEffect(() => {
toast(
<div>
<Text fontSize={'sm'}>
You're viewing {querySubnet ? 'a subnet' : `the ${queryNetworkMode}`}
{querySubnet || queryApiUrl ? (
<>
Expand All @@ -27,7 +28,7 @@
</>
) : null}{' '}
Explorer
</div>,
</Text>,
{
id: 'network-mode-toast',
style: {
Expand Down
46 changes: 28 additions & 18 deletions src/app/_components/BlockList/AnimatedBlockAndMicroblocksItem.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
'use client';

import { ScaleFade, SlideFade } from '@chakra-ui/react';
import { FC, memo, useEffect, useState } from 'react';

import { Box } from '../../../ui/Box';
import { Button } from '../../../ui/Button';
import { Collapse } from '../../../ui/Collapse';
import { useDisclosure } from '../../../ui/hooks/useDisclosure';
import { BlockAndMicroblocksItem } from './BlockAndMicroblocksItem';
import { EnhancedBlock } from './types';

export const animationDuration = 0.25;
export const animationDuration = 0.8;

export const AnimatedBlockAndMicroblocksItem: FC<{
block: EnhancedBlock;
Expand All @@ -16,7 +20,9 @@ export const AnimatedBlockAndMicroblocksItem: FC<{
const [show, setShow] = useState(!block.animate);
useEffect(() => {
if (block.animate) {
setShow(true);
setTimeout(() => {
setShow(true);
}, 100);
}
}, [block.animate]);
useEffect(() => {
Expand All @@ -26,22 +32,26 @@ export const AnimatedBlockAndMicroblocksItem: FC<{
}, [block.destroy]);

return (
<Collapse
in={show}
animateOpacity
transition={{
enter: { duration: animationDuration },
exit: { duration: animationDuration },
}}
onAnimationComplete={state => {
if (state === 'exit') {
onAnimationExit?.();
}
}}
data-testid={`block-item-${block.hash}`}
>
<BlockAndMicroblocksItem block={block} />
</Collapse>
<>
<Box borderBottom={'1px'} _last={{ borderBottom: 'none' }}>
<Collapse
in={show}
animateOpacity
transition={{
enter: { duration: animationDuration },
exit: { duration: animationDuration },
}}
onAnimationComplete={state => {
if (state === 'exit') {
onAnimationExit?.();
}
}}
data-testid={`block-item-${block.hash}`}
>
<BlockAndMicroblocksItem block={block} />
</Collapse>
</Box>
</>
);
},
(prevProps, currentProps) =>
Expand Down
9 changes: 6 additions & 3 deletions src/app/_components/BlockList/BlockAndMicroblocksItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { memo } from 'react';

import { Block } from '@stacks/stacks-blockchain-api-types';

import { useVerticallyStackedElementsBorderStyle } from '../../../common/hooks/useVerticallyStackedElementsBorderStyle';
import { AccordionButton } from '../../../ui/AccordionButton';
import { AccordionIcon } from '../../../ui/AccordionIcon';
import { AccordionItem } from '../../../ui/AccordionItem';
Expand All @@ -15,7 +14,11 @@ import { MicroblockListItem } from './MicroblockListItem';
export const BlockAndMicroblocksItem: React.FC<{ block: Block }> = memo(
({ block }) => {
return (
<AccordionItem pl={'20px'} border={'none'}>
<AccordionItem
border={'none'}
borderBottom={'1px solid var(--stacks-colors-border)'}
_last={{ border: 'none' }}
>
<Flex gap={'6px'}>
<BlockListItem block={block} data-test={`block-${block.hash}`} />
<AccordionButton
Expand All @@ -29,7 +32,7 @@ export const BlockAndMicroblocksItem: React.FC<{ block: Block }> = memo(
<AccordionIcon />
</AccordionButton>
</Flex>
<AccordionPanel p={'0 30px 0 0'} css={useVerticallyStackedElementsBorderStyle}>
<AccordionPanel p={'0 30px 0 0'}>
{!!block.microblocks_accepted?.length ? (
block.microblocks_accepted.map((microblockHash, microblockIndex) => (
<MicroblockListItem
Expand Down
29 changes: 3 additions & 26 deletions src/app/_components/BlockList/BlockListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,21 @@ import React from 'react';
import { Block } from '@stacks/stacks-blockchain-api-types';

import { BtcStxBlockLinks } from '../../../common/components/BtcStxBlockLinks';
import { BlockLink } from '../../../common/components/ExplorerLinks';
import { TwoColsListItem } from '../../../common/components/TwoColumnsListItem';
import { addSepBetweenStrings, toRelativeTime, truncateMiddle } from '../../../common/utils/utils';
import { Circle } from '../../../ui/Circle';
import { Flex, FlexProps } from '../../../ui/Flex';
import { Icon } from '../../../ui/Icon';
import { CheckIcon } from '../../../ui/icons';
import { Caption, Text } from '../../../ui/typography';

export const BlockListItem: React.FC<{ block: Block } & FlexProps> = React.memo(
({ block, ...rest }) => {
return (
<TwoColsListItem
icon={
<BlockLink hash={block.hash}>
<Circle size="40px">
<Icon as={CheckIcon} size="16px" color={'textCaption.light'} />
</Circle>
</BlockLink>
}
leftContent={{
title: (
<Flex
onClick={e => {
e.stopPropagation();
}}
color={'textTitle'}
alignItems="center"
>
<BtcStxBlockLinks
Expand All @@ -42,7 +30,7 @@ export const BlockListItem: React.FC<{ block: Block } & FlexProps> = React.memo(
</Flex>
),
subtitle: (
<Caption display="block">
<Caption display="block" color={'secondaryText'}>
{addSepBetweenStrings([
`${block?.microblocks_accepted?.length || 0} ${pluralize(
'microblock',
Expand All @@ -57,19 +45,8 @@ export const BlockListItem: React.FC<{ block: Block } & FlexProps> = React.memo(
),
}}
rightContent={{
title: (
<Text
fontSize="14px"
width="100%"
textAlign="right"
color={'textBody'}
display="block"
suppressHydrationWarning={true}
>
{toRelativeTime(block.burn_block_time * 1000)}
</Text>
),
subtitle: <Caption display="block">{truncateMiddle(block.hash)}</Caption>,
title: toRelativeTime(block.burn_block_time * 1000),
subtitle: truncateMiddle(block.hash),
}}
{...rest}
/>
Expand Down
21 changes: 5 additions & 16 deletions src/app/_components/BlockList/BlockListWithControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function BlockListWithControls() {
<SectionWithControls
title="Recent Blocks"
controls={
<Stack spacing={'6px'}>
<Stack gap={1.5}>
<Flex justifyContent={'space-between'}>
<FormControl display="flex" alignItems="center" gap={'12px'} minW={0}>
<Switch
Expand Down Expand Up @@ -158,7 +158,7 @@ export function BlockListWithControls() {
</Text>
<TextLink
href={'javascript:void(0)'}
color={`brand.${colorMode}`}
color={`brand`}
_hover={{ textDecoration: 'underline' }}
onClick={() => {
setLoading(true);
Expand Down Expand Up @@ -187,20 +187,9 @@ export function BlockListWithControls() {
</Stack>
}
footer={
<>
<Button
width={'100%'}
backgroundColor={'#fff'}
color={'#242629'}
fontWeight={500}
borderWidth={'1px'}
_hover={{
backgroundColor: '#F9F9FA',
}}
>
View all recent blocks <Icon as={HiMiniArrowUpRight} width={'16px'} height={'16px'} />
</Button>
</>
<Button width={'full'} variant={'secondary'}>
View all recent blocks <Icon as={HiMiniArrowUpRight} size={4} />
</Button>
}
></SectionWithControls>
);
Expand Down
20 changes: 7 additions & 13 deletions src/app/_components/BlockList/MicroblockListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { useColorMode } from '@chakra-ui/react';
import React from 'react';
import { FiZap } from 'react-icons/fi';

import { Circle } from '../../../common/components/Circle';
import { MicroBlockLink } from '../../../common/components/ExplorerLinks';
import { toRelativeTime } from '../../../common/utils/utils';
import { Circle } from '../../../ui/Circle';
import { Flex } from '../../../ui/Flex';
import { HStack } from '../../../ui/HStack';
import { Icon } from '../../../ui/Icon';
import { Stack } from '../../../ui/Stack';
import { Caption, Text, Title } from '../../../ui/typography';
Expand All @@ -19,28 +20,21 @@ export const MicroblockListItem: React.FC<{
<Flex
justifyContent="space-between"
py="24px"
color={'textBody'}
_hover={{
borderLeftColor: 'accent',
}}
{...rest}
>
<Stack as="span" isInline alignItems="center" spacing="16px" minWidth={0}>
<HStack as="span" alignItems="center" gap={4} minWidth={0}>
<Circle size="40px" flexShrink={0}>
<Icon as={FiZap} size="16px" fill={'textCaption.light'} color={'textCaption.light'} />
</Circle>
<Stack spacing="8px" as="span" minWidth={0}>
<Stack gap={2} as="span" minWidth={0}>
<Flex alignItems="center" minWidth={0}>
<MicroBlockLink hash={hash}>
<Title
display="block"
fontSize={'14px'}
as="a"
color={`links.${useColorMode().colorMode}`}
_hover={{
cursor: 'pointer',
textDecoration: 'underline',
}}
fontSize={'sm'}
minWidth={0}
textOverflow={'ellipsis'}
overflow={'hidden'}
Expand All @@ -52,8 +46,8 @@ export const MicroblockListItem: React.FC<{
</Flex>
<Caption display="block">Microblock</Caption>
</Stack>
</Stack>
<Stack spacing="8px" textAlign="right" as="span" minWidth={'80px'}>
</HStack>
<Stack gap={2} textAlign="right" as="span" minWidth={'80px'}>
<Text
fontSize="14px"
width="100%"
Expand Down
20 changes: 20 additions & 0 deletions src/app/_components/BlockList/SkeletonBlockList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as React from 'react';

Check warning on line 1 in src/app/_components/BlockList/SkeletonBlockList.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/BlockList/SkeletonBlockList.tsx#L1

Added line #L1 was not covered by tests

import { Section } from '../../../common/components/Section';
import { TwoColumnsListItemSkeleton } from '../../../common/components/TwoColumnsListItemSkeleton';

Check warning on line 4 in src/app/_components/BlockList/SkeletonBlockList.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/BlockList/SkeletonBlockList.tsx#L3-L4

Added lines #L3 - L4 were not covered by tests

export const SkeletonBlockList = () => {

Check warning on line 6 in src/app/_components/BlockList/SkeletonBlockList.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/BlockList/SkeletonBlockList.tsx#L6

Added line #L6 was not covered by tests
return (
<Section title="Recent Blocks">
{[...Array(10)].map((_, i) => (
<TwoColumnsListItemSkeleton

Check warning on line 10 in src/app/_components/BlockList/SkeletonBlockList.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/BlockList/SkeletonBlockList.tsx#L10

Added line #L10 was not covered by tests
key={i}
leftContentSubtitle
leftContentTitle
rightContentSubtitle
rightContentTitle
/>
))}
</Section>
);
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { hash } from '@noble/hashes/_assert';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { act, fireEvent, render, screen, waitFor } from '@testing-library/react';
import React from 'react';
Expand All @@ -10,6 +9,7 @@ import {
import { Block } from '@stacks/stacks-blockchain-api-types';

import { useSuspenseBlockListInfinite as useSuspenseBlockListInfiniteActual } from '../../../../common/queries/useBlockListInfinite';
import '../../../../common/utils/test-utils/matchMedia.mock';
import { BlocksList } from '../index';
import { EnhancedBlock } from '../types';

Expand Down
Loading
Loading