Skip to content

Commit

Permalink
fix: added AED is now displayed
Browse files Browse the repository at this point in the history
  • Loading branch information
matisiekpl committed Jan 15, 2025
1 parent f81f157 commit a5476ef
Show file tree
Hide file tree
Showing 4 changed files with 220 additions and 210 deletions.
16 changes: 8 additions & 8 deletions lib/bloc/points/points_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,18 @@ class PointsCubit extends Cubit<PointsState> {
update(AED aed) {
if (state is PointsLoadSuccess) {
if (aed.id == 0) {
var newAeds = List<AED>.from((state as PointsLoadSuccess).aeds)
..add(aed);
var newDefibrillators = List<AED>.from((state as PointsLoadSuccess).aeds)
..insert(0, aed);
emit((state as PointsLoadSuccess).copyWith(
aeds: newAeds, markers: _getMarkers(newAeds), selected: aed));
aeds: newDefibrillators, markers: _getMarkers(newDefibrillators), selected: aed));
} else {
var updatedAeds = List<AED>.from((state as PointsLoadSuccess).aeds)
.map((e) => e.id == aed.id ? aed : e)
.toList();
var updatedDefibrillators = List<AED>.from((state as PointsLoadSuccess).aeds)
..removeWhere((x) => x.id == aed.id)
..insert(0, aed);
emit((state as PointsLoadSuccess).copyWith(
selected: aed,
aeds: updatedAeds,
markers: _getMarkers(updatedAeds)));
aeds: updatedDefibrillators,
markers: _getMarkers(updatedDefibrillators)));
}
}
}
Expand Down
30 changes: 16 additions & 14 deletions lib/repositories/points_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,20 @@ class PointsRepository {
Future<AED> insertDefibrillator(AED aed) async {
try {
var changesetId = await getChangesetId();
var response = await http.put(
Uri.parse('https://api.openstreetmap.org/api/0.6/node/create'),
headers: {
'Content-Type': 'text/xml',
'Authorization': 'Bearer $token'
},
body: aed.toXml(changesetId, 1));
var id = int.parse(response.body.toString());
aed.id = id;
if (kDebugMode) {
print('https://www.openstreetmap.org/node/$id');
if (!kDebugMode) {
var response = await http.put(
Uri.parse('https://api.openstreetmap.org/api/0.6/node/create'),
headers: {
'Content-Type': 'text/xml',
'Authorization': 'Bearer $token'
},
body: aed.toXml(changesetId, 1));
var id = int.parse(response.body.toString());
aed.id = id;
} else {
aed.id = 9999;
}
if (kDebugMode) {}
updateAEDs();
} catch (err) {
if (kDebugMode) {
Expand All @@ -161,6 +163,9 @@ class PointsRepository {
}

Future<AED> updateDefibrillator(AED aed) async {
if (kDebugMode) {
return aed;
}
try {
var changesetId = await getChangesetId();
var fetchResponse = await http.get(
Expand Down Expand Up @@ -199,9 +204,6 @@ class PointsRepository {
'Authorization': 'Bearer $token'
},
body: xml);
if (kDebugMode) {
print('https://www.openstreetmap.org/node/${aed.id}');
}
updateAEDs();
} catch (err) {
if (kDebugMode) {
Expand Down
Loading

0 comments on commit a5476ef

Please sign in to comment.