Use new module API
This commit is contained in:
parent
2dfeef138b
commit
db3abd0a86
@ -95,7 +95,23 @@ export default class MapComponent extends Component {
|
||||
|
||||
async loadBookmarks() {
|
||||
try {
|
||||
const places = await this.storage.places.listAll();
|
||||
// For now, continue to load ALL places.
|
||||
// In the future, we can pass geohash prefixes based on map view extent here.
|
||||
// e.g. this.storage.loadAllPlaces(this.getVisiblePrefixes())
|
||||
// But since the signature of list() changed to optional prefixes, we should use loadAllPlaces
|
||||
// from the service instead of accessing storage.places.listAll directly if possible,
|
||||
// OR update this call to match the new API.
|
||||
// The service wraps it in loadAllPlaces(), but let's check what that does.
|
||||
|
||||
// The Service now has: loadAllPlaces(prefixes = null) -> calls rs.places.list(prefixes)
|
||||
|
||||
// Let's use the Service method if we want to update the tracked property,
|
||||
// BUT this component seems to want to manage the vector source directly.
|
||||
// Actually, looking at line 98, it calls `this.storage.places.listAll()`.
|
||||
// The `listAll` method was REMOVED from the module and replaced with `list`.
|
||||
|
||||
// So we MUST change this line.
|
||||
const places = await this.storage.places.getPlaces();
|
||||
|
||||
this.bookmarkSource.clear();
|
||||
|
||||
|
||||
@ -18,6 +18,20 @@ export default class StorageService extends Service {
|
||||
});
|
||||
|
||||
this.rs.access.claim('places', 'rw');
|
||||
// Caching strategy:
|
||||
// With the new nested structure, enabling caching on root '/' might try to sync everything.
|
||||
// For now, let's keep it, but we might need to be more selective later if data grows huge.
|
||||
// Note: The path structure changed from /places/ to just root access in the module?
|
||||
// In places.ts: getPath returns "ab/cd/id".
|
||||
// RemoteStorage modules usually implicitly use a base scope based on module name if not defined differently?
|
||||
// Wait, the module defines `privateClient`.
|
||||
// When we do `privateClient.storeObject`, it stores it under the module's scope.
|
||||
// If module name is 'places', then it's stored under /places/.
|
||||
// So getPath "ab/cd/id" becomes "/places/ab/cd/id".
|
||||
// So enabling caching on '/places/' is correct.
|
||||
// However, per instructions, we should set maxAge to false for listings in the module,
|
||||
// which we did.
|
||||
// We also need to be careful about what we cache here.
|
||||
this.rs.caching.enable('/places/');
|
||||
|
||||
window.remoteStorage = this.rs;
|
||||
@ -43,13 +57,30 @@ export default class StorageService extends Service {
|
||||
this.loadAllPlaces();
|
||||
}
|
||||
|
||||
async loadAllPlaces() {
|
||||
async loadAllPlaces(prefixes = null) {
|
||||
try {
|
||||
const places = await this.rs.places.listAll();
|
||||
// If prefixes is null, it loads everything (recursive scan).
|
||||
// If prefixes is an array ['w1q7'], it loads just that sector.
|
||||
const places = await this.rs.places.getPlaces(prefixes);
|
||||
|
||||
if (places && Array.isArray(places)) {
|
||||
this.savedPlaces = places;
|
||||
if (prefixes) {
|
||||
// If partial load, we might want to merge instead of replace?
|
||||
// For now, let's keep the simple behavior: replacing the tracked array triggers updates.
|
||||
// However, replacing 'all saved places' with 'just these visible places'
|
||||
// might hide other bookmarks from the list.
|
||||
|
||||
// Strategy: maintain a Map of loaded places to avoid duplicates/overwrites?
|
||||
// Or just append unique ones?
|
||||
const currentIds = new Set(this.savedPlaces.map((p) => p.id));
|
||||
const newPlaces = places.filter((p) => !currentIds.has(p.id));
|
||||
this.savedPlaces = [...this.savedPlaces, ...newPlaces];
|
||||
} else {
|
||||
// Full reload
|
||||
this.savedPlaces = places;
|
||||
}
|
||||
} else {
|
||||
this.savedPlaces = [];
|
||||
if (!prefixes) this.savedPlaces = [];
|
||||
}
|
||||
console.log('Loaded saved places:', this.savedPlaces.length);
|
||||
} catch (e) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user