import '../../about/external/data/Group.dart'; import '../../about/external/initial/IdRequest.dart'; import '../../about/external/initial/NudgeRequest.dart'; import '../../about/external/initial/ObjectiveProgressRequest.dart'; import '../parent/ParentViewModel.dart'; import 'ConnectGroupDetail.dart'; class ViewGroupDetail extends ParentViewModel { ConnectGroupDetail connection; ViewGroupDetail(super.context, this.connection); /// [quiet] refreshes behind the screen without the loading overlay, for /// coming back from the chat or the goal editor. void loadGroup(String groupId, {bool quiet = false}) async { if (!await hasNetwork(() => loadGroup(groupId, quiet: quiet))) return; if (!quiet) showLoading("Loading the group"); try { final response = await getDataManager().getGroupEntry(IdRequest(id: groupId)); if (!quiet) closeLoading(); connection.onGroupLoaded(Group.fromJson(response.data)); } catch (e) { handleError(e, () => loadGroup(groupId, quiet: quiet), () => dismissError(), "Retry"); } } void logProgress(ObjectiveProgressRequest request, String summary) async { if (!await hasNetwork(() => logProgress(request, summary))) return; showLoading("Logging"); try { final response = await getDataManager().logObjectiveProgress(request); closeLoading(); connection.onProgressLogged(Group.fromJson(response.data), summary); } catch (e) { handleError(e, () => logProgress(request, summary), () => dismissError(), "Retry"); } } void nudge(NudgeRequest request, String who) async { if (!await hasNetwork(() => nudge(request, who))) return; try { await getDataManager().nudgeGroupMember(request); connection.onNudged(who); } catch (e) { handleError(e, () => nudge(request, who), () => dismissError(), "Retry"); } } void leave(String groupId) async { if (!await hasNetwork(() => leave(groupId))) return; showLoading("Leaving"); try { await getDataManager().leaveGroupEntry(IdRequest(id: groupId)); closeLoading(); connection.onLeft(); } catch (e) { handleError(e, () => leave(groupId), () => dismissError(), "Retry"); } } }