Skip to content

Commit

Permalink
feat: redesign - add search to nav
Browse files Browse the repository at this point in the history
  • Loading branch information
He1DAr committed Feb 20, 2025
1 parent b68a048 commit 8a444dc
Show file tree
Hide file tree
Showing 11 changed files with 366 additions and 86 deletions.
30 changes: 28 additions & 2 deletions src/app/_components/NewNavBar/NavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,37 @@
import { Input } from '@/ui/Input';
import { Box, Flex, FlexProps, Icon, useDisclosure } from '@chakra-ui/react';
import { List } from '@phosphor-icons/react';
import { useSearchParams } from 'next/navigation';

Check warning on line 6 in src/app/_components/NewNavBar/NavBar.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/NewNavBar/NavBar.tsx#L6

Added line #L6 was not covered by tests
import { useEffect, useState } from 'react';

import {
buildAdvancedSearchQuery,
getRecentResultsLocalStorage,
} from '../../../common/queries/useSearchQuery';
import { Search } from '../Search/Search';

Check warning on line 13 in src/app/_components/NewNavBar/NavBar.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/NewNavBar/NavBar.tsx#L12-L13

Added lines #L12 - L13 were not covered by tests
import { FeePopover } from './FeePopover';
import { Logo } from './Logo';
import { MobileNavPage } from './MobileNavPage';
import { PagesSlidingMenu } from './PagesSlidingMenu';
import { SettingsPopover } from './SettingsPopover';

const DesktopNavBar = (props: any) => {
const params = new URLSearchParams(useSearchParams());
const filterParams: Record<string, string> = {};
params.forEach((value, filter) => {

Check warning on line 23 in src/app/_components/NewNavBar/NavBar.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/NewNavBar/NavBar.tsx#L21-L23

Added lines #L21 - L23 were not covered by tests
if (
filter === 'fromAddress' ||
filter === 'toAddress' ||
filter === 'startTime' ||
filter === 'endTime' ||
filter.startsWith('term_')

Check warning on line 29 in src/app/_components/NewNavBar/NavBar.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/NewNavBar/NavBar.tsx#L26-L29

Added lines #L26 - L29 were not covered by tests
) {
filterParams[filter] = value;

Check warning on line 31 in src/app/_components/NewNavBar/NavBar.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/NewNavBar/NavBar.tsx#L31

Added line #L31 was not covered by tests
}
});
const searchTermFromQueryParams = buildAdvancedSearchQuery(filterParams);
const recentResults = getRecentResultsLocalStorage();

Check warning on line 35 in src/app/_components/NewNavBar/NavBar.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/NewNavBar/NavBar.tsx#L34-L35

Added lines #L34 - L35 were not covered by tests

return (
<Flex
width="full"
Expand All @@ -24,8 +47,11 @@ const DesktopNavBar = (props: any) => {
<Logo logoSize={10} />
<PagesSlidingMenu width={50} />
</Flex>
<Flex flexGrow={1} flexShrink={1} maxWidth="474px">
<Input placeholder="Explore" bg="surfaceSecondary" variant="redesignPrimary" />
<Flex flexGrow={1} flexShrink={1} maxWidth="507px">
<Search
searchTermFromQueryParams={searchTermFromQueryParams}
recentResults={recentResults}
/>
</Flex>
<Flex gap={4}>
<FeePopover />
Expand Down
109 changes: 88 additions & 21 deletions src/app/_components/Search/ResultItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
ContractDeployTxs,
TokenTransferTxs,
} from '../../../common/types/tx';
import { buildUrl } from '../../../common/utils/buildUrl';
import {
getContractName,
microToStacksFormatted,
Expand Down Expand Up @@ -70,21 +71,31 @@ function ResultItemIcon({ type }: { type?: 'arrow' | 'enter' | undefined }) {
return null;
}

export function ResultItem({ value }: { value: string }) {
export function ResultItem({

Check warning on line 74 in src/app/_components/Search/ResultItem.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/Search/ResultItem.tsx#L74

Added line #L74 was not covered by tests
value,
url,
iconType = 'arrow',
}: {
value: string;
url: string;
iconType?: 'arrow' | 'enter';
}) {

Check warning on line 82 in src/app/_components/Search/ResultItem.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/Search/ResultItem.tsx#L82

Added line #L82 was not covered by tests
return (
<ResultItemWrapper>
<SearchLink href={'#'}>{value}</SearchLink>
<ResultItemIcon type={'arrow'} />
<SearchLink href={url}>{value}</SearchLink>
<ResultItemIcon type={iconType} />
</ResultItemWrapper>
);
}

function TxResultItem({
tx,
children,
iconType = 'arrow',
}: {
tx: Transaction | MempoolTransaction;
children: ReactNode;
iconType?: 'arrow' | 'enter';
}) {
return (
<ResultItemWrapper>
Expand All @@ -100,15 +111,23 @@ function TxResultItem({
}
/>
</Flex>
<ResultItemIcon type={'arrow'} />
<ResultItemIcon type={iconType} />
</ResultItemWrapper>
);
}

export function TokenTransferResultItem({ tx }: { tx: TokenTransferTxs }) {
export function TokenTransferResultItem({

Check warning on line 119 in src/app/_components/Search/ResultItem.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/Search/ResultItem.tsx#L119

Added line #L119 was not covered by tests
tx,
url,
iconType = 'arrow',
}: {
tx: TokenTransferTxs;
url: string;
iconType?: 'arrow' | 'enter';
}) {

Check warning on line 127 in src/app/_components/Search/ResultItem.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/Search/ResultItem.tsx#L127

Added line #L127 was not covered by tests
return (
<TxResultItem tx={tx}>
<SearchLink href={'#'}>{microToStacksFormatted(tx.token_transfer.amount)} STX</SearchLink>
<TxResultItem tx={tx} iconType={iconType}>
<SearchLink href={url}>{microToStacksFormatted(tx.token_transfer.amount)} STX</SearchLink>
<Flex gap={1.5} alignItems={'center'}>
<Text fontSize={'sm'} color={'textPrimary'} whiteSpace={'nowrap'}>
{truncateMiddle(tx.sender_address, 4)}
Expand All @@ -124,32 +143,56 @@ export function TokenTransferResultItem({ tx }: { tx: TokenTransferTxs }) {
);
}

export function ContractDeployResultItem({ tx }: { tx: ContractDeployTxs }) {
export function ContractDeployResultItem({

Check warning on line 146 in src/app/_components/Search/ResultItem.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/Search/ResultItem.tsx#L146

Added line #L146 was not covered by tests
tx,
url,
iconType = 'arrow',
}: {
tx: ContractDeployTxs;
url: string;
iconType?: 'arrow' | 'enter';
}) {

Check warning on line 154 in src/app/_components/Search/ResultItem.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/Search/ResultItem.tsx#L154

Added line #L154 was not covered by tests
return (
<TxResultItem tx={tx}>
<SearchLink href={'#'}>{getContractName(tx.smart_contract.contract_id)}</SearchLink>
<SearchLink href={url}>{getContractName(tx.smart_contract.contract_id)}</SearchLink>
<Text fontSize={'sm'} color={'textPrimary'} whiteSpace={'nowrap'}>
{truncateMiddle(tx.tx_id, 4)}
</Text>
</TxResultItem>
);
}

export function ContractCallResultItem({ tx }: { tx: ContractCallTxs }) {
export function ContractCallResultItem({

Check warning on line 165 in src/app/_components/Search/ResultItem.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/Search/ResultItem.tsx#L165

Added line #L165 was not covered by tests
tx,
url,
iconType = 'arrow',
}: {
tx: ContractCallTxs;
url: string;
iconType?: 'arrow' | 'enter';
}) {

Check warning on line 173 in src/app/_components/Search/ResultItem.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/Search/ResultItem.tsx#L173

Added line #L173 was not covered by tests
return (
<TxResultItem tx={tx}>
<SearchLink href={'#'}>{tx.contract_call.function_name}</SearchLink>
<SearchLink href={url}>{tx.contract_call.function_name}</SearchLink>
<Text fontSize={'sm'} color={'textPrimary'} whiteSpace={'nowrap'}>
{truncateMiddle(tx.tx_id, 4)}
</Text>
</TxResultItem>
);
}

export function CoinbaseResultItem({ tx }: { tx: CoinbaseTxs }) {
export function CoinbaseResultItem({

Check warning on line 184 in src/app/_components/Search/ResultItem.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/Search/ResultItem.tsx#L184

Added line #L184 was not covered by tests
tx,
url,
iconType = 'arrow',
}: {
tx: CoinbaseTxs;
url: string;
iconType?: 'arrow' | 'enter';
}) {

Check warning on line 192 in src/app/_components/Search/ResultItem.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/Search/ResultItem.tsx#L192

Added line #L192 was not covered by tests
return (
<TxResultItem tx={tx}>
<SearchLink href={'#'}>Coinbase</SearchLink>
<SearchLink href={url}>Coinbase</SearchLink>
<Text fontSize={'sm'} color={'textPrimary'} whiteSpace={'nowrap'}>
{truncateMiddle(tx.tx_id, 4)}
</Text>
Expand All @@ -159,38 +202,62 @@ export function CoinbaseResultItem({ tx }: { tx: CoinbaseTxs }) {

export function TenureChangeResultItem({
tx,
url,
iconType = 'arrow',
}: {
tx: TenureChangeTransaction | MempoolTenureChangeTransaction;
url: string;
iconType?: 'arrow' | 'enter';
}) {
return (
<TxResultItem tx={tx}>
<SearchLink href={'#'}>Tenure Change</SearchLink>
<SearchLink href={url}>Tenure Change</SearchLink>
<Text fontSize={'sm'} color={'textPrimary'} whiteSpace={'nowrap'}>
{truncateMiddle(tx.tx_id, 4)}
</Text>
</TxResultItem>
);
}

export function BnsResultItem({ bns, address }: { bns: string; address: string }) {
export function BnsResultItem({

Check warning on line 222 in src/app/_components/Search/ResultItem.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/Search/ResultItem.tsx#L222

Added line #L222 was not covered by tests
bns,
address,
url,
iconType = 'arrow',
}: {
bns: string;
address: string;
url: string;
iconType?: 'arrow' | 'enter';
}) {

Check warning on line 232 in src/app/_components/Search/ResultItem.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/Search/ResultItem.tsx#L232

Added line #L232 was not covered by tests
return (
<ResultItemWrapper>
<Flex gap={4} flex={'1 1 auto'} minWidth={0}>
<SearchLink href={'#'}>{bns}</SearchLink>
<SearchLink href={url}>{bns}</SearchLink>
<Text fontSize={'sm'} color={'textPrimary'} whiteSpace={'nowrap'}>
{truncateMiddle(address, 5)}
</Text>
</Flex>
<ResultItemIcon type={'arrow'} />
<ResultItemIcon type={iconType} />
</ResultItemWrapper>
);
}

export function BlockResultItem({ height, hash }: { height: number; hash: string }) {
export function BlockResultItem({

Check warning on line 246 in src/app/_components/Search/ResultItem.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/Search/ResultItem.tsx#L246

Added line #L246 was not covered by tests
height,
hash,
url,
iconType = 'arrow',
}: {
height: number;
hash: string;
url: string;
iconType?: 'arrow' | 'enter';
}) {

Check warning on line 256 in src/app/_components/Search/ResultItem.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/Search/ResultItem.tsx#L256

Added line #L256 was not covered by tests
return (
<ResultItemWrapper py={2.5}>
<Flex gap={4} flex={'1 1 auto'} minWidth={0}>
<TextLink href={'#'}>
<SearchLink href={url}>
<Flex
alignItems={'center'}
gap={1.5}
Expand Down Expand Up @@ -219,12 +286,12 @@ export function BlockResultItem({ height, hash }: { height: number; hash: string
#{height}
</Text>
</Flex>
</TextLink>
</SearchLink>
<Text fontSize={'sm'} color={'textPrimary'} whiteSpace={'nowrap'}>
{truncateMiddle(hash, 4)}
</Text>
</Flex>
<ResultItemIcon type={'arrow'} />
<ResultItemIcon type={iconType} />
</ResultItemWrapper>
);
}
Loading

0 comments on commit 8a444dc

Please sign in to comment.