Improve datastore about cached trip details
This commit is contained in:
@@ -7,6 +7,16 @@ export class LocationsDataStore {
|
||||
LocationsDataStore.set(locations);
|
||||
}
|
||||
|
||||
static rememberAllIfNotExist(location_list) {
|
||||
let locations = LocationsDataStore.get();
|
||||
for (let location of location_list) {
|
||||
if (!(location.id in locations)) {
|
||||
locations[location.id] = location;
|
||||
}
|
||||
}
|
||||
LocationsDataStore.set(locations);
|
||||
}
|
||||
|
||||
static get() {
|
||||
return DataStore.get("locations") || {};
|
||||
}
|
||||
@@ -16,7 +26,6 @@ export class LocationsDataStore {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export class RecentLocationsDataStore {
|
||||
static remember(location_id) {
|
||||
let recent_locations = RecentLocationsDataStore.get();
|
||||
@@ -36,6 +45,48 @@ export class RecentLocationsDataStore {
|
||||
}
|
||||
}
|
||||
|
||||
export class TrackedTripsDataStore {
|
||||
static remember(trip_id, origin_id, destination_id) {
|
||||
let tracked_trips = TrackedTripsDataStore.get();
|
||||
tracked_trips.push({
|
||||
trip: trip_id,
|
||||
origin: origin_id,
|
||||
destination: destination_id,
|
||||
});
|
||||
TrackedTripsDataStore.set(tracked_trips);
|
||||
}
|
||||
|
||||
static get() {
|
||||
return DataStore.get("tracked-trips") || [];
|
||||
}
|
||||
|
||||
static set(value) {
|
||||
DataStore.set("tracked-trips", value);
|
||||
}
|
||||
}
|
||||
|
||||
export class TripsDataStore {
|
||||
static remember(trip) {
|
||||
TripsDataStore.rememberAll([trip]);
|
||||
}
|
||||
|
||||
static rememberAll(trip_list) {
|
||||
let tracked_trips = TripsDataStore.get();
|
||||
for (let trip of trip_list) {
|
||||
tracked_trips[trip.id] = trip;
|
||||
}
|
||||
TripsDataStore.set(tracked_trips);
|
||||
}
|
||||
|
||||
static get() {
|
||||
return DataStore.get("trips") || {};
|
||||
}
|
||||
|
||||
static set(value) {
|
||||
DataStore.set("trips", value);
|
||||
}
|
||||
}
|
||||
|
||||
export class DataStore {
|
||||
static get(key) {
|
||||
return JSON.parse(window.localStorage.getItem(key));
|
||||
@@ -47,4 +98,6 @@ export class DataStore {
|
||||
|
||||
static locations = LocationsDataStore;
|
||||
static recent_locations = RecentLocationsDataStore;
|
||||
static tracked_trips = TrackedTripsDataStore;
|
||||
static trips = TripsDataStore;
|
||||
}
|
||||
|
Reference in New Issue
Block a user