mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-01 00:43:15 +00:00
feat(places): All saved shows each place once, All places shows its count
A place saved into several lists from the same trip place showed once per list in All saved and counted that often, while All places groups the copies as one place. All saved now shows such a place once, the first copy read standing for it, and the rail counts All saved and All places the way All places groups them, on the desktop and the phone.
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
// FE-STORE-COLUNION-001 to FE-STORE-COLUNION-002: the places of several lists, each place once.
|
||||
import type { CollectionPlace } from '@trek/shared';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { distinctPlaces } from './collectionUnion';
|
||||
|
||||
const saved = (id: number, over: Partial<CollectionPlace> = {}): CollectionPlace => ({
|
||||
id,
|
||||
collection_id: 1,
|
||||
name: `Place ${id}`,
|
||||
status: 'idea',
|
||||
...over,
|
||||
});
|
||||
|
||||
describe('distinctPlaces', () => {
|
||||
it('FE-STORE-COLUNION-001: copies saved from one trip place are one place, the first one read stands for it', () => {
|
||||
const tower = saved(9, { collection_id: 1, name: 'Belem Tower', source_trip_id: 1, source_place_id: 1 });
|
||||
const again = saved(10, { collection_id: 2, name: 'Belem Tower', source_trip_id: 1, source_place_id: 1 });
|
||||
const other = saved(11, { collection_id: 2, source_trip_id: 1, source_place_id: 2 });
|
||||
expect(distinctPlaces([tower, again, other])).toEqual([tower, other]);
|
||||
});
|
||||
|
||||
it('FE-STORE-COLUNION-002: saved places of no trip stay apart, even under one name', () => {
|
||||
const a = saved(1, { name: 'Senso-ji' });
|
||||
const b = saved(2, { collection_id: 2, name: 'Senso-ji' });
|
||||
expect(distinctPlaces([a, b])).toEqual([a, b]);
|
||||
expect(distinctPlaces([])).toEqual([]);
|
||||
});
|
||||
});
|
||||
@@ -32,3 +32,19 @@ export async function loadUnionPlaces(ids: number[]): Promise<CollectionPlace[]>
|
||||
}
|
||||
return merged;
|
||||
}
|
||||
|
||||
/**
|
||||
* The places of several lists with each place once, for the views over all of
|
||||
* them (All saved, the picker's All lists): copies saved from the same trip
|
||||
* place are one place, the way All places groups them, and the first one read
|
||||
* stands for it. Every other saved place stays, even with the same name.
|
||||
*/
|
||||
export function distinctPlaces(places: CollectionPlace[]): CollectionPlace[] {
|
||||
const seen = new Set<string>();
|
||||
return places.filter((p) => {
|
||||
const key = p.source_place_id != null ? `trip:${p.source_place_id}` : `list:${p.id}`;
|
||||
if (seen.has(key)) return false;
|
||||
seen.add(key);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user