Added whisky-business
Signed-off-by: James Ketrenos <james_eikona@ketrenos.com>
This commit is contained in:
parent
302bea1398
commit
e3c4aa287a
4
whisky-business/.expo-shared/assets.json
Normal file
4
whisky-business/.expo-shared/assets.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"12bb71342c6255bbf50437ec8f4441c083f47cdb74bd89160c15e4f43e52a1cb": true,
|
||||
"40b842e832070c58deac6aa9e08fa459302ee3f9da492c7e77d93d2fbf4a56fd": true
|
||||
}
|
13
whisky-business/.gitignore
vendored
Normal file
13
whisky-business/.gitignore
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
node_modules/
|
||||
.expo/
|
||||
npm-debug.*
|
||||
*.jks
|
||||
*.p8
|
||||
*.p12
|
||||
*.key
|
||||
*.mobileprovision
|
||||
*.orig.*
|
||||
web-build/
|
||||
|
||||
# macOS
|
||||
.DS_Store
|
169
whisky-business/App.tsx
Normal file
169
whisky-business/App.tsx
Normal file
@ -0,0 +1,169 @@
|
||||
import { StatusBar } from 'expo-status-bar';
|
||||
import React, { useState } from 'react';
|
||||
import { StyleSheet, Text, TouchableOpacity, View } from 'react-native';
|
||||
import { request, GraphQLClient, gql } from 'graphql-request';
|
||||
import moment from 'moment';
|
||||
import { buildExecutionContext } from 'graphql/execution/execute';
|
||||
|
||||
const client = new GraphQLClient("http://localhost:4000/graphql", { headers: {} });
|
||||
|
||||
const Whisky = (props : { active?: boolean, whisky: any, style: any }) => {
|
||||
const whisky = props.whisky;
|
||||
let quantity = 0,
|
||||
time = moment.unix(0);
|
||||
|
||||
const locations: any[] = [];
|
||||
|
||||
whisky.inventories.forEach((item : { location: any, quantity: number, updated: string }) => {
|
||||
quantity += item.quantity;
|
||||
const updated = moment(item.updated, 'YYYY-MM-DD');
|
||||
if (time < updated) {
|
||||
time = updated;
|
||||
}
|
||||
locations.push(
|
||||
<View key={item.location.code} style={[styles.horizontal,styles.container]}>
|
||||
<Text style={whiskyStyles.address}>{item.location.address}</Text>
|
||||
<Text style={whiskyStyles.phone}>{item.location.phone}</Text>
|
||||
<Text style={whiskyStyles.quantity}>{item.quantity}</Text>
|
||||
</View>
|
||||
)
|
||||
});
|
||||
const date = (time.unix() == 0) ? "" : time.format("YYYY-MM-DD");
|
||||
|
||||
return (
|
||||
<View style={[...props.style, whiskyStyles.container]}>
|
||||
<View style={[styles.container, styles.horizontal, {width: "100%"}]}>
|
||||
<View style={whiskyStyles.code}><Text>{whisky.code}</Text></View>
|
||||
<View style={whiskyStyles.description}><Text>{whisky.description}</Text></View>
|
||||
<View style={whiskyStyles.date}><Text>{date}</Text></View>
|
||||
<View style={whiskyStyles.quantity}><Text>{quantity}</Text></View>
|
||||
</View>
|
||||
{ props.active && <View style={styles.vertical}>
|
||||
{ locations }
|
||||
</View> }
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
const textStyle = {
|
||||
paddingTop: 5,
|
||||
paddingRight: 10,
|
||||
paddingBottom: 5,
|
||||
paddingLeft: 10
|
||||
};
|
||||
|
||||
const whiskyStyles = StyleSheet.create({
|
||||
container: {
|
||||
flex: 1,
|
||||
minHeight: 25,
|
||||
},
|
||||
code: {
|
||||
...textStyle
|
||||
},
|
||||
description: {
|
||||
flexGrow: 10,
|
||||
...textStyle
|
||||
},
|
||||
date: {
|
||||
...textStyle
|
||||
},
|
||||
address: {
|
||||
flex: 1,
|
||||
flexGrow: 1,
|
||||
...textStyle
|
||||
},
|
||||
phone: {
|
||||
...textStyle
|
||||
},
|
||||
quantity: {
|
||||
flexShrink: 10,
|
||||
minWidth: 50,
|
||||
...textStyle
|
||||
}
|
||||
});
|
||||
|
||||
export default function App() {
|
||||
const [whiskies, setWhiskies] = useState<any>(null),
|
||||
[activeWhisky, setActiveWhisky] = useState<string>("");
|
||||
|
||||
const onPress = (code : string) => {
|
||||
setActiveWhisky(code == activeWhisky ? "" : code);
|
||||
};
|
||||
|
||||
const items = whiskies ? whiskies
|
||||
.filter((item : any) => item.size == 750 && item.inventories.length)
|
||||
.map((whisky : any) => {
|
||||
const active = whisky.code == activeWhisky;
|
||||
return (
|
||||
<TouchableOpacity key={whisky.code} onPress={() => onPress(whisky.code)}>
|
||||
<Whisky
|
||||
active={active}
|
||||
style={[styles.container, styles.whisky]}
|
||||
whisky={whisky}/>
|
||||
</TouchableOpacity>
|
||||
);
|
||||
}) : [];
|
||||
|
||||
let query = gql` {
|
||||
Whiskies {
|
||||
code
|
||||
description
|
||||
price
|
||||
size
|
||||
lastSeen
|
||||
inventories {
|
||||
location {
|
||||
code
|
||||
address
|
||||
city
|
||||
phone
|
||||
longitude
|
||||
latitude
|
||||
}
|
||||
quantity
|
||||
updated
|
||||
}
|
||||
}
|
||||
}`;
|
||||
|
||||
client.request(query)
|
||||
.then(data => {
|
||||
setWhiskies(data.Whiskies);
|
||||
})
|
||||
.catch (error => {
|
||||
console.error(error);
|
||||
});
|
||||
|
||||
return (
|
||||
<View style={[styles.container]}>
|
||||
{ items }
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: {
|
||||
flex: 1,
|
||||
backgroundColor: '#fff',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
},
|
||||
horizontal: {
|
||||
flex: 1,
|
||||
display: "flex",
|
||||
flexGrow: 1,
|
||||
flexDirection: "row",
|
||||
},
|
||||
vertical: {
|
||||
flex: 1,
|
||||
display: "flex",
|
||||
flexGrow: 1,
|
||||
flexDirection: "column",
|
||||
},
|
||||
whisky: {
|
||||
width: 500,
|
||||
borderWidth: 1,
|
||||
borderColor: "black",
|
||||
margin: 2
|
||||
}
|
||||
});
|
32
whisky-business/app.json
Normal file
32
whisky-business/app.json
Normal file
@ -0,0 +1,32 @@
|
||||
{
|
||||
"expo": {
|
||||
"name": "whisky-business",
|
||||
"slug": "whisky-business",
|
||||
"version": "1.0.0",
|
||||
"orientation": "portrait",
|
||||
"icon": "./assets/icon.png",
|
||||
"splash": {
|
||||
"image": "./assets/splash.png",
|
||||
"resizeMode": "contain",
|
||||
"backgroundColor": "#ffffff"
|
||||
},
|
||||
"updates": {
|
||||
"fallbackToCacheTimeout": 0
|
||||
},
|
||||
"assetBundlePatterns": [
|
||||
"**/*"
|
||||
],
|
||||
"ios": {
|
||||
"supportsTablet": true
|
||||
},
|
||||
"android": {
|
||||
"adaptiveIcon": {
|
||||
"foregroundImage": "./assets/adaptive-icon.png",
|
||||
"backgroundColor": "#FFFFFF"
|
||||
}
|
||||
},
|
||||
"web": {
|
||||
"favicon": "./assets/favicon.png"
|
||||
}
|
||||
}
|
||||
}
|
BIN
whisky-business/assets/adaptive-icon.png
Normal file
BIN
whisky-business/assets/adaptive-icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
BIN
whisky-business/assets/favicon.png
Normal file
BIN
whisky-business/assets/favicon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
BIN
whisky-business/assets/icon.png
Normal file
BIN
whisky-business/assets/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 22 KiB |
BIN
whisky-business/assets/splash.png
Normal file
BIN
whisky-business/assets/splash.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 47 KiB |
6
whisky-business/babel.config.js
Normal file
6
whisky-business/babel.config.js
Normal file
@ -0,0 +1,6 @@
|
||||
module.exports = function(api) {
|
||||
api.cache(true);
|
||||
return {
|
||||
presets: ['babel-preset-expo'],
|
||||
};
|
||||
};
|
8419
whisky-business/package-lock.json
generated
Normal file
8419
whisky-business/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
27
whisky-business/package.json
Normal file
27
whisky-business/package.json
Normal file
@ -0,0 +1,27 @@
|
||||
{
|
||||
"main": "node_modules/expo/AppEntry.js",
|
||||
"scripts": {
|
||||
"start": "expo start",
|
||||
"android": "expo start --android",
|
||||
"ios": "expo start --ios",
|
||||
"web": "expo start --web",
|
||||
"eject": "expo eject"
|
||||
},
|
||||
"dependencies": {
|
||||
"expo": "~41.0.1",
|
||||
"expo-status-bar": "~1.0.4",
|
||||
"graphql-request": "^3.4.0",
|
||||
"moment": "^2.29.1",
|
||||
"react": "16.13.1",
|
||||
"react-dom": "16.13.1",
|
||||
"react-native": "https://github.com/expo/react-native/archive/sdk-41.0.0.tar.gz",
|
||||
"react-native-web": "~0.13.12"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.9.0",
|
||||
"@types/react": "~16.9.35",
|
||||
"@types/react-native": "~0.63.2",
|
||||
"typescript": "~4.0.0"
|
||||
},
|
||||
"private": true
|
||||
}
|
6
whisky-business/tsconfig.json
Normal file
6
whisky-business/tsconfig.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"extends": "expo/tsconfig.base",
|
||||
"compilerOptions": {
|
||||
"strict": true
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user