More redux work

This commit is contained in:
vjrj 2018-06-27 22:29:54 +02:00
parent 69428c5d96
commit 5d947f9577
14 changed files with 170 additions and 88 deletions

View file

@ -1,9 +1,12 @@
import 'package:bson_objectid/bson_objectid.dart';
import 'package:comunes_flutter/comunes_flutter.dart';
import 'package:fires_flutter/models/yourLocation.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:meta/meta.dart';
import 'package:comunes_flutter/comunes_flutter.dart';
import 'fireMapState.dart';
import 'yourLocation.dart';
import 'user.dart';
part 'appState.g.dart';
@immutable
@ -32,8 +35,8 @@ class AppState extends Object with _$AppStateSerializerMixin {
_$AppStateFromJson(json);
AppState(
{this.yourLocations : const <YourLocation>[],
this.user: const User.initial(),
{this.yourLocations: const <YourLocation>[],
this.user: const User.initial(),
this.isLoading: false,
this.isLoaded: false,
this.error: null,
@ -66,6 +69,16 @@ class AppState extends Object with _$AppStateSerializerMixin {
@override
String toString() {
return 'AppState{\nuser: ${user}\nisLoading: $isLoading\nisLoaded: $isLoaded\napiKey: ${ellipse(firesApiKey, 8)}\napiUrl: ${ellipse(firesApiUrl, 8)}\nyourLocations: ${yourLocations}';
return 'AppState{\nuser: ${user}\nisLoading: $isLoading\nisLoaded: $isLoaded\napiKey: ${ellipse(
firesApiKey, 8)}\napiUrl: ${ellipse(
firesApiUrl, 8)}\nyourLocations count: ${yourLocations
.length}\nyourLocations: ${yourLocations}';
}
}
typedef void AddYourLocationFunction(YourLocation loc);
typedef void DeleteYourLocationFunction(ObjectId id);
typedef void UpdateYourLocationFunction(ObjectId id, YourLocation loc);
typedef void ToggleSubscriptionFunction(ObjectId id);
typedef void SubscribeFunction(ObjectId id);
typedef void UnSubscribeFunction(ObjectId id);

View file

@ -4,8 +4,10 @@ import 'dart:convert';
import 'package:http/http.dart' as ht;
import 'package:jaguar_resty/jaguar_resty.dart' as resty;
import 'package:fires_flutter/models/yourLocation.dart';
import 'appState.dart';
import 'yourLocation.dart';
class FiresApi {
FiresApi() {

View file

@ -37,6 +37,8 @@ class YourLocation extends Object with _$YourLocationSerializerMixin {
if (this.id == null) this.id = new ObjectId();
}
@override
bool operator ==(Object other) =>
identical(this, other) ||
@ -55,4 +57,10 @@ class YourLocation extends Object with _$YourLocationSerializerMixin {
lon.hashCode ^
description.hashCode ^
subscribed.hashCode;
@override
String toString() {
return 'YourLocation {id: $id, lat: $lat, lon: $lon, description: $description, subscribed: $subscribed}';
}
}

View file

@ -1,11 +1,12 @@
import 'dart:convert';
import '../globals.dart' as globals;
import 'dart:async';
import 'yourLocation.dart';
import 'dart:convert';
import 'package:fires_flutter/models/yourLocation.dart';
import 'package:shared_preferences/shared_preferences.dart';
final String locationKey = 'yourlocations';
import '../globals.dart' as globals;
final String locationKey = 'yourlocations';
Future<List<YourLocation>> loadYourLocations() async {
return await globals.prefs.then((prefs) {
@ -23,7 +24,8 @@ persistYourLocations(List<YourLocation> yl) {
});
}
Future<List<YourLocation>> loadYourLocationsWithPrefs(SharedPreferences prefs) async {
Future<List<YourLocation>> loadYourLocationsWithPrefs(
SharedPreferences prefs) async {
return await globals.prefs.then((prefs) {
List<String> yourLocations = prefs.getStringList(locationKey);
if (yourLocations == null) {
@ -33,9 +35,8 @@ Future<List<YourLocation>> loadYourLocationsWithPrefs(SharedPreferences prefs) a
List<YourLocation> persistedList = List<YourLocation>();
yourLocations.forEach((locationString) {
Map locationMap = json.decode(locationString);
persistedList.add(YourLocation.fromJson(locationMap));
persistedList.add(YourLocation.fromJson(locationMap));
});
return persistedList;
});
}