Groups let people keep each other honest: create one or join with a six-letter invite code. Each group has shared goals split into measurable objectives (km, sessions, words) that every member logs toward, a leaderboard of kept rate and streak with nudges, and a group chat where check-ins and nudges appear as cards beside the talk. The open chat polls for new messages. Reached from a new Groups tab (Training moves into the day rail), a Home "Your groups" rail that opens the chat, and a Group tile in the add sheet. Mock mode seeds two groups, a joinable one and members who reply. The water tracker is removed; it did not fit the app. Bottom sheets are now square app-wide via the theme. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KhQh614DMeYoQEH9SoMRUw
78 lines
2.2 KiB
Dart
78 lines
2.2 KiB
Dart
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");
|
|
}
|
|
}
|
|
}
|