|
1 | | -import React, { useCallback, useEffect } from 'react' |
| 1 | +import React, { useCallback, useEffect, useMemo } from 'react' |
2 | 2 | import { RouteComponentProps } from 'react-router-dom' |
3 | 3 | import { useTranslation } from 'react-i18next' |
4 | 4 | import { Stack, SearchBox } from 'office-ui-fabric-react' |
@@ -33,47 +33,65 @@ const History = ({ |
33 | 33 | }, [id, history]) |
34 | 34 | const onSearch = useCallback(() => history.push(`${Routes.History}?keywords=${keywords}`), [history, keywords]) |
35 | 35 |
|
36 | | - return ( |
37 | | - <Stack> |
38 | | - <Stack horizontal horizontalAlign="end" tokens={{ childrenGap: 15 }}> |
39 | | - <SearchBox |
40 | | - value={keywords} |
41 | | - styles={{ root: { width: 500 } }} |
42 | | - placeholder={t('history.search.placeholder')} |
43 | | - onChange={onKeywordsChange} |
44 | | - onSearch={onSearch} |
45 | | - iconProps={{ iconName: 'Search', styles: { root: { height: '18px' } } }} |
| 36 | + const List = useMemo(() => { |
| 37 | + return ( |
| 38 | + <Stack> |
| 39 | + <Stack horizontal horizontalAlign="end" tokens={{ childrenGap: 15 }}> |
| 40 | + <SearchBox |
| 41 | + value={keywords} |
| 42 | + styles={{ root: { width: 500 } }} |
| 43 | + placeholder={t('history.search.placeholder')} |
| 44 | + onChange={onKeywordsChange} |
| 45 | + onSearch={onSearch} |
| 46 | + iconProps={{ iconName: 'Search', styles: { root: { height: '18px' } } }} |
| 47 | + /> |
| 48 | + </Stack> |
| 49 | + <TransactionList |
| 50 | + isLoading={isLoading} |
| 51 | + isUpdatingDescription={isUpdatingDescription} |
| 52 | + walletID={id} |
| 53 | + items={items} |
| 54 | + dispatch={dispatch} |
| 55 | + /> |
| 56 | + <Pagination |
| 57 | + selectedPageIndex={pageNo - 1} |
| 58 | + pageCount={Math.ceil(totalCount / pageSize)} |
| 59 | + itemsPerPage={pageSize} |
| 60 | + totalItemCount={totalCount} |
| 61 | + previousPageAriaLabel={t('pagination.previous-page')} |
| 62 | + nextPageAriaLabel={t('pagination.next-page')} |
| 63 | + firstPageAriaLabel={t('pagination.first-page')} |
| 64 | + lastPageAriaLabel={t('pagination.last-page')} |
| 65 | + pageAriaLabel={t('pagination-page')} |
| 66 | + selectedAriaLabel={t('pagination-selected')} |
| 67 | + firstPageIconProps={{ iconName: 'FirstPage' }} |
| 68 | + previousPageIconProps={{ iconName: 'PrevPage' }} |
| 69 | + nextPageIconProps={{ iconName: 'NextPage' }} |
| 70 | + lastPageIconProps={{ iconName: 'LastPage' }} |
| 71 | + format="buttons" |
| 72 | + onPageChange={(idx: number) => { |
| 73 | + history.push(`${Routes.History}?pageNo=${idx + 1}`) |
| 74 | + }} |
46 | 75 | /> |
47 | 76 | </Stack> |
48 | | - <TransactionList |
49 | | - isLoading={isLoading} |
50 | | - isUpdatingDescription={isUpdatingDescription} |
51 | | - walletID={id} |
52 | | - items={items} |
53 | | - dispatch={dispatch} |
54 | | - /> |
55 | | - <Pagination |
56 | | - selectedPageIndex={pageNo - 1} |
57 | | - pageCount={Math.ceil(totalCount / pageSize)} |
58 | | - itemsPerPage={pageSize} |
59 | | - totalItemCount={totalCount} |
60 | | - previousPageAriaLabel={t('pagination.previous-page')} |
61 | | - nextPageAriaLabel={t('pagination.next-page')} |
62 | | - firstPageAriaLabel={t('pagination.first-page')} |
63 | | - lastPageAriaLabel={t('pagination.last-page')} |
64 | | - pageAriaLabel={t('pagination-page')} |
65 | | - selectedAriaLabel={t('pagination-selected')} |
66 | | - firstPageIconProps={{ iconName: 'FirstPage' }} |
67 | | - previousPageIconProps={{ iconName: 'PrevPage' }} |
68 | | - nextPageIconProps={{ iconName: 'NextPage' }} |
69 | | - lastPageIconProps={{ iconName: 'LastPage' }} |
70 | | - format="buttons" |
71 | | - onPageChange={(idx: number) => { |
72 | | - history.push(`${Routes.History}?pageNo=${idx + 1}`) |
73 | | - }} |
74 | | - /> |
75 | | - </Stack> |
76 | | - ) |
| 77 | + ) |
| 78 | + }, [ |
| 79 | + keywords, |
| 80 | + onKeywordsChange, |
| 81 | + onSearch, |
| 82 | + isLoading, |
| 83 | + isUpdatingDescription, |
| 84 | + id, |
| 85 | + items, |
| 86 | + dispatch, |
| 87 | + pageNo, |
| 88 | + totalCount, |
| 89 | + pageSize, |
| 90 | + history, |
| 91 | + t, |
| 92 | + ]) |
| 93 | + |
| 94 | + return List |
77 | 95 | } |
78 | 96 |
|
79 | 97 | History.displayName = 'History' |
|
0 commit comments