|
| 1 | +import { Loading } from 'idea-react'; |
| 2 | +import { GitRepository, RepositoryModel } from 'mobx-github'; |
| 3 | +import { observer } from 'mobx-react'; |
| 4 | +import { ScrollList } from 'mobx-restful-table'; |
| 5 | +import { cache, compose, errorLogger } from 'next-ssr-middleware'; |
| 6 | +import { FC, useContext } from 'react'; |
| 7 | +import { Col, Container, Row } from 'react-bootstrap'; |
| 8 | + |
| 9 | +import { GitCard } from '../components/Git/Card'; |
| 10 | +import { PageHead } from '../components/Layout/PageHead'; |
| 11 | +import { repositoryStore } from '../models/Repository'; |
| 12 | +import { I18nContext } from '../models/Translation'; |
| 13 | + |
| 14 | +export const getServerSideProps = compose(cache(), errorLogger, async () => { |
| 15 | + const list = await new RepositoryModel('Open-Source-Bazaar').getList({ |
| 16 | + relation: ['languages'], |
| 17 | + }); |
| 18 | + |
| 19 | + return { props: JSON.parse(JSON.stringify({ list })) }; |
| 20 | +}); |
| 21 | + |
| 22 | +const ProjectListPage: FC<{ list: GitRepository[] }> = observer(({ list }) => { |
| 23 | + const i18n = useContext(I18nContext); |
| 24 | + const { t } = i18n; |
| 25 | + |
| 26 | + return ( |
| 27 | + <Container> |
| 28 | + <PageHead title={t('open_source_projects')} /> |
| 29 | + <h1 className="my-4">{t('open_source_projects')}</h1> |
| 30 | + |
| 31 | + {repositoryStore.downloading > 0 && <Loading />} |
| 32 | + |
| 33 | + <ScrollList |
| 34 | + translator={i18n} |
| 35 | + store={repositoryStore} |
| 36 | + filter={{ relation: ['languages'] }} |
| 37 | + renderList={allItems => ( |
| 38 | + <Row as="ul" className="list-unstyled g-4" xs={1} sm={2}> |
| 39 | + {allItems.map( |
| 40 | + item => |
| 41 | + item.homepage && ( |
| 42 | + <Col key={item.id} as="li"> |
| 43 | + <GitCard className="h-100 shadow-sm" {...item} /> |
| 44 | + </Col> |
| 45 | + ), |
| 46 | + )} |
| 47 | + </Row> |
| 48 | + )} |
| 49 | + defaultData={list} |
| 50 | + /> |
| 51 | + </Container> |
| 52 | + ); |
| 53 | +}); |
| 54 | + |
| 55 | +export default ProjectListPage; |
0 commit comments