|
1 | 1 | import { component, mixin, createCell, Fragment } from 'web-cell'; |
| 2 | +import { observer } from 'mobx-web-cell'; |
2 | 3 | import classNames from 'classnames'; |
3 | 4 |
|
4 | 5 | import { NavBar } from 'boot-cell/source/Navigator/NavBar'; |
5 | 6 | import { Form } from 'boot-cell/source/Form/Form'; |
6 | 7 | import { Field } from 'boot-cell/source/Form/Field'; |
7 | 8 | import { Button } from 'boot-cell/source/Form/Button'; |
8 | 9 | import { CarouselView, CarouselItem } from 'boot-cell/source/Media/Carousel'; |
| 10 | +import { SpinnerBox } from 'boot-cell/source/Prompt/Spinner'; |
9 | 11 |
|
10 | 12 | import { Feature } from './Feature'; |
11 | 13 | import style from './index.less'; |
12 | 14 |
|
13 | | -import { Repository, github } from '../../../model'; |
14 | 15 | import { headers, banners, features } from './data'; |
| 16 | +import repository, { Repository } from '../../../model/Repository'; |
15 | 17 |
|
16 | | -interface CarouselPageState { |
17 | | - projects: Repository[]; |
18 | | -} |
19 | | - |
| 18 | +@observer |
20 | 19 | @component({ |
21 | 20 | tagName: 'carousel-page', |
22 | 21 | renderTarget: 'children' |
23 | 22 | }) |
24 | | -export class CarouselPage extends mixin<{}, CarouselPageState>() { |
25 | | - state = { |
26 | | - projects: [] as Repository[] |
27 | | - }; |
| 23 | +export class CarouselPage extends mixin() { |
| 24 | + connectedCallback() { |
| 25 | + repository.getList(); |
28 | 26 |
|
29 | | - async connectedCallback() { |
30 | 27 | super.connectedCallback(); |
| 28 | + } |
31 | 29 |
|
32 | | - const { body } = await github.get<Repository[]>( |
33 | | - 'orgs/EasyWebApp/repos' |
34 | | - ); |
| 30 | + renderItem = ({ name, description, html_url }: Repository) => ( |
| 31 | + <div className="col-lg-4 mb-4"> |
| 32 | + <img |
| 33 | + className="rounded-circle" |
| 34 | + style={{ width: '8.75rem' }} |
| 35 | + src="https://web-cell.dev/WebCell-0.f1ffd28b.png" |
| 36 | + /> |
| 37 | + <h2 style={{ fontWeight: '400' }}>{name}</h2> |
| 38 | + <p>{description}</p> |
| 39 | + <p> |
| 40 | + <Button color="secondary" href={html_url}> |
| 41 | + View details » |
| 42 | + </Button> |
| 43 | + </p> |
| 44 | + </div> |
| 45 | + ); |
35 | 46 |
|
36 | | - await this.setState({ |
37 | | - projects: body |
38 | | - .sort(({ updated_at: A }, { updated_at: B }) => |
39 | | - B.localeCompare(A) |
40 | | - ) |
41 | | - .slice(0, 3) |
42 | | - }); |
43 | | - } |
| 47 | + render() { |
| 48 | + const { loading, list } = repository; |
44 | 49 |
|
45 | | - render(_, { projects }: CarouselPageState) { |
46 | 50 | return ( |
47 | 51 | <> |
48 | 52 | <NavBar brand="Carousel" menu={headers}> |
@@ -71,24 +75,9 @@ export class CarouselPage extends mixin<{}, CarouselPageState>() { |
71 | 75 | </CarouselView> |
72 | 76 |
|
73 | 77 | <div className={classNames('container', style.marketing)}> |
74 | | - <div className="row text-center"> |
75 | | - {projects.map(({ name, description, html_url }) => ( |
76 | | - <div className="col-lg-4 mb-4"> |
77 | | - <img |
78 | | - className="rounded-circle" |
79 | | - style={{ width: '8.75rem' }} |
80 | | - src="https://web-cell.dev/WebCell-0.f1ffd28b.png" |
81 | | - /> |
82 | | - <h2 style={{ fontWeight: '400' }}>{name}</h2> |
83 | | - <p>{description}</p> |
84 | | - <p> |
85 | | - <Button color="secondary" href={html_url}> |
86 | | - View details » |
87 | | - </Button> |
88 | | - </p> |
89 | | - </div> |
90 | | - ))} |
91 | | - </div> |
| 78 | + <SpinnerBox className="row text-center" cover={loading}> |
| 79 | + {list.slice(0, 3).map(this.renderItem)} |
| 80 | + </SpinnerBox> |
92 | 81 | <hr className={style['featurette-divider']} /> |
93 | 82 |
|
94 | 83 | {features.map((item, index) => ( |
|
0 commit comments