Customize displayed bus stops via a URL query #17
Labels
No labels
bug
contribution welcome
duplicate
enhancement
good first issue
help wanted
invalid
question
upstream
needs/docs
needs/research
needs/upstream
type/bug
type/external
type/feature
type/refactor
urgency
high
urgency
immediate
urgency
low
urgency
medium
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
ScottyLabs/bus-sign#17
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Objective
The current bus sign only shows stops 4407 (tepper) and stop 7117 (UC). We'd like to be able to customize this by passing the
stopsquery parameter in the URL, like so:https://bus-sign.scottylabs.org/?stops=4407,7117
That is, if
stops=X,Y, then display stopXon the left and stopYon the right. Ifstopsis not defined, then default to 4407 and 7117.Assume there are exactly two bus stops in the query parameter, separated by commas. If there is not exactly two, then reject it with some kind of error. (In the future, we'll make this more general but for now just focus on two)
Suggested Approach
The stops we pass into PRT's API are currently defined as a constant
&strarraySTOPSin backend/src/lib.rs. You'll want to define a struct to deserialize thestopsparameter and updateget_predictionsto accept the parameters rather than the constant. TheQueryextractor will probably be used here.We cache API calls in the backend. If there are multiple requests to the backend with different
stops, then this might cause the cache to repeatedly overwrite itself (which defeats the purpose of a cache!). Make sure that this is handled properly as well.Next, you'll have to edit frontend/src/App.svelte to accept a new
stopsparameter (likely using theURLSearchParamsinterface) and display the corresponding data from the backend. The stops are defined as a constant right now, so you'll need to figure out how to change that to a parameter. For inbound vs outbound, use your own discretion (see if there's a way to differentiate between them based on the stop number, otherwise feel free to skip it). Just make sure that the default bus sign looks the same as usual.Note to contributors
Take your time with this. While AI can probably one-shot the code, PLEASE try to do it by yourself for the learning experience. Try to use AI to explain things, not write code for you.
This video tutorial is lengthy, but it assumes no prior Rust experience. The first 20 minutes are dedicated purely to giving an overview Rust. The remaining parts of the video go over
Axum, the web app framework we use.You can also find resources linked on the CMU course 98-008: Intro to Rust Lang! Click on the materials dropdown of each lecture in the Schedules page (shameless plug)
The frontend should be a bit easier to pick up, but if you'd like, check out the official Svelte tutorial! In particular, you may find lifecycle hooks like
onMountto be useful for this.Customize displayed bus stops via the URL pathto Customize displayed bus stops via a URL query