Change datastore to not need to deserialize LocalStorage for every read
This commit is contained in:
@@ -1,15 +1,14 @@
|
||||
import { EL } from "./dom.js";
|
||||
import { displayTripDetails } from "./trip-details.js";
|
||||
import { fetchTrip } from './api.js';
|
||||
import { DataStore } from './datastore.js';
|
||||
|
||||
let element_board = document.querySelector("#drafting-board-content");
|
||||
|
||||
export function addJourneyToDraftingBoard(journey) {
|
||||
for (let leg of journey.legs.filter(item => !("walking" in item))) {
|
||||
DataStore.tracked_trips.remember(leg.tripId, leg.origin.id, leg.destination.id);
|
||||
window.dataStore.tracked_trips.remember(leg.tripId, leg.origin.id, leg.destination.id);
|
||||
fetchTrip(leg.tripId).then(result => {
|
||||
DataStore.trips.remember(result.trip);
|
||||
window.dataStore.trips.remember(result.trip);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -20,7 +19,7 @@ export function drawDraftingBoard() {
|
||||
element_board.innerText = "";
|
||||
|
||||
let sorted_locations = trackedTripsLocationsSorted();
|
||||
let display_locations = sorted_locations.map(item => DataStore.locations.get()[item]);
|
||||
let display_locations = sorted_locations.map(item => window.dataStore.locations.data[item]);
|
||||
|
||||
let grid_location_indexes = {};
|
||||
|
||||
@@ -39,7 +38,7 @@ export function drawDraftingBoard() {
|
||||
|
||||
}
|
||||
|
||||
let trip_data = DataStore.trips.get();
|
||||
let trip_data = window.dataStore.trips.data;
|
||||
console.log(trip_data);
|
||||
|
||||
function getStopFromTrip(tripId, location_id) {
|
||||
@@ -54,7 +53,7 @@ export function drawDraftingBoard() {
|
||||
|
||||
}
|
||||
|
||||
let display_trips = DataStore.tracked_trips.get().map(item => {
|
||||
let display_trips = window.dataStore.tracked_trips.data.map(item => {
|
||||
item["trip_data"] = trip_data[item.trip];
|
||||
|
||||
item.originStop = getStopFromTrip(item.trip, item.origin);
|
||||
@@ -187,7 +186,7 @@ export function sortLocations(sorted_locations, unsorted_locations, trips) {
|
||||
}
|
||||
|
||||
export function trackedTripsLocationsSorted() {
|
||||
let tracked_trips = DataStore.tracked_trips.get();
|
||||
let tracked_trips = window.dataStore.tracked_trips.data;
|
||||
let tracked_locations = Array.from(new Set(tracked_trips.map(trip => trip.origin).concat(tracked_trips.map(trip => trip.destination))));
|
||||
|
||||
console.log(tracked_trips);
|
||||
@@ -197,7 +196,7 @@ export function trackedTripsLocationsSorted() {
|
||||
|
||||
console.log(sorted_locations);
|
||||
|
||||
console.log(sorted_locations.map(item => DataStore.locations.get()[item]?.name));
|
||||
console.log(sorted_locations.map(item => window.dataStore.locations.data[item]?.name));
|
||||
|
||||
return sorted_locations;
|
||||
}
|
||||
|
Reference in New Issue
Block a user