Skip to content
This repository was archived by the owner on May 6, 2019. It is now read-only.

Commit 7e11a40

Browse files
committed
✨ Checkpoint
1 parent 4c34465 commit 7e11a40

File tree

5 files changed

+96
-39
lines changed

5 files changed

+96
-39
lines changed

src/components/eventcard.jsx

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import React from 'react'
2+
import PropTypes from 'prop-types'
3+
4+
import {Card, Divider, Button, Typography} from 'antd'
5+
6+
const {Text} = Typography
7+
8+
const EventCard = props => {
9+
const {event} = props
10+
11+
return (
12+
<Card cover={<img alt={event.name} src={event.cover} />}>
13+
<p style={{marginBottom: '8px', color: 'rgba(0,0,0,0.85)', fontSize: '16px', fontWeight: 500}}>{event.name}</p>
14+
<Text type="secondary">{event.desc}</Text>
15+
{event.breifing.pilot === null && event.breifing.atc === null ? null : (
16+
<>
17+
<Divider orientation="left">
18+
<Text style={{fontSize: '14px'}} strong>
19+
Breifing
20+
</Text>
21+
</Divider>
22+
{event.breifing.pilot === null ? null : (
23+
<a href={event.breifing.pilot} target="_blank" rel="noopener noreferrer">
24+
<Button type="dashed">Pilot</Button>
25+
</a>
26+
)}
27+
{event.breifing.atc === null ? null : (
28+
<a href={event.breifing.atc} target="_blank" rel="noopener noreferrer">
29+
<Button type="dashed">ATC</Button>
30+
</a>
31+
)}
32+
</>
33+
)}
34+
</Card>
35+
)
36+
}
37+
38+
export default EventCard
39+
40+
EventCard.propTypes = {
41+
event: PropTypes.object,
42+
}

src/pages/event.jsx

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const Event = props => {
1818

1919
const [flights, setFlights] = useState([])
2020
const [more, setMore] = useState(true)
21+
const [error, setError] = useState(false)
22+
const [errorRaw, setErrorRaw] = useState(null)
2123
const [tabs] = useState([
2224
{
2325
name: 'Departure',
@@ -32,14 +34,20 @@ const Event = props => {
3234
const dispatch = useContext(appContext)
3335

3436
const loadMoreFlights = async page => {
35-
const out = await Axios.get(`${store.apiEndpoint}/api/v1/flight/list/${eventID}/${page}`)
37+
try {
38+
const out = await Axios.get(`${store.apiEndpoint}/api/v1/flight/list/${eventID}/${page}`)
3639

37-
if (out.data.response.data.flights.length === 0) {
40+
if (out.data.response.data.flights.length === 0) {
41+
setMore(false)
42+
return
43+
}
44+
45+
setFlights(prev => [...prev, ...out.data.response.data.flights])
46+
} catch (err) {
3847
setMore(false)
39-
return
48+
setErrorRaw(err.response.data)
49+
setError(true)
4050
}
41-
42-
setFlights(prev => [...prev, ...out.data.response.data.flights])
4351
}
4452

4553
useEffect(() => {
@@ -53,20 +61,28 @@ const Event = props => {
5361
loadMore={loadMoreFlights}
5462
hasMore={more}
5563
loader={<Loading key={`${eventID}-list-loader`} />}>
56-
<appContext.Provider value={dispatch} key={`${eventID}-list-context`}>
57-
<Tabs defaultActiveKey="0">
58-
{tabs.map((tab, i) => (
59-
<TabPane tab={tab.name} key={i}>
60-
<Row gutter={16} type="flex" justify="space-around" align="middle" key="grid-row">
61-
{_.filter(flights, o => o.type === tab.key).map(flight => (
62-
<Strip key={`${eventID}-strip-${flight.id}`} eventID={eventID} flightID={flight.id} store={store} />
63-
))}
64-
</Row>
65-
</TabPane>
66-
))}
67-
</Tabs>
68-
{!more ? <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description={`Reached the end`} /> : null}
69-
</appContext.Provider>
64+
{error === true ? (
65+
errorRaw.code === 706 ? (
66+
<Empty description={`This event is closed for reservation`} />
67+
) : (
68+
<>Could not fetch flights</>
69+
)
70+
) : (
71+
<appContext.Provider value={dispatch} key={`${eventID}-list-context`}>
72+
<Tabs defaultActiveKey="0">
73+
{tabs.map((tab, i) => (
74+
<TabPane tab={tab.name} key={i}>
75+
<Row gutter={16} type="flex" justify="space-around" align="middle" key="grid-row">
76+
{_.filter(flights, o => o.type === tab.key).map(flight => (
77+
<Strip key={`${eventID}-strip-${flight.id}`} eventID={eventID} flightID={flight.id} store={store} />
78+
))}
79+
</Row>
80+
</TabPane>
81+
))}
82+
</Tabs>
83+
{!more ? <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description={`Reached the end`} /> : null}
84+
</appContext.Provider>
85+
)}
7086
</InfiniteScroll>
7187
)
7288
}

src/pages/home.jsx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import PropTypes from 'prop-types'
33

44
import {Axios, Loading, Link, appContext} from '../bridge'
55

6-
import {Row, Col, Card, Typography, Empty} from 'antd'
6+
import EventCard from '../components/eventcard'
7+
8+
import {Row, Col, Typography, Empty} from 'antd'
79

810
const {Title, Text} = Typography
9-
const {Meta} = Card
1011

1112
const Home = props => {
1213
const [raw, setRaw] = useState([])
@@ -21,16 +22,18 @@ const Home = props => {
2122
;(async () => {
2223
dispatch({type: 'setSubMenu', subMenu: 'events'})
2324

24-
try {
25-
const out = await Axios.get(`${store.apiEndpoint}/api/v1/event/list`)
26-
setRaw(out.data.response.data.events)
27-
setIsLoading(false)
28-
} catch {
29-
setError(true)
30-
setIsLoading(false)
25+
if (isLoading === true && error === false) {
26+
try {
27+
const out = await Axios.get(`${store.apiEndpoint}/api/v1/event/list`)
28+
setRaw(out.data.response.data.events)
29+
setIsLoading(false)
30+
} catch {
31+
setError(true)
32+
setIsLoading(false)
33+
}
3134
}
3235
})()
33-
}, [dispatch, store.apiEndpoint])
36+
}, [dispatch, error, isLoading, store])
3437

3538
return (
3639
<>
@@ -50,9 +53,7 @@ const Home = props => {
5053
{raw.map(event => (
5154
<Col xs={{span: 24}} sm={{span: 12}} md={{span: 8}} lg={{span: 6}} key={`card-event-${event.id}`}>
5255
<Link to={`/event/${event.id}`}>
53-
<Card cover={<img alt={event.name} src={event.cover} />}>
54-
<Meta title={event.name} description={event.desc} />
55-
</Card>
56+
<EventCard event={event} />
5657
</Link>
5758
</Col>
5859
))}

src/pages/wallet.jsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import PropTypes from 'prop-types'
33

44
import {Axios, appContext, Loading} from '../bridge'
55

6+
import EventCard from '../components/eventcard'
67
import FlightCard from '../components/flightcard'
78

8-
import {Row, Col, Typography, List, Modal, message, Card} from 'antd'
9+
import {Row, Col, Typography, List, Modal, message} from 'antd'
910

1011
const {Title, Text} = Typography
11-
const {Meta} = Card
1212

1313
const Wallet = props => {
1414
const [raw, setRaw] = useState(null)
@@ -111,7 +111,7 @@ const Wallet = props => {
111111
renderItem={item => (
112112
<List.Item
113113
actions={
114-
item.event.isOpen
114+
item.event.isOpen === true
115115
? [
116116
<Text
117117
key={`${item.event.id}-${item.flight.id}-button-cancel`}
@@ -156,9 +156,7 @@ const Wallet = props => {
156156
<Title level={3}>Event</Title>
157157
</Row>
158158
<Row style={{margin: '10px 0'}}>
159-
<Card cover={<img alt={modalRaw.event.name} src={modalRaw.event.cover} />}>
160-
<Meta title={modalRaw.event.name} description={modalRaw.event.desc} />
161-
</Card>
159+
<EventCard event={modalRaw.event} />
162160
</Row>
163161
</Col>
164162
<Col xs={{span: 24}} md={{span: 14}}>

src/store/hooks-reducers.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import ls from 'local-storage'
33
export const initState = {
44
toggleMenu: false,
55
subMenu: 'initializing',
6-
apiEndpoint: 'https://rfe-api.th.ivao.aero',
6+
apiEndpoint: 'http://localhost:3001',
77
identity: null,
88
token: ls('token'),
99
tokenTime: ls('tokenTime'),

0 commit comments

Comments
 (0)