Skip to content

Commit

Permalink
fix: make planner a separate route, make tokens nullable instead of l…
Browse files Browse the repository at this point in the history
…ate, and disable randomization buttom while options are loading (#1556)
  • Loading branch information
ggurdin authored Jan 23, 2025
1 parent b15ed04 commit 62d5197
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
12 changes: 12 additions & 0 deletions lib/config/routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import 'package:fluffychat/pages/settings_notifications/settings_notifications.d
import 'package:fluffychat/pages/settings_password/settings_password.dart';
import 'package:fluffychat/pages/settings_security/settings_security.dart';
import 'package:fluffychat/pages/settings_style/settings_style.dart';
import 'package:fluffychat/pangea/activity_planner/activity_planner_page.dart';
import 'package:fluffychat/pangea/guard/p_vguard.dart';
import 'package:fluffychat/pangea/login/pages/login_or_signup_view.dart';
import 'package:fluffychat/pangea/login/pages/signup.dart';
Expand Down Expand Up @@ -483,6 +484,17 @@ abstract class AppRoutes {
redirect: loggedOutRedirect,
),
// #Pangea
GoRoute(
path: 'planner',
pageBuilder: (context, state) => defaultPageBuilder(
context,
state,
ActivityPlannerPage(
roomID: state.pathParameters['roomid']!,
),
),
redirect: loggedOutRedirect,
),
// GoRoute(
// path: 'encryption',
// pageBuilder: (context, state) => defaultPageBuilder(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'package:flutter/material.dart';

import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:go_router/go_router.dart';

import 'package:fluffychat/pages/chat/chat.dart';
import 'package:fluffychat/pangea/activity_planner/activity_planner_page.dart';

class ActivityPlanPageLaunchIconButton extends StatelessWidget {
const ActivityPlanPageLaunchIconButton({
Expand All @@ -18,13 +18,7 @@ class ActivityPlanPageLaunchIconButton extends StatelessWidget {
return IconButton(
icon: const Icon(Icons.event_note_outlined),
tooltip: L10n.of(context).activityPlannerTitle,
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => ActivityPlannerPage(room: controller.room),
),
);
},
onPressed: () => context.go('/rooms/${controller.room.id}/planner'),
);
}
}
29 changes: 22 additions & 7 deletions lib/pangea/activity_planner/activity_planner_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ enum _PageMode {
}

class ActivityPlannerPage extends StatefulWidget {
final Room room;
const ActivityPlannerPage({super.key, required this.room});
final String roomID;
const ActivityPlannerPage({super.key, required this.roomID});

@override
ActivityPlannerPageState createState() => ActivityPlannerPageState();
Expand Down Expand Up @@ -92,10 +92,16 @@ class ActivityPlannerPageState extends State<ActivityPlannerPage> {
final _objectiveSearchController = TextEditingController();

final List<TextEditingController> _activityControllers = [];
Room? get room => Matrix.of(context).client.getRoomById(widget.roomID);

@override
void initState() {
super.initState();
if (room == null) {
Navigator.of(context).pop();
return;
}

_loadDropdownData();

_selectedLanguageOfInstructions =
Expand Down Expand Up @@ -147,7 +153,7 @@ class ActivityPlannerPageState extends State<ActivityPlannerPage> {
context: context,
future: () async {
// this shouldn't often error but just in case since it's not necessary for the activity to be sent
late List<PangeaToken> tokens;
List<PangeaToken>? tokens;
try {
tokens = await MatrixState.pangeaController.messageData.getTokens(
repEventId: null,
Expand All @@ -163,7 +169,7 @@ class ActivityPlannerPageState extends State<ActivityPlannerPage> {
debugger(when: kDebugMode);
}

final eventId = await widget.room.pangeaSendTextEvent(
final eventId = await room?.pangeaSendTextEvent(
_activities[index],
messageTag: ModelKey.messageTagActivityPlan,
originalSent: PangeaRepresentation(
Expand All @@ -172,15 +178,16 @@ class ActivityPlannerPageState extends State<ActivityPlannerPage> {
originalSent: true,
originalWritten: false,
),
tokensSent: PangeaMessageTokens(tokens: tokens),
tokensSent:
tokens != null ? PangeaMessageTokens(tokens: tokens) : null,
);

if (eventId == null) {
debugger(when: kDebugMode);
return;
}

await widget.room.setPinnedEvents([eventId]);
await room?.setPinnedEvents([eventId]);

Navigator.of(context).pop();
},
Expand Down Expand Up @@ -215,7 +222,14 @@ class ActivityPlannerPageState extends State<ActivityPlannerPage> {
}
}

bool get _canRandomizeSelections =>
_topicItems.isNotEmpty &&
_objectiveItems.isNotEmpty &&
_modeItems.isNotEmpty;

void _randomizeSelections() {
if (!_canRandomizeSelections) return;

setState(() {
_selectedTopic = (_topicItems..shuffle()).first.name;
_selectedObjective = (_objectiveItems..shuffle()).first.name;
Expand Down Expand Up @@ -391,7 +405,8 @@ class ActivityPlannerPageState extends State<ActivityPlannerPage> {
children: [
IconButton(
icon: const Icon(Icons.shuffle),
onPressed: _randomizeSelections,
onPressed:
_canRandomizeSelections ? _randomizeSelections : null,
),
const SizedBox(width: 16),
Expanded(
Expand Down

0 comments on commit 62d5197

Please sign in to comment.