Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Commit

Permalink
Merge local with github
Browse files Browse the repository at this point in the history
  • Loading branch information
cederstrom committed Jul 5, 2018
1 parent 6abb5ca commit d57eacc
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 13 deletions.
73 changes: 63 additions & 10 deletions App.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@ import {
ActivityIndicator,
StyleSheet,
Text,
View
View,
ScrollView,
RefreshControl,
Linking
} from "react-native";
import { Card, Header } from "react-native-elements";
import moment from "moment/min/moment-with-locales";

export default class FetchExample extends React.Component {
constructor(props) {
super(props);
this.state = { isLoading: true };
moment.locale("sv-SE");
}

componentDidMount() {
Expand All @@ -20,7 +26,7 @@ export default class FetchExample extends React.Component {
this.setState(
{
isLoading: false,
dataSource: responseJson
dataSource: responseJson.sort(this.bouySort)
},
function() {}
);
Expand All @@ -30,6 +36,16 @@ export default class FetchExample extends React.Component {
});
}

bouySort(a, b) {
if (a.name < b.name) return -1;
if (a.name > b.name) return 1;
return 0;
}

onRefresh = () => {
this.componentDidMount();
};

render() {
if (this.state.isLoading) {
return (
Expand All @@ -41,15 +57,52 @@ export default class FetchExample extends React.Component {

return (
<View style={{ flex: 1, paddingTop: 20 }}>
<FlatList
data={this.state.dataSource}
renderItem={({ item }) => (
<Text>
{item.name}: {Math.round(item.temperature)}°C
</Text>
)}
keyExtractor={(item, index) => index}
<Header
centerComponent={{
text: "Badtemperaturer i Karlskrona kommun",
style: { color: "#fff" }
}}
/>
<ScrollView
contentContainerStyle={{ paddingBottom: 20 }}
refreshControl={
<RefreshControl
refreshing={this.state.isLoading}
onRefresh={this.onRefresh}
/>
}
>
{this.state.dataSource.map((item, i) => (
<Card key={i}>
<Text h1 style={{ fontWeight: "bold", fontSize: 20 }}>
{item.name}
</Text>
<Text style={{ fontWeight: "bold", fontSize: 40 }}>
{Math.round(item.temperature)}°C
</Text>
<Text style={{ color: "gray", fontSize: 10 }}>
Uppdaterad {moment(new Date(item.time)).fromNow()}
</Text>
</Card>
))}
<Text
style={{
textAlign: "center",
color: "gray",
paddingTop: 20,
padding: 15
}}
>
Byggd av Andreas Cederström med data från Karlskrona kommun och All
Binary. Mer info på{" "}
<Text
style={{ color: "blue" }}
onPress={() => Linking.openURL("https://buoy.ioe.allbin.se")}
>
https://buoy.ioe.allbin.se
</Text>
</Text>
</ScrollView>
</View>
);
}
Expand Down
12 changes: 11 additions & 1 deletion app.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"expo": {
"sdkVersion": "27.0.0"
"name": "Badtemperatur i Karlskrona",
"icon": "./icon.png",
"description":
"Visa aktuella badtemperaturer vid stränderna i Karlskrona kommun.",
"version": "1.0.0",
"slug": "badtemperatur-i-karlskrona",
"privacy": "public",
"sdkVersion": "27.0.0",
"android": {
"package": "com.cederstrom.badtemp"
}
}
}
27 changes: 25 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
},
"dependencies": {
"expo": "^27.0.1",
"moment": "^2.22.2",
"react": "16.3.1",
"react-native": "~0.55.2",
"react-native-elements": "^0.19.1"
Expand Down

0 comments on commit d57eacc

Please sign in to comment.