HustleTime Development: Ignoring specific train lines (part 3)

I’m excited to be rolling out a new version of HustleTime to the app store. It’s going to include some small Ui fixes, as well as a functional Ignore train feature.

Here’s your normal view: where we see some and trains rolling into High Street.

I’ll then go into the modal by clicking the Chevrons and we now have 2 tabs, a favorites as well as an ignore, I’ll click the ignore Icon and move to the ignore menu:

I’ll click on the train I want to ignore (in this case, the )

When we close the modal, the app will refresh; displaying arrivals that exclude the train, as well as display an icon indicating that you’re actively ignoring a train (this will display when ignoring any number of trains).

What this looks like from a programming perspective is such:

On the front end, App state includes an object that has a boolean for each train line.
When I send an api call, I’m including any of those values that are marked true.

let ignoredTrains = []    
let allTrains = Object.entries(this.state.shown)
allTrains.forEach( entry => entry[1] == false ? ignoredTrains.push(entry[0]) : null )

I’m transforming the object into an array that includes the keys for the objects where the boolean value is false, then including that array in the api call.

The back end receives this information and filters out all the departure which have ['train'] values that match the ignored trains. For reference, each departure is stored as its own object, looking something like the following:

{\"train\":\"1\",\"time\":1557778941,\"station\":\"138S\",\"direction\":\"S\"}

or

{ train: '1', time: 1557778941, station: '138S', direction: 'S' }

when parsed. The filter looks something like this (for northbound departures):

DataHelper.retrieve_data.find_all{|sta| sta['station'] == station.code + 'N' && ignored.include?(sta['train']) == false }

Anyway, I’m super excited to be submitting this new feature to the app store for release (hopefully) next week! Then on to Android implementation, and then I’ll see what’s next.