feat(todo): a pin in the map's middle, and what is around it (ADR 0033, D32)

The location picker fills the screen with its map, the search floating
over it. A pin stays in the middle, lifting while the map moves, as
Molly's; where it lands the instance names the address and lists the
places around, as Threema's. That is `nearby` on the search endpoint,
for those signed in, the point neither kept nor logged, counted among
the searches: two lookups, as a plain one finds house numbers alone.

Fixes the map's credit, which overflowed a phone and was pale on white.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
This commit is contained in:
Tizian 「ティツィアーン」 2026-11-05 23:42:06 +01:00
commit ce07fab193
Signed by: raisondetredev
GPG key ID: 07F6FCF405488B64
3 changed files with 1254 additions and 113 deletions

View file

@ -40,6 +40,33 @@ class _FakePhoton implements PlaceFinder {
}
return photonAnswer(answer);
}
/// What was asked around a point: with tags for places to go, else for the
/// address.
final around_ = <({Set<String> tags, String? language})>[];
/// What Photon finds around a point.
List<Map<String, Object?>> address = const [
{'lat': 47.5, 'lon': 9.7, 'street': 'Danziger Weg', 'housenumber': '4'},
];
List<Map<String, Object?>> neighbours = const [
{'lat': 47.5, 'lon': 9.7, 'name': 'EDEKA', 'osm_value': 'supermarket'},
];
@override
Future<Map<String, Object?>> around(
PlacePoint at, {
required double radiusKm,
Set<String> tags = const {},
String? language,
required int limit,
}) async {
around_.add((tags: tags, language: language));
if (failing) {
throw const PhotonFailed('down');
}
return photonAnswer(tags.isEmpty ? address : neighbours);
}
}
Matcher _refused(String reason) =>
@ -179,6 +206,93 @@ void main() {
expect(places.first.name, 'EDEKA 0');
});
test('around a point: the address, and the places to go to', () async {
final nearby = await endpoints.search.nearby(
alice,
PlacePoint(lat: 47.5, lon: 9.7),
language: 'de',
);
expect(nearby.spot?.name, 'Danziger Weg 4');
expect(nearby.places.single.name, 'EDEKA');
expect(photon.around_.map((asked) => asked.language), ['de', 'de']);
expect(photon.around_.map((asked) => asked.tags.isEmpty), [true, false]);
});
test('around a point nothing is found, without failing', () async {
photon
..address = const []
..neighbours = const [];
final nearby = await endpoints.search.nearby(
alice,
PlacePoint(lat: 47.5, lon: 9.7),
);
expect(nearby.spot, isNull);
expect(nearby.places, isEmpty);
});
test('the places around a point are no more than a search lists', () async {
photon.neighbours = [
for (var i = 0; i < PlaceSearch.limit + 2; i++)
{'lat': 1, 'lon': 2, 'name': 'Shop $i', 'osm_value': 'bakery'},
];
final nearby = await endpoints.search.nearby(
alice,
PlacePoint(lat: 47.5, lon: 9.7),
);
expect(nearby.places, hasLength(PlaceSearch.limit));
});
test('tells nobody signed in what is around a point', () async {
await expectLater(
endpoints.search.nearby(
sessionBuilder.copyWith(
authentication: AuthenticationOverride.unauthenticated(),
),
PlacePoint(lat: 47.5, lon: 9.7),
),
throwsA(isA<ServerpodUnauthenticatedException>()),
);
expect(photon.around_, isEmpty);
});
test(
'refuses around a point off the earth, without asking Photon',
() async {
await expectLater(
endpoints.search.nearby(alice, PlacePoint(lat: 91, lon: 9.7)),
_refused('invalid'),
);
expect(photon.around_, isEmpty);
},
);
test('tells nothing around a point without a Photon', () async {
useSearch(PlaceSearch());
await expectLater(
endpoints.search.nearby(alice, PlacePoint(lat: 47.5, lon: 9.7)),
_refused('off'),
);
});
test("says Photon didn't answer around a point", () async {
photon.failing = true;
await expectLater(
endpoints.search.nearby(alice, PlacePoint(lat: 47.5, lon: 9.7)),
_refused('unreachable'),
);
});
test('a look around a point counts among the searches', () async {
for (var i = 0; i < PlaceSearch.perMinute; i++) {
await endpoints.search.nearby(alice, PlacePoint(lat: 47.5, lon: 9.7));
}
await expectLater(
endpoints.search.places(alice, 'Berlin'),
_refused('tooOften'),
);
});
test("says Photon didn't answer where it fails", () async {
photon.failing = true;
await expectLater(

View file

@ -15,6 +15,8 @@ import 'dart:async' as _ida;
import 'dart:io' as _idi;
import 'package:halkyon_todo_server/src/generated/future_calls.dart'
as _i772x17y;
import 'package:halkyon_todo_server/src/generated/search/nearby.dart'
as _isobfemy;
import 'package:halkyon_todo_server/src/generated/search/place.dart'
as _ih6de0l6;
import 'package:halkyon_todo_server/src/generated/search/place_point.dart'
@ -251,6 +253,41 @@ class _SearchEndpoint {
}
});
}
_ida.Future<_isobfemy.Nearby> nearby(
_ist.TestSessionBuilder sessionBuilder,
_iywv9say.PlacePoint at, {
String? language,
}) async {
return _ist.callAwaitableFunctionAndHandleExceptions(() async {
var _localUniqueSession =
(sessionBuilder as _ist.InternalTestSessionBuilder).internalBuild(
endpoint: 'search',
method: 'nearby',
);
try {
var _localCallContext = await _endpointDispatch.getMethodCallContext(
createSessionCallback: (_) => _localUniqueSession,
endpointPath: 'search',
methodName: 'nearby',
parameters: _ist.testObjectToJson({
'at': at,
'language': language,
}),
serializationManager: _serializationManager,
);
var _localReturnValue =
await (_localCallContext.method.call(
_localUniqueSession,
_localCallContext.arguments,
)
as _ida.Future<_isobfemy.Nearby>);
return _localReturnValue;
} finally {
await _localUniqueSession.close();
}
});
}
}
class _PruningFutureCall {

View file

@ -207,6 +207,51 @@ void main() {
expect([for (final place in places) place.osmValue], ['supermarket']);
});
test('the places around a point: each name once, what nobody goes to left '
'out', () {
final places = neighboursOf(
photonAnswer(const [
{'lat': 47.5, 'lon': 9.7, 'name': 'Volksbank', 'osm_value': 'bank'},
{'lat': 47.5, 'lon': 9.7, 'name': 'Volksbank', 'osm_value': 'bank'},
{'lat': 47.5, 'lon': 9.7, 'name': 'Volksbank', 'osm_value': 'atm'},
{'lat': 47.5, 'lon': 9.7, 'name': 'Bank', 'osm_value': 'bench'},
{'lat': 47.5, 'lon': 9.7, 'name': 'EDEKA', 'osm_value': 'parking'},
{'lat': 47.5, 'lon': 9.7, 'name': 'EDEKA', 'osm_value': 'supermarket'},
]),
);
expect(places.map((place) => (place.name, place.osmValue)), [
('Volksbank', 'bank'),
('EDEKA', 'supermarket'),
]);
});
test(
'HttpPhoton asks /reverse with the point, the radius and each tag',
() async {
final server = await HttpServer.bind(InternetAddress.loopbackIPv4, 0);
addTearDown(() => server.close(force: true));
Uri? asked;
server.listen((request) {
asked = request.uri;
request.response
..write(jsonEncode(photonAnswer(const [])))
..close();
});
await HttpPhoton(Uri.parse('http://127.0.0.1:${server.port}/')).around(
PlacePoint(lat: 47.5, lon: 9.7),
radiusKm: 0.5,
tags: const {'shop', 'amenity'},
language: 'de',
limit: 20,
);
expect(asked?.path, '/reverse');
expect(asked?.queryParameters['lat'], '47.5');
expect(asked?.queryParameters['radius'], '0.5');
expect(asked?.queryParameters['lang'], 'de');
expect(asked?.queryParametersAll['osm_tag'], ['shop', 'amenity']);
},
);
test('HttpPhoton asks /api with the query, the point, the language and '
'the limit, and fails on what is no answer', () async {
final server = await HttpServer.bind(InternetAddress.loopbackIPv4, 0);