-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Gateway] add flatlist screen (#119)
* [Gateway] add flatlist screen * add upColor/downColor to StatusDot * add gateway connected status * prepend ttn to gateway * add catch to gateway actions * define alive gateway as seen in last minute * [eslint] remove import plugin * fix prop type * lint
- Loading branch information
1 parent
1422e87
commit f05a08b
Showing
12 changed files
with
400 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// @flow | ||
|
||
import React, { Component } from 'react' | ||
import { StyleSheet, Text, TouchableOpacity, View } from 'react-native' | ||
|
||
import StatusDot from '../components/StatusDot' | ||
import TagLabel from '../components/TagLabel' | ||
|
||
import { GATEWAY_DETAIL } from '../scopes/navigation/constants' | ||
import { BLUE, MID_GREY, WHITE } from '../constants/colors' | ||
import { LATO_REGULAR } from '../constants/fonts' | ||
|
||
const LAST_SEEN_LIMIT_MSECS = 1000 * 60 // 1 minute | ||
|
||
import type { TTNGateway } from '../scopes/content/gateways/types' | ||
|
||
type Props = { | ||
gateway: TTNGateway, | ||
navigation: Object, | ||
} | ||
|
||
export default class GatewayListItem extends Component { | ||
props: Props | ||
_navigateToSingleGateway = gateway => { | ||
this.props.navigation.navigate(GATEWAY_DETAIL, { | ||
gateway: gateway, | ||
gatwayName: gateway.attributes.description, | ||
gatwayId: gateway.id, | ||
}) | ||
} | ||
render() { | ||
const { gateway } = this.props | ||
const isAlive = | ||
Date.now() - gateway.status.time / (1000 * 1000) < LAST_SEEN_LIMIT_MSECS | ||
|
||
return ( | ||
<TouchableOpacity | ||
onPress={() => this._navigateToSingleGateway(gateway)} | ||
style={styles.gatewayItem} | ||
> | ||
<View style={styles.idHandlerRow}> | ||
<TagLabel center orange style={{ width: '50%' }}> | ||
{gateway.id} | ||
</TagLabel> | ||
<StatusDot downColor={MID_GREY} up={isAlive} upColor={BLUE} /> | ||
</View> | ||
<View style={styles.descriptionRow}> | ||
<Text | ||
ellipsizeMode="tail" | ||
numberOfLines={1} | ||
style={styles.descriptionText} | ||
> | ||
{gateway.attributes.description} | ||
</Text> | ||
<Text style={styles.frequencyText}> | ||
{gateway.frequency_plan} | ||
</Text> | ||
</View> | ||
</TouchableOpacity> | ||
) | ||
} | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
gatewayItem: { | ||
backgroundColor: WHITE, | ||
borderRadius: 3, | ||
padding: 10, | ||
minHeight: 100, | ||
justifyContent: 'center', | ||
}, | ||
idHandlerRow: { | ||
alignItems: 'center', | ||
justifyContent: 'space-between', | ||
paddingHorizontal: 5, | ||
flexDirection: 'row', | ||
}, | ||
descriptionRow: { | ||
alignItems: 'center', | ||
flexDirection: 'row', | ||
justifyContent: 'space-between', | ||
paddingHorizontal: 5, | ||
marginTop: 10, | ||
marginLeft: 5, | ||
}, | ||
descriptionText: { | ||
color: MID_GREY, | ||
fontFamily: LATO_REGULAR, | ||
}, | ||
nameContainer: { | ||
flex: 1, | ||
alignItems: 'flex-start', | ||
}, | ||
handlerContainer: { | ||
width: 70, | ||
}, | ||
frequencyText: { | ||
fontStyle: 'italic', | ||
fontSize: 10, | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// @flow | ||
|
||
import apiClient from '../../../utils/apiClient' | ||
|
||
import { GATEWAYS } from '../../../constants/apiEndpoints' | ||
import type { TTNGateway } from './types' | ||
import type { Dispatch, GetState } from '../../../types/redux' | ||
|
||
/** | ||
* Fetch ALL Gateways | ||
*/ | ||
|
||
export function getGatewaysAsync() { | ||
return async (dispatch: Dispatch, getState: GetState) => { | ||
try { | ||
const payload: Array<TTNGateway> = await apiClient.get(GATEWAYS) | ||
return dispatch({ type: 'content/RECEIVE_TTN_GATEWAYS', payload }) | ||
} catch (err) { | ||
console.log('## getGatewaysAsync error', err) | ||
throw err | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Fetch Gateway by ID | ||
*/ | ||
|
||
export function getGatewayAsync(gateway: TTNGateway) { | ||
const { id } = gateway | ||
return async (dispatch: Dispatch, getState: GetState) => { | ||
try { | ||
const payload: TTNGateway = await apiClient.get(GATEWAYS + id) | ||
return dispatch({ type: 'content/RECEIVE_TTN_GATEWAY', payload }) | ||
} catch (err) { | ||
console.log('## getGatewaysAsync error', err) | ||
throw err | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// @flow | ||
|
||
type Collaborator = { | ||
username: string, | ||
rights: Array<string>, | ||
} | ||
|
||
export type TTNGateway = { | ||
id: string, | ||
activated: boolean, | ||
frequency_plan: string, | ||
frequency_plan_url: string, | ||
auto_update: boolean, | ||
location_public: boolean, | ||
status_public: boolean, | ||
owner_public: boolean, | ||
antenna_location: { | ||
longitude: number, | ||
latitude: number, | ||
altitude: number, | ||
}, | ||
collaborators: ?Array<Collaborator>, | ||
key: string, | ||
token: { | ||
access_token: string, | ||
expiry: string, | ||
}, | ||
attributes: { | ||
brand: string, | ||
model: string, | ||
placement: string, | ||
antenna_model: string, | ||
description: string, | ||
}, | ||
router: Router, | ||
fallback_routers: Array<Router>, | ||
owner: { id: string, username: string }, | ||
rights: ?Array<string>, | ||
status: { | ||
time: number, | ||
gps: { altitude: number }, | ||
rx_ok: number, | ||
tx_in: number, | ||
}, | ||
} | ||
|
||
type Router = { | ||
id: string, | ||
address: string, | ||
mqtt_address: string, | ||
} | ||
|
||
export const RECEIVE_TTN_GATEWAY = 'content/RECEIVE_TTN_GATEWAY' | ||
export const RECEIVE_TTN_GATEWAYS = 'content/RECEIVE_TTN_GATEWAYS' | ||
|
||
export type ReceiveTTNGatewayAction = { | ||
type: 'content/RECEIVE_TTN_GATEWAY', | ||
payload: TTNGateway, | ||
} | ||
|
||
export type ReceiveTTNGatewaysAction = { | ||
type: 'content/RECEIVE_TTN_GATEWAYS', | ||
payload: Array<TTNGateway>, | ||
} | ||
|
||
export type TTNGatewayAction = | ||
| ReceiveTTNGatewayAction | ||
| ReceiveTTNGatewaysAction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.