Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules/
db/
3 changes: 3 additions & 0 deletions AnarchitectsApp/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["module:metro-react-native-babel-preset"]
}
6 changes: 6 additions & 0 deletions AnarchitectsApp/.buckconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

[android]
target = Google Inc.:Google APIs:23

[maven_repositories]
central = https://repo1.maven.org/maven2
1 change: 1 addition & 0 deletions AnarchitectsApp/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pbxproj -text
61 changes: 61 additions & 0 deletions AnarchitectsApp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# OSX
#
.DS_Store

# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate
project.xcworkspace

# Android/IntelliJ
#
build/
.idea
.gradle
local.properties
*.iml

# node.js
#
node_modules/
npm-debug.log
yarn-error.log

# BUCK
buck-out/
\.buckd/
*.keystore

# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/

*/fastlane/report.xml
*/fastlane/Preview.html
*/fastlane/screenshots

# Bundle artifact
*.jsbundle

android/
ios/
web-build/
.expo/
156 changes: 156 additions & 0 deletions AnarchitectsApp/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
import React, { useState, useEffect } from 'react';
import { StyleSheet, Text, View, SafeAreaView, SectionList, Button, TextInput } from 'react-native';

type Building = { id: string, name: string, value: number }

export default function App() {

const [buildings, setBuildings] = useState([])
const [buildingName, setBuildingName] = useState("")

useEffect(() => {
getBuildings()
setBuildings(mockBuildings)
}, [])

function handleBuildingNameInput(name: string) {
setBuildingName(name)
}

const mockBuildings = [
{
title: "Feracious Fields",
data: [{
id: 22,
name: "Feracious Fields",
value: 10244.19
}]
},
{
title: "Greene Meadows",
data: [{
id: 14,
name: "Greene Meadows",
value: 1989.11
}]
},
{
title: "Woodlawn Terrace",
data: [{
id: 14,
name: "Woodlawn Terrace",
value: 23232.10
}]
},
{
title: "Mohawk Estates",
data: [{
id: 16,
name: "Mohawk Estates",
value: 23232.10
}]
},
]

function getBuildings() {
return fetch('http://192.168.178.33:5000/buildings', {
mode: 'cors',
headers: {
"Content-Type": "application/json",
Accept: "application/json"
}
})
.then((response) => {
return response.json()
})
.then(responseJson => {
const buildingsData = responseJson && responseJson.buildings.map((item) => {
return { title: item.name, value: item.value, data: [item] }
});
setBuildings(buildingsData)
})
.catch((error) => {
console.error(error);
});
}

function createNewBuilding() {
return {
name: buildingName, value: 0
}
}

function triggerAddBuilding() {
const data = createNewBuilding()
return fetch('http://192.168.178.33:5000/buildings', {
method: 'POST',
mode: 'cors',
headers: {
"Content-Type": "application/json",
Accept: "application/json"
},
body: JSON.stringify(data)
})
.then((response) => {
return response.json()
})
.then(responseJson => {
console.log(responseJson)
})
.catch((error) => {
console.error(error);
});
}

function Item({ title, value }) {
return (
<View style={styles.item}>
<Text>{title}</Text>
<Text>{value}</Text>
</View>
);
}

return (
<SafeAreaView style={styles.container}>
<View>
<SectionList
sections={buildings}
keyExtractor={(item: { title: string, value: number }, index: number) => item.title + index}
renderItem={({ item }) => <Item title={item.title} value={item.value} />}
renderSectionHeader={({ section: { title } }) => <Text style={styles.header}>{title}</Text>}
/>
</View>
<View>
<Text>{buildingName}</Text>
<TextInput
style={{ height: 40, borderColor: 'gray', borderWidth: 1 }}
onChangeText={text => handleBuildingNameInput(text)}
value={buildingName}
/>
<Button
title="Add Building"
onPress={triggerAddBuilding}
/>
</View>
</SafeAreaView>
);
}

const styles = StyleSheet.create({
container: {
flex: 1,
//marginHorizontal: 16,
},
item: {
backgroundColor: '#f9c2ff',
padding: 20,
marginVertical: 8,
},
header: {
fontSize: 32,
},
title: {
fontSize: 24,
},
});
10 changes: 10 additions & 0 deletions AnarchitectsApp/__tests__/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import 'react-native';
import React from 'react';
import App from '../App.tsx';

// Note: test renderer must be required after react-native.
import renderer from 'react-test-renderer';

it('renders correctly', () => {
renderer.create(<App />);
});
17 changes: 17 additions & 0 deletions AnarchitectsApp/app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "AnarchitectsApp",
"displayName": "AnarchitectsApp",
"expo": {
"name": "AnarchitectsApp",
"slug": "AnarchitectsApp",
"privacy": "unlisted",
"sdkVersion": "36.0.0",
"version": "1.0.0",
"entryPoint": "node_modules/expo/AppEntry.js",
"platforms": [
"ios",
"android",
"web"
]
}
}
6 changes: 6 additions & 0 deletions AnarchitectsApp/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = function(api) {
api.cache(true);
return {
presets: ['babel-preset-expo'],
};
};
5 changes: 5 additions & 0 deletions AnarchitectsApp/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {AppRegistry} from 'react-native'
import App from './App'
import {name as appName} from './app.json'

AppRegistry.registerComponent(appName, () => App)
Loading