Skip to content

frontend: WIP search txs #3448

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions frontends/web/src/routes/account/account.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,77 @@

.txHistorySkeleton {
margin-top: var(--space-quarter);
}

.searchContainer {
position: relative;
display: flex;
align-items: center;
margin-bottom: var(--space-half);
}

.searchInput {
background-color: var(--background-secondary);
border: 1px solid transparent;
border-radius: 0;
color: var(--color-default);
font-size: var(--size-default);
width: 100%;
padding: calc(var(--space-quarter) + var(--space-eight)) var(--space-half);
padding-left: 28px;
outline: none;
transition: border-color .2s ease-out;
}

.searchInput:focus {
border: 1px solid var(--color-blue);
outline: none;
box-shadow: none;
}

.searchInput.withClearButton {
padding-right: 28px;
}

.searchIcon {
position: absolute;
left: 8px;
top: 50%;
transform: translateY(-50%);
width: 16px;
height: 16px;
pointer-events: none;
opacity: 0.6;
}

.clearButton {
position: absolute;
right: 12px;
top: 50%;
transform: translateY(-50%);
background: none;
border: none;
cursor: pointer;
font-size: 16px;
padding: 0;
width: 16px;
height: 16px;
display: flex;
align-items: center;
justify-content: center;
}

.clearButton:hover {
opacity: 1;
}

.headerControls {
display: flex;
gap: var(--space-quarter);
align-items: center;
}

.clearButtonIcon {
width: 16px;
height: 16px;
}
145 changes: 117 additions & 28 deletions frontends/web/src/routes/account/account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { useCallback, useContext, useEffect, useState } from 'react';
import React, { useCallback, useContext, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { Link } from 'react-router-dom';
import * as accountApi from '@/api/account';
Expand All @@ -27,7 +27,7 @@ import { useSDCard } from '@/hooks/sdcard';
import { alertUser } from '@/components/alert/Alert';
import { Balance } from '@/components/balance/balance';
import { HeadersSync } from '@/components/headerssync/headerssync';
import { Info } from '@/components/icon';
import { CloseXDark, CloseXWhite, Info, Loupe } from '@/components/icon';
import { GuidedContent, GuideWrapper, Header, Main } from '@/components/layout';
import { Spinner } from '@/components/spinner/Spinner';
import { Status } from '@/components/status/status';
Expand All @@ -51,8 +51,62 @@ import { TransactionDetails } from '@/components/transactions/details';
import { Button } from '@/components/forms';
import { SubTitle } from '@/components/title';
import { TransactionHistorySkeleton } from '@/routes/account/transaction-history-skeleton';
import style from './account.module.css';
import { RatesContext } from '@/contexts/RatesContext';
import { useDarkmode } from '@/hooks/darkmode';
import style from './account.module.css';

const SearchInput = React.memo(({
placeholder,
onSearchChange
}: {
placeholder: string;
onSearchChange?: (searchTerm: string) => void;
}) => {
const [query, setQuery] = useState<string>('');
const { isDarkMode } = useDarkmode();

const handleChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
const value = e.target.value;
setQuery(value);
}, []);

const handleClear = useCallback(() => {
setQuery('');
onSearchChange?.('');
}, [onSearchChange]);

useEffect(() => {
const timeoutId = setTimeout(() => {
onSearchChange?.(query);
}, 300);

return () => clearTimeout(timeoutId);
}, [query, onSearchChange]);

return (
<div className={style.searchContainer}>
<Loupe className={style.searchIcon} />
<input
type="text"
placeholder={placeholder}
value={query}
onChange={handleChange}
className={`${style.searchInput} ${query ? style.withClearButton : ''}`}
/>
{query && (
<button
onClick={handleClear}
className={style.clearButton}
title="Clear search"
>
{isDarkMode ? <CloseXWhite className={style.clearButtonIcon} /> : <CloseXDark className={style.clearButtonIcon} />}
</button>
)}
</div>
);
});

SearchInput.displayName = 'SearchInput';

type Props = {
accounts: accountApi.IAccount[];
Expand Down Expand Up @@ -91,6 +145,8 @@ const RemountAccount = ({
const [detailID, setDetailID] = useState<accountApi.ITransaction['internalID'] | null>(null);
const supportedExchanges = useLoad<SupportedExchanges>(getExchangeSupported(code), [code]);

const [debouncedSearchQuery, setDebouncedSearchQuery] = useState<string>('');

const account = accounts && accounts.find(acct => acct.code === code);

const getBitsuranceGuideLink = (): string => {
Expand Down Expand Up @@ -196,6 +252,22 @@ const RemountAccount = ({
.catch(console.error);
};

const handleDebouncedSearch = useCallback((searchTerm: string) => {
setDebouncedSearchQuery(searchTerm);
}, []);

// Filter transactions based on debounced search query
const filteredTransactions = debouncedSearchQuery && transactions?.success
? {
...transactions,
list: transactions.list.filter(tx => {
const searchLower = debouncedSearchQuery.toLowerCase();
return tx.txID.toLowerCase().includes(searchLower) ||
tx.note.toLowerCase().includes(searchLower);
})
}
: transactions;

const hasDataLoaded = balance !== undefined && transactions !== undefined;

if (!account) {
Expand Down Expand Up @@ -235,7 +307,6 @@ const RemountAccount = ({
&& transactions.success
&& transactions.list.length === 0;


const actionButtonsProps = {
code,
accountDataLoaded: hasDataLoaded,
Expand All @@ -247,6 +318,7 @@ const RemountAccount = ({

const loadingTransactions = transactions?.success === undefined;
const hasTransactions = transactions?.success && transactions.list.length > 0;
const showingFilteredResults = debouncedSearchQuery && transactions?.success;

return (
<GuideWrapper>
Expand Down Expand Up @@ -299,7 +371,7 @@ const RemountAccount = ({
</ViewHeader>
<ViewContent fullWidth>
<div className={style.accountHeader}>
{isAccountEmpty && (
{isAccountEmpty && balance && (
<BuyReceiveCTA
account={account}
code={code}
Expand All @@ -316,35 +388,52 @@ const RemountAccount = ({
) : !isAccountEmpty && (
<SubTitle className={style.titleWithButton}>
{t('accountSummary.transactionHistory')}
<Button
transparent
disabled={!hasTransactions}
className={style.exportButton}
onClick={exportAccount}
title={t('account.exportTransactions')}>
{t('account.export')}
</Button>
<div className={style.headerControls}>
<Button
transparent
disabled={!hasTransactions}
className={style.exportButton}
onClick={exportAccount}
title={t('account.exportTransactions')}>
{t('account.export')}
</Button>
</div>
</SubTitle>
)}

{hasTransactions && (
<SearchInput
placeholder={t('account.searchTransactions', 'Search by transaction ID or notes')}
onSearchChange={handleDebouncedSearch}
/>
)}

{showingFilteredResults && filteredTransactions?.success && filteredTransactions.list.length === 0 && (
<p className={style.emptyTransactions}>
No transactions found matching "{debouncedSearchQuery}" in transaction ID or notes
</p>
)}
</div>

{loadingTransactions && <TransactionHistorySkeleton />}

{hasTransactions ? (
transactions.list.map(tx => (
<Transaction
key={tx.internalID}
onShowDetail={(internalID: accountApi.ITransaction['internalID']) => {
setDetailID(internalID);
}}
{...tx}
/>
))
) : transactions?.success && (
<p className={style.emptyTransactions}>
{t('transactions.placeholder')}
</p>
)}
<div className={style.transactionsList}>
{filteredTransactions?.success && filteredTransactions.list.length > 0 ? (
filteredTransactions.list.map(tx => (
<Transaction
key={tx.internalID}
onShowDetail={(internalID: accountApi.ITransaction['internalID']) => {
setDetailID(internalID);
}}
{...tx}
/>
))
) : transactions?.success && !showingFilteredResults ? (
<p className={style.emptyTransactions}>
{t('transactions.placeholder')}
</p>
) : null}
</div>

<TransactionDetails
accountCode={code}
Expand Down