Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Route list date scroll #322

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions app/screens/route-list/components/result-date-card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { TextStyle, View, ViewStyle } from "react-native"
import { Text } from "../../../components"
import { color, spacing } from "../../../theme"

const DATE_TEXT_STYLES: TextStyle = {
color: color.primary,
}

const DATE_CONTAINER_STYLES: ViewStyle = {
display: "flex",
alignItems: "center",
alignContent: "center",
paddingBottom: spacing[2],
height: "100%",
justifyContent: "center",
}

export const ResultDateCard = function ResultDateCard(props: { date: string }) {
return (
<View style={DATE_CONTAINER_STYLES}>
<Text text={props.date} style={DATE_TEXT_STYLES} />
</View>
)
}
24 changes: 9 additions & 15 deletions app/screens/route-list/route-list-screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import { RouteListScreenProps } from "../../navigators/main-navigator"
import { useStores } from "../../models"
import { color, fontScale, spacing } from "../../theme"
import { RouteItem } from "../../services/api"
import { Screen, RouteDetailsHeader, RouteCard, RouteCardHeight, Text } from "../../components"
import { flatMap, max, round, uniqBy } from "lodash"
import { ResultDateCard } from "./components/result-date-card"
import { Screen, RouteDetailsHeader, RouteCard, RouteCardHeight } from "../../components"
import { NoTrainsFoundMessage, NoInternetConnection, RouteListWarning, WarningType, DateScroll } from "./components"
import { flatMap, max, round } from "lodash"
import { translate } from "../../i18n"

const ROOT: ViewStyle = {
Expand Down Expand Up @@ -40,7 +41,11 @@ export const RouteListScreen = observer(function RouteListScreen({ navigation, r

useEffect(() => {
if (trains.isSuccess) {
setRouteData((prevData) => [...prevData, routePlan.date.toDateString(), ...trains.data])
setRouteData((prevData) =>
uniqBy([...prevData, routePlan.date.toDateString(), ...trains.data], (item) => {
return typeof item === "string" ? item : item.trains.map((train) => train.departureTimeString).join()
Copy link
Collaborator

@planecore planecore Oct 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unique by train numbers AND departure times as departure times can be the same

item.trains.map((train) => train.trainNumber).join()

}),
)
}
}, [trains.data?.length])

Expand Down Expand Up @@ -88,18 +93,7 @@ export const RouteListScreen = observer(function RouteListScreen({ navigation, r

const renderRouteCard = ({ item }: { item: RouteData }) => {
if (typeof item === "string") {
return (
<View
style={{
display: "flex",
alignItems: "center",
padding: "2%",
justifyContent: "center",
}}
>
<Text text={item} style={{ color: color.primary }} />
</View>
)
return <ResultDateCard date={item} />
}
const departureTime = item.trains[0].departureTime
let arrivalTime = item.trains[0].arrivalTime
Expand Down