From 4f4b73e07cf1743843675238971262146f7d9ad6 Mon Sep 17 00:00:00 2001 From: theborakompanioni Date: Fri, 29 Mar 2024 21:02:37 +0100 Subject: [PATCH] ui(orderbook): add delay hint to highlighted offer toggle --- src/components/Orderbook.tsx | 26 +++++++++++++------------- src/i18n/locales/en/translation.json | 1 + 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/components/Orderbook.tsx b/src/components/Orderbook.tsx index 71c70c0e..e2c2f8f8 100644 --- a/src/components/Orderbook.tsx +++ b/src/components/Orderbook.tsx @@ -1,4 +1,4 @@ -import { ReactElement, ChangeEvent, useCallback, useEffect, useMemo, useState } from 'react' +import { ReactElement, useCallback, useEffect, useMemo, useState } from 'react' import { Table, Header, HeaderRow, HeaderCell, Body, Row, Cell } from '@table-library/react-table-library/table' import { usePagination } from '@table-library/react-table-library/pagination' import { useSort, HeaderCellSort, SortToggleType } from '@table-library/react-table-library/sort' @@ -16,6 +16,7 @@ import TablePagination from './TablePagination' import { factorToPercentage, isAbsoluteOffer, isRelativeOffer } from '../utils' import { isDevMode } from '../constants/debugFeatures' import styles from './Orderbook.module.css' +import ToggleSwitch from './ToggleSwitch' const TABLE_THEME = { Table: ` @@ -352,13 +353,13 @@ export function Orderbook({ entries, refresh, nickname }: OrderbookProps) { [tableData], ) + const ownOffers = useMemo(() => { + return nickname ? entries.filter((it) => it.counterparty === nickname) : [] + }, [nickname, entries]) + useEffect(() => { - if (!nickname || !isHighlightOwnOffers) { - setHighlightedOrders([]) - } else { - setHighlightedOrders(entries.filter((it) => it.counterparty === nickname)) - } - }, [entries, nickname, isHighlightOwnOffers]) + setHighlightedOrders(isHighlightOwnOffers ? ownOffers : []) + }, [ownOffers, isHighlightOwnOffers]) return (
@@ -424,13 +425,12 @@ export function Orderbook({ entries, refresh, nickname }: OrderbookProps) { <> {nickname && (
- ) => { - setIsHighlightOwnOffers(e.target.checked) - }} + subtitle={ownOffers.length === 0 ? t('orderbook.text_highlight_own_orders_subtitle') : undefined} + toggledOn={isHighlightOwnOffers} + onToggle={(isToggled) => setIsHighlightOwnOffers(isToggled)} + disabled={isLoadingRefresh} />
)} diff --git a/src/i18n/locales/en/translation.json b/src/i18n/locales/en/translation.json index f32e6e2b..ad7b6618 100644 --- a/src/i18n/locales/en/translation.json +++ b/src/i18n/locales/en/translation.json @@ -602,6 +602,7 @@ "placeholder_search": "Search", "text_orderbook_filter_count": "{{ filterCount }} entries match given search criteria", "label_highlight_own_orders": "Highlight my offers", + "text_highlight_own_orders_subtitle": "It might take some time for your offer and your bond to appear in your local orderbook.", "table": { "heading_type": "Type", "heading_counterparty": "Counterparty",