This repository was archived by the owner on May 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathindex.tsx
More file actions
141 lines (129 loc) · 3.27 KB
/
index.tsx
File metadata and controls
141 lines (129 loc) · 3.27 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import { useEffect } from 'react';
import { shallowEqual } from 'react-redux';
import { Helmet } from 'react-helmet';
import { Input, Breadcrumb, Button } from 'antd';
import { RedoOutlined } from '@ant-design/icons';
import { useAppSelector, useAppDispatch } from '../../redux/hooks';
import { homeSlice, listRepos, perPage, sync } from '../../redux/home';
import { RequestStatus } from '../../models';
import Main from '../main';
import RepoList, { RepoListProps } from './RepoList';
import Pagination from '../../components/Pagination';
import Spin from '../../components/Spin';
const { Search } = Input;
const { actions } = homeSlice;
// Binding the state to the deployment page.
export default (): JSX.Element => {
const { loading, repos, page, syncing } = useAppSelector(
(state) => state.home,
shallowEqual
);
const dispatch = useAppDispatch();
useEffect(() => {
dispatch(listRepos());
}, [dispatch]);
const search = (q: string) => {
// TODO: Replace the state of the query into the URL query parameter.
dispatch(actions.setQ(q));
dispatch(actions.setFirstPage());
dispatch(listRepos());
};
const onClickPrev = () => {
dispatch(actions.decreasePage());
dispatch(listRepos());
};
const onClickNext = () => {
dispatch(actions.increasePage());
dispatch(listRepos());
};
const onClickSync = () => {
const f = async () => {
await dispatch(sync());
await dispatch(actions.setFirstPage());
await dispatch(listRepos());
};
f();
};
return (
<Main>
<Home
loading={loading}
syncing={syncing}
page={page}
repos={repos}
search={search}
onClickSync={onClickSync}
onClickPrev={onClickPrev}
onClickNext={onClickNext}
/>
</Main>
);
};
interface HomeProps extends RepoListProps {
loading: boolean;
syncing: RequestStatus;
page: number;
search(q: string): void;
onClickSync(): void;
onClickPrev(): void;
onClickNext(): void;
}
function Home({
loading,
page,
syncing,
repos,
search,
onClickSync,
onClickPrev,
onClickNext,
}: HomeProps): JSX.Element {
return (
<>
<Helmet>
<title>Home</title>
</Helmet>
<div>
<Breadcrumb>
<Breadcrumb.Item>
<a href="/">Repositories</a>
</Breadcrumb.Item>
</Breadcrumb>
</div>
<div style={{ textAlign: 'right' }}>
<Button
loading={syncing === RequestStatus.Pending}
icon={<RedoOutlined />}
onClick={onClickSync}
>
Sync
</Button>
</div>
<div style={{ marginTop: '20px' }}>
<Search
placeholder="Search repository ..."
onSearch={search}
size="large"
enterButton
/>
</div>
<div style={{ marginTop: '20px' }}>
{loading ? (
<div style={{ textAlign: 'center' }}>
<Spin />
</div>
) : (
<RepoList repos={repos} />
)}
</div>
<div style={{ marginTop: '20px', textAlign: 'center' }}>
<Pagination
disabledPrev={page <= 1}
disabledNext={repos.length < perPage}
onClickPrev={onClickPrev}
onClickNext={onClickNext}
/>
</div>
</>
);
}