Skip to content

Commit

Permalink
feat: make LineProfilePage actually work & improve BusTooltip (#744)
Browse files Browse the repository at this point in the history
- make LineProfilePage fully functional 
- style BusTooltip according to language and make it scrollable
  • Loading branch information
itsoriki authored May 12, 2024
1 parent d3b0d5f commit cf0e663
Show file tree
Hide file tree
Showing 18 changed files with 532 additions and 462 deletions.
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = [
},
},
{
settings: { 'import/resolver': { typescript: {} } },
settings: { 'import/resolver': { typescript: {} }, react: { version: 'detect' } },
languageOptions: {
parser: typescriptEslintParser,
parserOptions: {
Expand Down
83 changes: 83 additions & 0 deletions src/hooks/useSingleLineData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import moment from 'moment'
import { useContext, useEffect, useMemo, useState } from 'react'
import { getStopsForRouteAsync } from 'src/api/gtfsService'
import useVehicleLocations from 'src/api/useVehicleLocations'
import { BusStop } from 'src/model/busStop'
import { SearchContext } from 'src/model/pageState'
import { Point } from 'src/pages/timeBasedMap'

export const useSingleLineData = (lineRef?: number, routeIds?: number[]) => {
const {
search: { timestamp },
} = useContext(SearchContext)
const [filteredPositions, setFilteredPositions] = useState<Point[]>([])
const [startTime, setStartTime] = useState<string>('00:00:00')
const [plannedRouteStops, setPlannedRouteStops] = useState<BusStop[]>([])

const { locations, isLoading: locationsAreLoading } = useVehicleLocations({
from: +new Date(timestamp).setHours(0, 0, 0, 0),
to: +new Date(timestamp).setHours(23, 59, 59, 999),
lineRef,
splitMinutes: 20,
})

const positions = useMemo(() => {
const pos = locations.map<Point>((location) => ({
loc: [location.lat, location.lon],
color: location.velocity,
operator: location.siri_route__operator_ref,
bearing: location.bearing,
recorded_at_time: new Date(location.recorded_at_time).getTime(),
point: location,
}))

return pos
}, [locations])

const options = useMemo(() => {
const options = positions
.map((position) => position.point?.siri_ride__scheduled_start_time) // get all start times
.filter((time, i, arr) => arr.indexOf(time) === i) // unique
.map((time) => new Date(time ?? 0).toLocaleTimeString()) // convert to strings
.map((time) => ({
// convert to options
value: time,
label: time,
}))
return options
}, [positions])

useEffect(() => {
if (startTime !== '00:00:00' && positions.length > 0) {
setFilteredPositions(
positions.filter(
(position) =>
new Date(position.point?.siri_ride__scheduled_start_time ?? 0).toLocaleTimeString() ===
startTime,
),
)
}
if (startTime !== '00:00:00') {
const [hours, minutes] = startTime.split(':')
const startTimeTimestamp = +new Date(
positions[0].point?.siri_ride__scheduled_start_time ?? 0,
).setHours(+hours, +minutes, 0, 0)
handlePlannedRouteStops(routeIds ?? [], startTimeTimestamp)
}
}, [startTime])

const handlePlannedRouteStops = async (routeIds: number[], startTimeTs: number) => {
const stops = await getStopsForRouteAsync(routeIds, moment(startTimeTs))
setPlannedRouteStops(stops)
}

return {
locationsAreLoading,
positions,
options,
filteredPositions,
plannedRouteStops,
startTime,
setStartTime,
}
}
25 changes: 22 additions & 3 deletions src/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,37 @@
"funding_paragraph": "The Databus project is developed by the Hasadna for public knowledge, by the contributions of volunteers, and based upon",
"all_rides_completed": "All/Almost the rides are completed",
"missing_rides": "Of the rides are missing",
"line": "line",
"line": "Line",
"from": "from",
"destination": "destination",
"velocity": "velocity",
"kmh": "kmh",
"sample_time": "sample time",
"at_time": "at",
"vehicle_ref": "vehicle plate",
"drive_direction": "drive direction",
"bearing": "bearing",
"coords": "coords",
"hide_document": "hide document",
"show_document": "show document",
"hide_document": "Hide geeks data",
"show_document": "Show geeks data",
"lineProfile": {
"title": "Profile for Line",
"notFound": "We couldn't find the line you were looking for :(",
"id": "ID",
"date": "Date",
"lineReference": "Line Reference",
"operatorReference": "Operator Reference",
"agencyName": "Agency Name",
"route": {
"shortName": "Route Short Name",
"start": "Start",
"end": "End",
"mkt": "Route MKT",
"direction": "Route Direction",
"alternative": "Route Alternative",
"type": "Route Type"
}
},
"aboutPage": {
"title": "About us",
"privacyText": "<0>Google Analytics</0> service is embedded in the website to analyze the usage patterns and positioning of the website in search engines. This code reveals to the operators of the service information regarding the behavior of the users. <1>Learn more</1> about the privacy policy of the service.",
Expand Down
21 changes: 18 additions & 3 deletions src/locale/he.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"github_link": "למעבר אל GitHub",
"dark_mode_tooltip": "עבור למצב חשוך",
"light_mode_tooltip": "עבור למצב בהיר",
"Change Language": "Englesh",
"Change Language": "English",
"bug_title": "כותרת/סיכום",
"bug_title_message": "אנא הזן כותרת/סיכום!",
"bug_description": "תיאור",
Expand Down Expand Up @@ -118,15 +118,30 @@
"velocity": "מהירות",
"kmh": "קמ״ש",
"sample_time": "זמן דגימה",
"at_time": "בשעה",
"vehicle_ref": "לוחית רישוי",
"drive_direction": "כיוון נסיעה:",
"drive_direction": "כיוון נסיעה",
"bearing": "מעלות",
"coords": "נ.צ.",
"hide_document": "הסתר מידע לגיקים",
"show_document": "הצג מידע לגיקים",
"lineProfile": {
"title": "פרופיל קו",
"notFound": "לא הצלחנו למצוא את הקו שחיפשת :("
"notFound": "לא הצלחנו למצוא את הקו שחיפשת :(",
"id": "מזהה טכני",
"date": "תאריך",
"lineReference": "מזהה קו",
"operatorReference": "מזהה חברה מפעילה",
"agencyName": "שם חברה מפעילה",
"route": {
"shortName": "מס' קו",
"start": "מוצא",
"end": "יעד",
"mkt": "מק\"ט קו",
"direction": "כיוון קו",
"alternative": "חלופה מס'",
"type": "סוג קו"
}
},
"errorPage": {
"title": "אופס, משהו השתבש",
Expand Down
200 changes: 0 additions & 200 deletions src/pages/Profile.tsx

This file was deleted.

Loading

0 comments on commit cf0e663

Please sign in to comment.