-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from TritonSE/DynamicMedicalEmergencyPage
Merge dynamic medical emergency page to resolve issue #9
- Loading branch information
Showing
8 changed files
with
558 additions
and
103 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,48 @@ | ||
import { useNavigation } from "@react-navigation/native"; | ||
import { useEffect, useState } from "react"; | ||
import { Pressable, Text } from "react-native"; | ||
|
||
import { getEmergency } from "./emergencies"; | ||
|
||
export default function HomeScreen() { | ||
const navigation = useNavigation(); | ||
const [emergency, setEmergency] = useState(null); | ||
|
||
useEffect(() => { | ||
async function fetchEmergency() { | ||
try { | ||
//It seems to work on Android and iPad | ||
//Test Case: Cervical Spine Injury - demonstrate recursive rendering | ||
const emergencyObjectId = "65b36d110c9c60394b37f7a1"; | ||
//Separate Test Case here: To Be Deleted Emergency - demonstrates textual rendering | ||
//const emergencyObjectId = "65b369a8e8fe96a404d4fd6b"; | ||
//Test Case: New Emergency Placeholder Four - demonstrates blank rendering (only title in db) | ||
//const emergencyObjectId = "65c2ef26b87b638ac61beb09"; | ||
//Test Case: Cervical Strain - demonstrates simple placeholder headers | ||
//const emergencyObjectId = "65b36f12640d62464e0dd129"; | ||
const result = await getEmergency(emergencyObjectId); | ||
if (result.success) { | ||
setEmergency(result.data); | ||
} else { | ||
console.error("Error fetching emergency data:", result.error); | ||
} | ||
} catch (error) { | ||
console.error("Error fetching emergency data:", error); | ||
} | ||
} | ||
|
||
void fetchEmergency(); | ||
}, []); | ||
|
||
const handlePress = () => { | ||
if (emergency !== null) { | ||
navigation.navigate("Conditions", { emergency }); | ||
} | ||
}; | ||
|
||
return ( | ||
<Pressable onPress={handlePress}> | ||
<Text>Navigate to ConditionsSection</Text> | ||
</Pressable> | ||
); | ||
} |
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,43 @@ | ||
import React from "react"; | ||
import { Text, View } from "react-native"; | ||
|
||
import styles from "../ConditionSectionStyles"; | ||
|
||
type StringValue = string | string[] | { [key: string]: StringValue } | undefined; | ||
|
||
type Props = { | ||
data: StringValue; | ||
}; | ||
|
||
const BulletList: React.FC<{ items: string[] }> = ({ items }) => ( | ||
<View style={styles.list}> | ||
{items.map((item: string, index: number) => ( | ||
<View key={index} style={styles.listItem}> | ||
<Text style={styles.bullet}>{"\u2022"}</Text> | ||
<Text style={styles.itemText}>{item}</Text> | ||
</View> | ||
))} | ||
</View> | ||
); | ||
|
||
const StringRenderer: React.FC<Props> = ({ data }) => { | ||
if (typeof data === "string") { | ||
return <Text style={styles.descriptionInfo}>{data}</Text>; | ||
} else if (Array.isArray(data) && data.every((item) => typeof item === "string")) { | ||
return <BulletList items={data} />; | ||
} else if (typeof data === "object") { | ||
return ( | ||
<View> | ||
{Object.keys(data).map((key, index) => ( | ||
<View key={index}> | ||
<Text style={styles.descriptionTitle}>{key}</Text> | ||
<StringRenderer data={data[key] as StringValue} /> | ||
</View> | ||
))} | ||
</View> | ||
); | ||
} | ||
return null; | ||
}; | ||
|
||
export default StringRenderer; |
Oops, something went wrong.