-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(predictions): only fetch predictions for a train when user opens …
…the train opover (#203) * fix: get departure predictions per route instead of per vehicle * fix: prediction fetching * fix: prediction fetching * fix: prediction * fix: remove extra file * fix: remove redundant variable * fix: some naming * fix: trailing whitespace
- Loading branch information
Showing
7 changed files
with
66 additions
and
21 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
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,20 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { Prediction } from '../types'; | ||
|
||
const getPrediction = (tripId: string, stopId: string) => { | ||
return fetch(`/predictions/${tripId}/${stopId}`).then((res) => { | ||
return res.json(); | ||
}); | ||
}; | ||
|
||
export const usePrediction = (tripId: string, stopId: string) => { | ||
const [pred, setPrediction] = useState<Prediction | null>(null); | ||
useEffect(() => { | ||
if (!tripId) { | ||
return; | ||
} | ||
getPrediction(tripId, stopId).then((pred) => setPrediction(pred)); | ||
}, [tripId, stopId]); | ||
|
||
return pred; | ||
}; |
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