-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ - Israel Railways Announcements & Urgent Updates (#289)
Co-authored-by: Guy Tepper <[email protected]>
- Loading branch information
Showing
27 changed files
with
6,166 additions
and
7,523 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
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,47 @@ | ||
import { ViewStyle, Platform, View, TextStyle } from "react-native" | ||
import TouchableScale from "react-native-touchable-scale" | ||
import { fontScale, spacing, color } from "../../theme" | ||
import { Text } from "../text/text" | ||
import { openLink } from "../../utils/helpers/open-link" | ||
|
||
const ANNOUNCEMENT_CARD: ViewStyle = { | ||
minHeight: 80 * fontScale, | ||
|
||
marginBottom: spacing[4], | ||
paddingVertical: spacing[3], | ||
paddingHorizontal: spacing[3], | ||
|
||
borderRadius: Platform.select({ ios: 12, android: 8 }), | ||
backgroundColor: Platform.select({ ios: color.tertiaryBackground, android: color.inputBackground }), | ||
shadowColor: color.palette.black, | ||
shadowOffset: { height: 0, width: 0 }, | ||
shadowOpacity: 0.05, | ||
elevation: 1, | ||
} | ||
|
||
const TITLE_STYLE: TextStyle = { | ||
fontFamily: "Heebo", | ||
color: color.primary, | ||
fontSize: 16, | ||
marginBottom: spacing[0], | ||
} | ||
|
||
const BODY_STYLE: TextStyle = { | ||
fontFamily: "Heebo", | ||
fontSize: 14, | ||
} | ||
|
||
type AnnouncementCardProps = { | ||
title?: string | ||
body: string | ||
link?: string | ||
} | ||
|
||
export const AnnouncementCard = ({ title, body, link }: AnnouncementCardProps) => ( | ||
<TouchableScale activeScale={0.98} friction={10} disabled={!link} onPress={() => openLink(link)}> | ||
<View style={ANNOUNCEMENT_CARD}> | ||
{title && <Text style={TITLE_STYLE}>{title}</Text>} | ||
<Text style={BODY_STYLE}>{body}</Text> | ||
</View> | ||
</TouchableScale> | ||
) |
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,30 @@ | ||
import { View, Image, ViewStyle } from "react-native" | ||
import { spacing, color } from "../../theme" | ||
import { Text } from "../text/text" | ||
|
||
const SEPARATOR_STYLE: ViewStyle = { | ||
backgroundColor: color.separator, | ||
height: 1, | ||
width: "100%", | ||
marginVertical: spacing[4], | ||
} | ||
|
||
type AnnouncementsHeaderProps = { | ||
separator?: "top" | "bottom" | ||
} | ||
|
||
export const AnnouncementsHeader: React.FC<AnnouncementsHeaderProps> = ({ separator }) => { | ||
return ( | ||
<> | ||
{separator === "top" && <View style={SEPARATOR_STYLE} />} | ||
<View style={{ width: "100%", marginBottom: spacing[4], flexDirection: "row", alignItems: "center" }}> | ||
<Image | ||
style={{ width: 20, height: 20, marginEnd: spacing[2], tintColor: color.text }} | ||
source={require("../../../assets/info.png")} | ||
/> | ||
<Text tx="routes.updates" style={{ fontWeight: "500" }} /> | ||
</View> | ||
{separator === "bottom" && <View style={SEPARATOR_STYLE} />} | ||
</> | ||
) | ||
} |
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,78 @@ | ||
import React from "react" | ||
import { ActivityIndicator, Button, Image, TextStyle, View, ViewStyle } from "react-native" | ||
import { useQuery } from "react-query" | ||
import { translate, userLocale } from "../../i18n" | ||
import { Announcement, PopUpMessage, railApi } from "../../services/api" | ||
import { color, spacing } from "../../theme" | ||
import { AnnouncementCard } from "./announcement-card" | ||
import { Text } from "../text/text" | ||
|
||
type AnnouncementsListProps = { | ||
updatesType: "regular" | "urgent" | ||
relevantStationIds?: string[] | ||
hideLoader?: boolean | ||
} | ||
|
||
export const AnnouncementsList: React.FC<AnnouncementsListProps> = ({ updatesType, relevantStationIds, hideLoader }) => { | ||
const { | ||
isLoading, | ||
data: announcements, | ||
isError, | ||
refetch, | ||
} = useQuery<Announcement[] | PopUpMessage[]>(["announcements", updatesType, relevantStationIds], () => { | ||
return updatesType === "regular" | ||
? railApi.getAnnouncements(userLocale, relevantStationIds) | ||
: railApi.getPopupMessages(userLocale) | ||
}) | ||
|
||
if (isLoading) { | ||
if (hideLoader) { | ||
return <></> | ||
} | ||
|
||
return <ActivityIndicator style={{ marginTop: spacing[5] }} size="large" /> | ||
} | ||
|
||
if (isError) { | ||
return <ErrorMessage refetch={refetch} /> | ||
} | ||
|
||
return ( | ||
<> | ||
{announcements.map((announcement, index) => { | ||
if (updatesType === "regular") { | ||
const a: Announcement = announcement | ||
return <AnnouncementCard key={index} title={a.updateHeader} body={a.updateContent} link={a.updateLink} /> | ||
} else { | ||
const a: PopUpMessage = announcement | ||
return <AnnouncementCard key={index} title={a.title} body={a.messageBody} /> | ||
} | ||
})} | ||
</> | ||
) | ||
} | ||
|
||
const ERORR_MESSAGE_WRAPPER: ViewStyle = { | ||
paddingHorizontal: spacing[3], | ||
alignItems: "center", | ||
} | ||
|
||
const ERORR_MESSAGE_TEXT: TextStyle = { | ||
fontSize: 20, | ||
fontWeight: "bold", | ||
marginBottom: spacing[1], | ||
} | ||
|
||
function ErrorMessage({ refetch }) { | ||
return ( | ||
<View style={ERORR_MESSAGE_WRAPPER}> | ||
<Image | ||
source={require("../../../assets/info.png")} | ||
style={{ width: 80, height: 80, marginBottom: spacing[0], tintColor: color.error }} | ||
/> | ||
<Text tx="common.error" style={ERORR_MESSAGE_TEXT} /> | ||
<Text tx="routes.updatesError" style={{ textAlign: "center", marginBottom: spacing[2] }} /> | ||
<Button onPress={() => refetch()} title={translate("common.tryAgain")} /> | ||
</View> | ||
) | ||
} |
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,26 @@ | ||
import React from "react" | ||
import { Platform, View } from "react-native" | ||
import { useQuery } from "react-query" | ||
import { userLocale } from "../../i18n" | ||
import { PopUpMessage, railApi } from "../../services/api" | ||
import { spacing } from "../../theme" | ||
import { Text } from "../text/text" | ||
import { Screen } from "../screen/screen" | ||
import { useIsDarkMode } from "../../hooks" | ||
import { AnnouncementCard } from "./announcement-card" | ||
|
||
export const UrgentAnnouncements = () => { | ||
const isDarkMode = useIsDarkMode() | ||
const { data: messages } = useQuery<PopUpMessage[]>(["announcements", "urgent"], () => railApi.getPopupMessages(userLocale)) | ||
|
||
return ( | ||
<Screen unsafe statusBar={Platform.select({ ios: "light-content" })} statusBarBackgroundColor={isDarkMode ? "#000" : "#fff"}> | ||
<Text style={{ fontSize: 48, textAlign: "center", marginVertical: spacing[4] }}>📣</Text> | ||
<View style={{ paddingHorizontal: spacing[4] }}> | ||
{messages?.map((m) => ( | ||
<AnnouncementCard body={m.messageBody} /> | ||
))} | ||
</View> | ||
</Screen> | ||
) | ||
} |
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
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
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,51 @@ | ||
import React from "react" | ||
import { createStackNavigator, StackScreenProps } from "@react-navigation/stack" | ||
import { CloseButton } from "../../components" | ||
import { AnnouncementsScreen } from "../../screens/announcements/announcements-screen" | ||
import { color, spacing, typography } from "../../theme" | ||
import { Platform, TextStyle } from "react-native" | ||
import { translate } from "../../i18n" | ||
import { UrgentAnnouncements } from "../../components/announcements/urgent-announcements" | ||
|
||
const AnnouncementsStack = createStackNavigator() | ||
|
||
export type AnnouncementsScreenProps = StackScreenProps<{}> | ||
|
||
export const AnnouncementsNavigator = () => ( | ||
<AnnouncementsStack.Navigator | ||
screenOptions={{ | ||
headerTintColor: color.primary, | ||
headerBackTitleVisible: false, | ||
headerStatusBarHeight: Platform.select({ ios: 10, android: 5 }), | ||
}} | ||
> | ||
<AnnouncementsStack.Screen | ||
name="announcement" | ||
component={AnnouncementsScreen} | ||
options={({ navigation }) => ({ | ||
title: translate("routes.updates"), | ||
headerLeft: () => <CloseButton onPress={() => navigation.goBack()} style={{ marginRight: spacing[2] }} />, | ||
headerTitleStyle: Platform.select({ ios: iOSTitleStyle, android: { ...androidTitleStyle, marginBottom: 10 } }), | ||
})} | ||
/> | ||
<AnnouncementsStack.Screen | ||
name="urgent" | ||
component={UrgentAnnouncements} | ||
options={({ navigation }) => ({ | ||
title: translate("routes.updates"), | ||
headerLeft: () => <CloseButton onPress={() => navigation.goBack()} style={{ marginRight: spacing[2] }} />, | ||
headerTitleStyle: Platform.select({ ios: iOSTitleStyle, android: { ...androidTitleStyle, marginBottom: 10 } }), | ||
})} | ||
/> | ||
</AnnouncementsStack.Navigator> | ||
) | ||
|
||
const iOSTitleStyle: TextStyle = { | ||
fontSize: 19, | ||
fontFamily: typography.primary, | ||
fontWeight: "400", | ||
marginRight: 10, | ||
marginBottom: 8, | ||
} | ||
|
||
const androidTitleStyle: TextStyle = { marginLeft: -18.5, marginBottom: 7.5 } |
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
Oops, something went wrong.