Skip to content

Commit

Permalink
fix null errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Nova136 committed Aug 11, 2024
1 parent 95a6b77 commit 59c18f3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
17 changes: 12 additions & 5 deletions src/components/ChatRoom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,31 @@ export default function ChatRoom(props: any) {
};
}, [props.chatRoom.id]);

const user = props.chatRoom.Users?.items?.[0]?.user;
const accommodation = chatRoom.Accommodation;

if (!user || !accommodation) {
return null; // or you can return a loading indicator or some fallback UI
}

return (
<Pressable
onPress={() =>
navigation.navigate("Chat", {
id: props.chatRoom.id,
name: props.chatRoom.Users.items[0].user.name,
title: chatRoom.Accommodation.title,
price: chatRoom.Accommodation.price,
name: user.name,
title: accommodation.title,
price: accommodation.price,
})
}
>
<View style={{ flex: 1, flexDirection: "row", marginVertical: 20 }}>
<Avatar.Text size={50} label="U" />
<View style={{ flexDirection: "column", marginHorizontal: 15 }}>
<Text variant="labelMedium" style={{ color: "gray" }}>
{props.chatRoom.Users.items[0].user.name}
{user.name}
</Text>
<Text variant="titleMedium"> {chatRoom.Accommodation.title} </Text>
<Text variant="titleMedium"> {accommodation.title} </Text>
<Text variant="labelMedium" style={{ color: "gray" }}>
{chatRoom.LastMessage?.text}
</Text>
Expand Down
7 changes: 6 additions & 1 deletion src/screens/AccommodationDetailScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,12 @@ export default function AccommodationDetailScreen({ navigation, route }) {
Location
</Text>

<Map latitude={address.geo.lat} longitude={address.geo.lng} />

{address?.geo?.lat && address?.geo?.lng ? (
<Map latitude={address.geo.lat} longitude={address.geo.lng} />
) : (
<Text variant="bodyMedium">Location data not available</Text>
)}

<Text variant="titleMedium" style={{ fontWeight: "bold" }}>
441B Clementi Avenue
Expand Down

0 comments on commit 59c18f3

Please sign in to comment.