-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathAssetList.jsx
63 lines (56 loc) · 1.73 KB
/
AssetList.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import React, { useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { Helmet } from 'react-helmet';
import { useTranslation } from 'react-i18next';
import AssetListRow from './AssetListRow';
import Loader from '../../App/components/loader';
import * as AssetActions from '../actions/assets';
const AssetList = () => {
const { t } = useTranslation();
const dispatch = useDispatch();
const { username, assetList, loading } = useSelector((state) => ({
username: state.user.username,
assetList: state.assets.list,
loading: state.loading
}));
useEffect(() => {
dispatch(AssetActions.getAssets());
}, []);
const hasAssets = () => !loading && assetList.length > 0;
const renderLoader = () => (loading ? <Loader /> : null);
const renderEmptyTable = () => {
if (!loading && assetList.length === 0) {
return (
<p className="asset-table__empty">{t('AssetList.NoUploadedAssets')}</p>
);
}
return null;
};
return (
<article className="asset-table-container">
<Helmet>
<title>{t('AssetList.Title')}</title>
</Helmet>
{renderLoader()}
{renderEmptyTable()}
{hasAssets() && (
<table className="asset-table">
<thead>
<tr>
<th>{t('AssetList.HeaderName')}</th>
<th>{t('AssetList.HeaderSize')}</th>
<th>{t('AssetList.HeaderSketch')}</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
{assetList.map((asset) => (
<AssetListRow asset={asset} key={asset.key} username={username} />
))}
</tbody>
</table>
)}
</article>
);
};
export default AssetList;