|
1 | | -import React, { Component } from 'react' |
2 | | - |
3 | | -import { Table } from 'reactstrap' |
4 | | -import NameCellRenderer from './Grid/cell-renderers/NameCellRenderer' |
5 | | -import TypeCellRenderer from './Grid/cell-renderers/TypeCellRenderer' |
| 1 | +import React, { useEffect, useState } from 'react' |
| 2 | +import InfiniteScroll from 'react-infinite-scroll-component' |
| 3 | +import { ListGroup, ListGroupItem } from 'reactstrap' |
6 | 4 | import ActionCellRenderer from './Grid/cell-renderers/ActionCellRenderer' |
7 | | -import VersionCellRenderer from './Grid/cell-renderers/VersionCellRenderer' |
8 | | - |
9 | | -const XL_WIDTH = 1200 |
10 | | -const L_WIDTH = 992 |
11 | | -const M_WIDTH = 768 |
12 | | -const S_WIDTH = 576 |
13 | 5 |
|
14 | | -class AppsList extends Component { |
15 | | - render() { |
16 | | - return ( |
17 | | - <Table> |
18 | | - <thead> |
19 | | - <tr> |
20 | | - <th>Name</th> |
21 | | - <th |
22 | | - className={ |
23 | | - 'text-center ' + (window.innerWidth < S_WIDTH ? 'd-none' : '') |
24 | | - } |
25 | | - > |
26 | | - Version |
27 | | - </th> |
28 | | - <th className={window.innerWidth < L_WIDTH ? 'd-none' : ''}> |
29 | | - Description |
30 | | - </th> |
31 | | - <th className={window.innerWidth < XL_WIDTH ? 'd-none' : ''}> |
32 | | - Author |
33 | | - </th> |
34 | | - <th |
35 | | - className={ |
36 | | - 'text-center ' + (window.innerWidth < M_WIDTH ? 'd-none' : '') |
37 | | - } |
38 | | - > |
39 | | - <div>Type</div> |
40 | | - </th> |
| 6 | +export function AppListItem(app) { |
| 7 | + return ( |
| 8 | + <ListGroupItem className="p-3"> |
| 9 | + <div className="d-md-flex align-items-center flex-grow-1"> |
| 10 | + <div className="flex-grow-1 mr-3"> |
| 11 | + <h5 className="text-dark mb-0">{app.name}</h5> |
| 12 | + <div className="text-muted"> |
| 13 | + <span className="font-weight-bolder"> |
| 14 | + v{app.installedVersion || app.version}{' '} |
| 15 | + </span> |
| 16 | + {app.newVersion && ( |
| 17 | + <> |
| 18 | + <span className="text-secondary"> → </span> |
| 19 | + <span className="font-weight-bolder text-success font-italic"> |
| 20 | + v{app.newVersion} |
| 21 | + </span>{' '} |
| 22 | + </> |
| 23 | + )} |
| 24 | + released by |
| 25 | + <span className="text-nowrap font-weight-bolder"> |
| 26 | + {' '} |
| 27 | + {app.author} |
| 28 | + </span>{' '} |
| 29 | + on |
| 30 | + <span className="text-nowrap"> {app.updated.substring(0, 10)}</span> |
| 31 | + </div> |
| 32 | + <p className="text-pretty mb-0">{app.description}</p> |
| 33 | + </div> |
| 34 | + <div className="mt-3 mt-md-0"> |
| 35 | + <ActionCellRenderer data={app} /> |
| 36 | + </div> |
| 37 | + </div> |
| 38 | + </ListGroupItem> |
| 39 | + ) |
| 40 | +} |
41 | 41 |
|
42 | | - <th className="text-center">Action</th> |
43 | | - </tr> |
44 | | - </thead> |
45 | | - <tbody> |
46 | | - {this.props.apps.map((app) => ( |
47 | | - <tr key={app.name}> |
48 | | - <td> |
49 | | - <NameCellRenderer data={app} value={app.name} /> |
50 | | - </td> |
51 | | - <td className={window.innerWidth < S_WIDTH ? 'd-none' : ''}> |
52 | | - <VersionCellRenderer data={app} /> |
53 | | - </td> |
54 | | - <td className={window.innerWidth < L_WIDTH ? 'd-none' : ''}> |
55 | | - {app.description} |
56 | | - </td> |
57 | | - <td className={window.innerWidth < XL_WIDTH ? 'd-none' : ''}> |
58 | | - {app.author} |
59 | | - </td> |
60 | | - <td className={window.innerWidth < M_WIDTH ? 'd-none' : ''}> |
61 | | - <TypeCellRenderer data={app} /> |
62 | | - </td> |
| 42 | +export default function AppList(props) { |
| 43 | + const [apps, setApps] = useState([]) |
63 | 44 |
|
64 | | - <td> |
65 | | - <ActionCellRenderer data={app} /> |
66 | | - </td> |
67 | | - </tr> |
68 | | - ))} |
69 | | - </tbody> |
70 | | - </Table> |
71 | | - ) |
| 45 | + function loadMore() { |
| 46 | + setApps(props.apps.slice(0, apps.length + 20)) |
72 | 47 | } |
73 | | -} |
74 | 48 |
|
75 | | -export default AppsList |
| 49 | + // Load initial list of apps |
| 50 | + useEffect(loadMore, [props.apps]) |
| 51 | + |
| 52 | + return ( |
| 53 | + <ListGroup> |
| 54 | + <InfiniteScroll |
| 55 | + dataLength={apps.length} |
| 56 | + next={loadMore} |
| 57 | + hasMore={apps.length != props.apps.length} |
| 58 | + > |
| 59 | + {apps.map((app) => ( |
| 60 | + <AppListItem key={app.name} {...app} /> |
| 61 | + ))} |
| 62 | + </InfiniteScroll> |
| 63 | + </ListGroup> |
| 64 | + ) |
| 65 | +} |
0 commit comments