Skip to content

Commit

Permalink
Merge pull request #46 from BesLogic/pop-up-box-info
Browse files Browse the repository at this point in the history
pop-up-box-info
  • Loading branch information
andy2great authored Aug 8, 2024
2 parents 993689c + 7eed407 commit 2c09a66
Show file tree
Hide file tree
Showing 6 changed files with 186 additions and 81 deletions.
2 changes: 2 additions & 0 deletions apps/releaf/mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
"@react-navigation/bottom-tabs": "^6.5.20",
"@react-navigation/native": "^6.1.17",
"@react-navigation/native-stack": "^6.9.26",
"date-fns": "^3.6.0",
"metro-config": "^0.80.3",
"nativewind": "^2.0.11",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-native": "^0.73.2",
"react-native-date-picker": "^5.0.2",
"react-native-gesture-handler": "^2.16.1",
"react-native-heroicons": "^4.0.0",
"react-native-safe-area-context": "^4.10.1",
"react-native-screens": "^3.31.1",
"react-native-svg": "^14.1.0",
Expand Down
91 changes: 12 additions & 79 deletions apps/releaf/mobile/src/app/box/Box.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { View, Text, ScrollView, StyleSheet, FlatList } from 'react-native';
import { View, Text, ScrollView, StyleSheet } from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { TreeStateCard } from './components/TreeStateCard';
import { useCallback, useEffect, useState } from 'react';
import { Loading } from '../shared/Loading';
import { BoxDetailsScreen } from './screens/BoxDetails';
import { BoxService } from '../infrastructure/services/box.service';
import { BoxDetails } from '../infrastructure/entities/boxDetails';

const styles = StyleSheet.create({
title: {
Expand All @@ -31,7 +31,16 @@ export const Box = () => {
component={BoxScreen}
options={{ headerShown: false }}
/>
<SettingsStack.Screen name="BoxDetails" component={BoxDetailsScreen} />
<SettingsStack.Screen
name="BoxDetails"
component={BoxDetailsScreen}
options={{ headerShown: false }}
/>
<SettingsStack.Screen
name="PopupBoxInfo"
component={BoxDetailsScreen}
options={{ headerShown: false }}
/>
</SettingsStack.Navigator>
);
};
Expand Down Expand Up @@ -97,79 +106,3 @@ function BoxScreen({ navigation }) {
</SafeAreaView>
);
}

function BoxDetailsScreen({ route, navigation }) {
const { id } = route.params;

const boxService = new BoxService();

const [isLoading, setIsLoading] = useState(true);
const [boxDetails, setBoxDetails] = useState<BoxDetails>(null);

const fetchBoxes = useCallback(async () => {
setIsLoading(true);
try {
const boxDetails: BoxDetails = await boxService.get(id);
setBoxDetails(boxDetails);
} catch (error) {
console.error(error);
}
setIsLoading(false);
}, []);

useEffect((): void => {
void fetchBoxes();
}, [fetchBoxes]);

if (isLoading) {
return <Loading></Loading>;
}

return (
<View>
<Text style={{ color: 'black' }}>
Details Screen {boxDetails?.growthInfo?.seedsAverageInchHeight ?? -1}
</Text>
<View
style={{
marginTop: 10,
}}
>
<Text style={{ color: 'black' }}>Seeds:</Text>
<FlatList
data={boxDetails?.seeds ?? []}
renderItem={({ item }) => <SeedDisplay seed={item} />}
keyExtractor={(item) => item.name}
/>
</View>
<View style={[styles.bottomSection]}>
<View>
<Text style={{ color: 'black' }}>
{boxDetails?.vitals?.temperature?.value ?? -1}
</Text>
<Text style={{ color: 'black' }}>temperature</Text>
</View>
<View>
<Text style={{ color: 'black' }}>
{boxDetails?.vitals?.soilMoisturePercent?.value ?? -1}
</Text>
<Text style={{ color: 'black' }}>soilMoisturePercent</Text>
</View>
<View>
<Text style={{ color: 'black' }}>
{boxDetails?.vitals?.luminosityPercent?.value ?? -1}
</Text>
<Text style={{ color: 'black' }}>luminosityPercent</Text>
</View>
</View>
</View>
);
}

function SeedDisplay({ seed }) {
return (
<View>
<Text style={{ color: 'black' }}>{seed.name}</Text>
</View>
);
}
162 changes: 162 additions & 0 deletions apps/releaf/mobile/src/app/box/screens/BoxDetails.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
import {
View,
Text,
TextInput,
ScrollView,
Button,
TouchableOpacity,
} from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import { useCallback, useEffect, useState } from 'react';
import { Loading } from '../../shared/Loading';
import { BoxService } from '../../infrastructure/services/box.service';
import { BoxDetails } from '../../infrastructure/entities/boxDetails';
import { styled } from 'nativewind';
import { differenceInDays, format } from 'date-fns';
import { CalendarIcon } from 'react-native-heroicons/outline';
import DatePicker from 'react-native-date-picker';

const SSafeAreaView = styled(SafeAreaView);
const SText = styled(Text);
const SView = styled(View);
const SCalendarIcon = styled(CalendarIcon);
const STextInput = styled(TextInput);
const SButton = styled(Button);
const STouchableOpacity = styled(TouchableOpacity);

export function BoxDetailsScreen({ route, navigation }) {
const { id } = route.params;

const [date, setDate] = useState(new Date());
const [open, setOpen] = useState(false);

const boxService = new BoxService();

const [isLoading, setIsLoading] = useState(true);
const [boxDetails, setBoxDetails] = useState<BoxDetails>(null);

const fetchBoxes = useCallback(async () => {
setIsLoading(true);
try {
const boxDetails: BoxDetails = await boxService.get(id);
setBoxDetails(boxDetails);
} catch (error) {
console.error(error);
}
setIsLoading(false);
}, []);

useEffect((): void => {
void fetchBoxes();
}, [fetchBoxes]);

if (isLoading) {
return <Loading></Loading>;
}

const save = () => {
console.log('save');
};

return (
<SSafeAreaView>
<ScrollView>
<SView className="m-10">
<SText className="text-black mb-2">Box ID: {id}</SText>
<SText className="text-black mb-2">
Tree Specie: {boxDetails.treeDefinitionId.value}
</SText>
<SText className="text-black mb-2">
Number:
<SText className="text-red-600 mb-2"> 20</SText>
</SText>
<SText className="text-black">
Device ID:
<SText className="text-red-600 mb-2"> Genparker xxxxx</SText>
</SText>
</SView>

<SView className="border-0.5 border-gray-400 mx-9" />

<SView className="mt-10 mx-12">
<SView className="mb-6">
<STouchableOpacity
onPress={() => {
setOpen(true);
}}
>
<SText className="text-black font-medium mb-1">
Germination Day
</SText>
<SView className="border-0.5 p-3 border-black rounded-lg flex flex-row">
<SView className="w-32">
<SText className="text-black py-2 px-1">
{format(date, 'dd-MMM-yyyy')}
</SText>
</SView>
<SView className="flex-auto">
<SCalendarIcon
className="m-auto mr-0"
color="green"
size={20}
></SCalendarIcon>
</SView>
</SView>
</STouchableOpacity>
</SView>

<SView className="mb-6">
<SText className="text-black font-medium">
Age: {differenceInDays(new Date(), date)} days
</SText>
<SText className="text-black">
The age of your saplings is calculated based on the germination
date.
</SText>
</SView>

<SView>
<SText className="text-black font-medium mb-1">
Average Height (Inch)
</SText>
<STextInput className="text-black border-0.5 p-3 border-black rounded-lg flex flex-row"></STextInput>
</SView>
</SView>

<SView className="mb-2 mt-16 mb-8 mx-12">
<STouchableOpacity onPress={save}>
<SView className="bg-green-600 px-8 py-5 rounded-lg">
<SText className="m-auto font-semibold text-white">Save</SText>
</SView>
</STouchableOpacity>
<STouchableOpacity
className="mt-2"
onPress={() => navigation.goBack()}
>
<SView className="border-green-600 border-[1px] px-8 py-5 rounded-lg">
<SText className="text-green-600 font-semibold m-auto">
Cancel
</SText>
</SView>
</STouchableOpacity>
</SView>

<DatePicker
modal
open={open}
date={date}
mode="date"
onConfirm={(date) => {
if (date <= new Date()) {
setDate(date);
}
setOpen(false);
}}
onCancel={() => {
setOpen(false);
}}
/>
</ScrollView>
</SSafeAreaView>
);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { GrowthInfo } from "./growthInfo";
import { Seed } from "./seed";
import { StringValue } from "./stringValue";
import { Vitals } from "./vital";

export interface BoxDetails {
id: string;
id: StringValue;
treeDefinitionId: StringValue;
growthInfo: GrowthInfo;
seeds: Seed[];
vitals: Vitals;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@


export interface StringValue {
value: string;
}
3 changes: 2 additions & 1 deletion apps/releaf/mobile/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ module.exports = {
700: "#009959",
900: "#2C4E3C",
},
orange: "#F28300"
orange: "#F28300",
black: "#000000",
}
},
borderRadius: {
Expand Down

0 comments on commit 2c09a66

Please sign in to comment.