|
1 | 1 | import PropTypes from 'prop-types'; |
2 | 2 | import classNames from 'classnames'; |
3 | | -import React, { useEffect, useState, useCallback } from 'react'; |
| 3 | +import React, { useEffect, useState, useMemo, useCallback } from 'react'; |
4 | 4 | import { Helmet } from 'react-helmet'; |
5 | 5 | import { connect } from 'react-redux'; |
6 | 6 | import { useTranslation } from 'react-i18next'; |
7 | 7 | import { bindActionCreators } from 'redux'; |
8 | | -import * as ProjectsActions from '../actions/projects'; // Added Projects actions |
9 | | -import * as CollectionsActions from '../actions/collections'; // Added Collections actions |
10 | | -import * as ToastActions from '../actions/toast'; // Added Toast actions |
11 | | -import * as SortingActions from '../actions/sorting'; // Added Sorting actions |
| 8 | +import * as ProjectsActions from '../actions/projects'; |
| 9 | +import * as CollectionsActions from '../actions/collections'; |
| 10 | +import * as ToastActions from '../actions/toast'; |
| 11 | +import * as SortingActions from '../actions/sorting'; |
12 | 12 | import getSortedSketches from '../selectors/projects'; |
13 | 13 | import Loader from '../../App/components/loader'; |
14 | 14 | import Overlay from '../../App/components/Overlay'; |
@@ -43,7 +43,7 @@ const SketchList = ({ |
43 | 43 | } |
44 | 44 | }, [sketches]); |
45 | 45 |
|
46 | | - const getSketchesTitle = useCallback( |
| 46 | + const getSketchesTitle = useMemo( |
47 | 47 | () => |
48 | 48 | username === user.username |
49 | 49 | ? t('SketchList.Title') |
@@ -81,44 +81,47 @@ const SketchList = ({ |
81 | 81 | [sorting, t] |
82 | 82 | ); |
83 | 83 |
|
84 | | - const renderFieldHeader = (fieldName, displayName) => { |
85 | | - const { field, direction } = sorting; |
86 | | - const headerClass = classNames({ |
87 | | - 'sketches-table__header': true, |
88 | | - 'sketches-table__header--selected': field === fieldName |
89 | | - }); |
90 | | - const buttonLabel = getButtonLabel(fieldName, displayName); |
91 | | - return ( |
92 | | - <th scope="col"> |
93 | | - <button |
94 | | - className="sketch-list__sort-button" |
95 | | - onClick={() => toggleDirectionForField(fieldName)} |
96 | | - aria-label={buttonLabel} |
97 | | - > |
98 | | - <span className={headerClass}>{displayName}</span> |
99 | | - {field === fieldName && |
100 | | - (direction === SortingActions.DIRECTION.ASC ? ( |
101 | | - <ArrowUpIcon |
102 | | - focusable="false" |
103 | | - role="img" |
104 | | - aria-label={t('SketchList.DirectionAscendingARIA')} |
105 | | - /> |
106 | | - ) : ( |
107 | | - <ArrowDownIcon |
108 | | - focusable="false" |
109 | | - role="img" |
110 | | - aria-label={t('SketchList.DirectionDescendingARIA')} |
111 | | - /> |
112 | | - ))} |
113 | | - </button> |
114 | | - </th> |
115 | | - ); |
116 | | - }; |
| 84 | + const renderFieldHeader = useCallback( |
| 85 | + (fieldName, displayName) => { |
| 86 | + const { field, direction } = sorting; |
| 87 | + const headerClass = classNames({ |
| 88 | + 'sketches-table__header': true, |
| 89 | + 'sketches-table__header--selected': field === fieldName |
| 90 | + }); |
| 91 | + const buttonLabel = getButtonLabel(fieldName, displayName); |
| 92 | + return ( |
| 93 | + <th scope="col"> |
| 94 | + <button |
| 95 | + className="sketch-list__sort-button" |
| 96 | + onClick={() => toggleDirectionForField(fieldName)} |
| 97 | + aria-label={buttonLabel} |
| 98 | + > |
| 99 | + <span className={headerClass}>{displayName}</span> |
| 100 | + {field === fieldName && |
| 101 | + (direction === SortingActions.DIRECTION.ASC ? ( |
| 102 | + <ArrowUpIcon |
| 103 | + focusable="false" |
| 104 | + role="img" |
| 105 | + aria-label={t('SketchList.DirectionAscendingARIA')} |
| 106 | + /> |
| 107 | + ) : ( |
| 108 | + <ArrowDownIcon |
| 109 | + focusable="false" |
| 110 | + role="img" |
| 111 | + aria-label={t('SketchList.DirectionDescendingARIA')} |
| 112 | + /> |
| 113 | + ))} |
| 114 | + </button> |
| 115 | + </th> |
| 116 | + ); |
| 117 | + }, |
| 118 | + [sorting, getButtonLabel, toggleDirectionForField, t] |
| 119 | + ); |
117 | 120 |
|
118 | 121 | return ( |
119 | 122 | <article className="sketches-table-container"> |
120 | 123 | <Helmet> |
121 | | - <title>{getSketchesTitle()}</title> |
| 124 | + <title>{getSketchesTitle}</title> |
122 | 125 | </Helmet> |
123 | 126 | {renderLoader()} |
124 | 127 | {renderEmptyTable()} |
|
0 commit comments