3
0
Fork 0

Refresh Sites when a site is saved (closes #89) (#93)

* Refresh Sites when a site is saved (closes #89)

* Update with iOS side fix
This commit is contained in:
John Maguire 2022-11-18 16:03:52 -05:00 committed by GitHub
parent 6108bf801b
commit 974c7a4eed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 4 deletions

View File

@ -210,7 +210,6 @@ class MainActivity: FlutterActivity() {
val gson = Gson()
site = gson.fromJson(call.arguments as String, IncomingSite::class.java)
siteDir = site.save(context)
} catch (err: Exception) {
//TODO: is toString the best or .message?
return result.error("failure", err.toString(), null)
@ -220,6 +219,8 @@ class MainActivity: FlutterActivity() {
return result.error("failure", "Site config was incomplete, please review and try again", null)
}
sites?.refreshSites()
result.success(null)
}

View File

@ -184,9 +184,11 @@ func MissingArgumentError(message: String, details: Any?) -> FlutterError {
return result(CallFailedError(message: "Failed to save site", details: error!.localizedDescription))
}
self.sites?.loadSites { _, _ in
result(nil)
}
}
}
func startSite(call: FlutterMethodCall, result: @escaping FlutterResult) {
guard let args = call.arguments as? Dictionary<String, String> else { return result(NoArgumentsError()) }

View File

@ -26,8 +26,13 @@ class Sites {
}
sites?.values.forEach{ site in
let updater = SiteUpdater(messenger: self.messenger!, site: site)
self.containers[site.id] = SiteContainer(site: site, updater: updater)
var updater = self.containers[site.id]?.updater
if (updater != nil) {
updater!.setSite(site: site)
} else {
updater = SiteUpdater(messenger: self.messenger!, site: site)
}
self.containers[site.id] = SiteContainer(site: site, updater: updater!)
}
let justSites = self.containers.mapValues {
@ -113,6 +118,10 @@ class SiteUpdater: NSObject, FlutterStreamHandler {
self.configObserver?.resume()
}
func setSite(site: Site) {
self.site = site
}
/// onListen is called when flutter code attaches an event listener
func onListen(withArguments arguments: Any?, eventSink events: @escaping FlutterEventSink) -> FlutterError? {
eventSink = events;

View File

@ -230,6 +230,7 @@ class _SiteDetailScreenState extends State<SiteDetailScreen> {
site: widget.site,
onSave: (site) async {
changed = true;
setState(() {});
});
});
},