chore: updates to activity generator UI

pull/2245/head
ggurdin 4 months ago
parent c377cc8976
commit 44982e8b84
No known key found for this signature in database
GPG Key ID: A01CB41737CBB478

@ -4732,7 +4732,7 @@
"activityPlannerTitle": "Activity Planner", "activityPlannerTitle": "Activity Planner",
"topicLabel": "Topic", "topicLabel": "Topic",
"topicPlaceholder": "Choose a topic...", "topicPlaceholder": "Choose a topic...",
"modeLabel": "Mode", "modeLabel": "Activity type",
"modePlaceholder": "Choose a mode...", "modePlaceholder": "Choose a mode...",
"learningObjectiveLabel": "Learning Objective", "learningObjectiveLabel": "Learning Objective",
"learningObjectivePlaceholder": "Choose a learning objective...", "learningObjectivePlaceholder": "Choose a learning objective...",
@ -4873,7 +4873,7 @@
"exploreMore": "Explore more", "exploreMore": "Explore more",
"randomize": "Randomize", "randomize": "Randomize",
"clear": "Clear", "clear": "Clear",
"makeYourOwnActivity": "Make your own activity", "makeYourOwnActivity": "Create your own activity",
"featuredActivities": "Featured", "featuredActivities": "Featured",
"yourBookmarks": "Bookmarked", "yourBookmarks": "Bookmarked",
"goToChat": "Go to chat", "goToChat": "Go to chat",
@ -5031,5 +5031,6 @@
} }
}, },
"failedToFetchTranscription": "Failed to fetch transcription", "failedToFetchTranscription": "Failed to fetch transcription",
"deleteEmptySpaceDesc": "The space will be deleted for all participants. This action cannot be undone." "deleteEmptySpaceDesc": "The space will be deleted for all participants. This action cannot be undone.",
"regenerate": "Regenerate"
} }

@ -5362,7 +5362,6 @@
"activityPlannerTitle": "Planificador de Actividades", "activityPlannerTitle": "Planificador de Actividades",
"topicLabel": "Tema", "topicLabel": "Tema",
"topicPlaceholder": "Elige un tema...", "topicPlaceholder": "Elige un tema...",
"modeLabel": "Modo",
"modePlaceholder": "Elige un modo...", "modePlaceholder": "Elige un modo...",
"learningObjectiveLabel": "Objetivo de Aprendizaje", "learningObjectiveLabel": "Objetivo de Aprendizaje",
"learningObjectivePlaceholder": "Elige un objetivo de aprendizaje...", "learningObjectivePlaceholder": "Elige un objetivo de aprendizaje...",
@ -5494,7 +5493,6 @@
"exploreMore": "Explorar más", "exploreMore": "Explorar más",
"randomize": "Aleatorizar", "randomize": "Aleatorizar",
"clear": "Limpiar", "clear": "Limpiar",
"makeYourOwnActivity": "Crea tu propia actividad",
"featuredActivities": "Destacadas", "featuredActivities": "Destacadas",
"yourBookmarks": "Marcados", "yourBookmarks": "Marcados",
"goToChat": "Ir al chat", "goToChat": "Ir al chat",

@ -3551,7 +3551,6 @@
"activityPlannerTitle": "Trình lập hoạt động", "activityPlannerTitle": "Trình lập hoạt động",
"topicLabel": "Chủ đề", "topicLabel": "Chủ đề",
"topicPlaceholder": "Chọn một chủ đề...", "topicPlaceholder": "Chọn một chủ đề...",
"modeLabel": "Chế độ",
"modePlaceholder": "Chọn một chế độ...", "modePlaceholder": "Chọn một chế độ...",
"learningObjectiveLabel": "Mục tiêu học tập", "learningObjectiveLabel": "Mục tiêu học tập",
"learningObjectivePlaceholder": "Chọn một mục tiêu học tập...", "learningObjectivePlaceholder": "Chọn một mục tiêu học tập...",
@ -3834,7 +3833,6 @@
"exploreMore": "Khám phá thêm", "exploreMore": "Khám phá thêm",
"randomize": "Ngẫu nhiên hóa", "randomize": "Ngẫu nhiên hóa",
"clear": "Xóa", "clear": "Xóa",
"makeYourOwnActivity": "Tạo hoạt động của riêng bạn",
"featuredActivities": "Nổi bật", "featuredActivities": "Nổi bật",
"yourBookmarks": "Đã đánh dấu", "yourBookmarks": "Đã đánh dấu",
"goToChat": "Đi đến trò chuyện", "goToChat": "Đi đến trò chuyện",

@ -10,7 +10,6 @@ import 'package:fluffychat/pangea/activity_planner/activity_mode_list_repo.dart'
import 'package:fluffychat/pangea/activity_planner/activity_plan_generation_repo.dart'; import 'package:fluffychat/pangea/activity_planner/activity_plan_generation_repo.dart';
import 'package:fluffychat/pangea/activity_planner/activity_plan_model.dart'; import 'package:fluffychat/pangea/activity_planner/activity_plan_model.dart';
import 'package:fluffychat/pangea/activity_planner/activity_plan_request.dart'; import 'package:fluffychat/pangea/activity_planner/activity_plan_request.dart';
import 'package:fluffychat/pangea/activity_planner/activity_plan_response.dart';
import 'package:fluffychat/pangea/activity_planner/learning_objective_list_repo.dart'; import 'package:fluffychat/pangea/activity_planner/learning_objective_list_repo.dart';
import 'package:fluffychat/pangea/activity_planner/list_request_schema.dart'; import 'package:fluffychat/pangea/activity_planner/list_request_schema.dart';
import 'package:fluffychat/pangea/activity_planner/media_enum.dart'; import 'package:fluffychat/pangea/activity_planner/media_enum.dart';
@ -166,11 +165,6 @@ class ActivityGeneratorState extends State<ActivityGenerator> {
setState(() => selectedCefrLevel = value); setState(() => selectedCefrLevel = value);
} }
void setSelectedMedia(MediaEnum? value) {
if (value == null) return;
setState(() => selectedMedia = value);
}
Future<ActivitySettingResponseSchema?> get _selectedMode async { Future<ActivitySettingResponseSchema?> get _selectedMode async {
final modes = await modeItems; final modes = await modeItems;
return modes.firstWhereOrNull( return modes.firstWhereOrNull(
@ -203,30 +197,18 @@ class ActivityGeneratorState extends State<ActivityGenerator> {
}); });
} }
Future<void> onEdit(int index, ActivityPlanModel updatedActivity) async { Future<void> generate({bool force = false}) async {
// in this case we're editing an activity plan that was generated recently
// via the repo and should be updated in the cached response
if (activities != null) {
activities?[index] = updatedActivity;
ActivityPlanGenerationRepo.set(
planRequest,
ActivityPlanResponse(activityPlans: activities!),
);
}
setState(() {});
}
void update() => setState(() {});
Future<void> generate() async {
setState(() { setState(() {
loading = true; loading = true;
error = null; error = null;
activities = null;
}); });
try { try {
final resp = await ActivityPlanGenerationRepo.get(planRequest); final resp = await ActivityPlanGenerationRepo.get(
planRequest,
force: force,
);
activities = resp.activityPlans; activities = resp.activityPlans;
await _setModeImageURL(); await _setModeImageURL();
} catch (e, s) { } catch (e, s) {

@ -61,6 +61,7 @@ class ActivityGeneratorView extends StatelessWidget {
room: controller.room, room: controller.room,
builder: (c) { builder: (c) {
return ActivityPlanCard( return ActivityPlanCard(
regenerate: () => controller.generate(force: true),
controller: c, controller: c,
); );
}, },

@ -20,10 +20,12 @@ import 'package:fluffychat/pangea/learning_settings/enums/language_level_type_en
import 'package:fluffychat/widgets/future_loading_dialog.dart'; import 'package:fluffychat/widgets/future_loading_dialog.dart';
class ActivityPlanCard extends StatefulWidget { class ActivityPlanCard extends StatefulWidget {
final VoidCallback regenerate;
final ActivityPlannerBuilderState controller; final ActivityPlannerBuilderState controller;
const ActivityPlanCard({ const ActivityPlanCard({
super.key, super.key,
required this.regenerate,
required this.controller, required this.controller,
}); });
@ -121,8 +123,11 @@ class ActivityPlanCardState extends State<ActivityPlanCard> {
AnimatedSize( AnimatedSize(
duration: FluffyThemes.animationDuration, duration: FluffyThemes.animationDuration,
child: Stack( child: Stack(
alignment: Alignment.bottomCenter,
children: [ children: [
Container( Container(
width: 200.0,
padding: const EdgeInsets.all(16.0),
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12.0), borderRadius: BorderRadius.circular(12.0),
), ),
@ -131,6 +136,7 @@ class ActivityPlanCardState extends State<ActivityPlanCard> {
child: widget.controller.imageURL != null || child: widget.controller.imageURL != null ||
widget.controller.avatar != null widget.controller.avatar != null
? ClipRRect( ? ClipRRect(
borderRadius: BorderRadius.circular(20.0),
child: widget.controller.avatar == null child: widget.controller.avatar == null
? CachedNetworkImage( ? CachedNetworkImage(
fit: BoxFit.cover, fit: BoxFit.cover,
@ -156,14 +162,17 @@ class ActivityPlanCardState extends State<ActivityPlanCard> {
), ),
), ),
if (widget.controller.isEditing) if (widget.controller.isEditing)
Positioned( InkWell(
top: 10.0, borderRadius: BorderRadius.circular(90),
right: 10.0, onTap: widget.controller.selectAvatar,
child: IconButton( child: CircleAvatar(
icon: const Icon(Icons.upload_outlined), backgroundColor:
onPressed: widget.controller.selectAvatar, Theme.of(context).colorScheme.secondary,
style: IconButton.styleFrom( radius: 16.0,
backgroundColor: Colors.black, child: Icon(
Icons.add_a_photo_outlined,
size: 16.0,
color: Theme.of(context).colorScheme.onSecondary,
), ),
), ),
), ),
@ -368,44 +377,105 @@ class ActivityPlanCardState extends State<ActivityPlanCard> {
), ),
], ],
const SizedBox(height: itemPadding), const SizedBox(height: itemPadding),
Row( widget.controller.isEditing
mainAxisAlignment: MainAxisAlignment.spaceBetween, ? Row(
spacing: 12.0,
children: [ children: [
Row( Expanded(
child: ElevatedButton(
onPressed: widget.controller.saveEdits,
child: Row(
children: [ children: [
Tooltip( const Icon(Icons.save),
message: !widget.controller.isEditing Expanded(
? l10n.edit child: Text(
: l10n.saveChanges, L10n.of(context).save,
child: IconButton( textAlign: TextAlign.center,
icon: Icon( ),
!widget.controller.isEditing
? Icons.edit
: Icons.save,
), ),
onPressed: () => !widget.controller.isEditing ],
? setState(() {
widget.controller.isEditing = true;
})
: widget.controller.saveEdits(),
isSelected: widget.controller.isEditing,
), ),
), ),
if (widget.controller.isEditing) ),
Tooltip( Expanded(
message: l10n.cancel, child: ElevatedButton(
child: IconButton(
icon: const Icon(Icons.cancel),
onPressed: widget.controller.clearEdits, onPressed: widget.controller.clearEdits,
child: Row(
children: [
const Icon(Icons.cancel),
Expanded(
child: Text(
L10n.of(context).cancel,
textAlign: TextAlign.center,
),
),
],
),
),
),
],
)
: Column(
spacing: 12.0,
children: [
Row(
spacing: 12.0,
children: [
Expanded(
child: ElevatedButton(
child: Row(
children: [
const Icon(Icons.edit),
Expanded(
child: Text(
L10n.of(context).edit,
textAlign: TextAlign.center,
),
),
],
),
onPressed: () =>
widget.controller.setEditing(true),
),
),
Expanded(
child: ElevatedButton(
onPressed: widget.regenerate,
child: Row(
children: [
const Icon(Icons.lightbulb_outline),
Expanded(
child: Text(
L10n.of(context).regenerate,
textAlign: TextAlign.center,
),
),
],
),
),
),
],
),
Row(
children: [
Expanded(
child: ElevatedButton(
onPressed: _onLaunch,
child: Row(
children: [
const Icon(Icons.send),
Expanded(
child: Text(
L10n.of(context)
.launchActivityButton,
textAlign: TextAlign.center,
), ),
), ),
], ],
), ),
ElevatedButton.icon( ),
onPressed: ),
!widget.controller.isEditing ? _onLaunch : null, ],
icon: const Icon(Icons.send),
label: Text(l10n.launchActivityButton),
), ),
], ],
), ),

@ -18,9 +18,12 @@ class ActivityPlanGenerationRepo {
_activityPlanStorage.write(request.storageKey, response.toJson()); _activityPlanStorage.write(request.storageKey, response.toJson());
} }
static Future<ActivityPlanResponse> get(ActivityPlanRequest request) async { static Future<ActivityPlanResponse> get(
ActivityPlanRequest request, {
bool force = false,
}) async {
final cachedJson = _activityPlanStorage.read(request.storageKey); final cachedJson = _activityPlanStorage.read(request.storageKey);
if (cachedJson != null) { if (cachedJson != null && !force) {
final cached = ActivityPlanResponse.fromJson(cachedJson); final cached = ActivityPlanResponse.fromJson(cachedJson);
return cached; return cached;

@ -7,6 +7,7 @@ import 'package:http/http.dart';
import 'package:matrix/matrix.dart'; import 'package:matrix/matrix.dart';
import 'package:fluffychat/pangea/activity_planner/activity_plan_model.dart'; import 'package:fluffychat/pangea/activity_planner/activity_plan_model.dart';
import 'package:fluffychat/pangea/activity_planner/bookmarked_activities_repo.dart';
import 'package:fluffychat/pangea/common/utils/error_handler.dart'; import 'package:fluffychat/pangea/common/utils/error_handler.dart';
import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart'; import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
import 'package:fluffychat/pangea/learning_settings/enums/language_level_type_enum.dart'; import 'package:fluffychat/pangea/learning_settings/enums/language_level_type_enum.dart';
@ -21,18 +22,12 @@ class ActivityPlannerBuilder extends StatefulWidget {
final Widget Function(ActivityPlannerBuilderState) builder; final Widget Function(ActivityPlannerBuilderState) builder;
final Future<void> Function(
String,
ActivityPlanModel,
)? onEdit;
const ActivityPlannerBuilder({ const ActivityPlannerBuilder({
super.key, super.key,
required this.initialActivity, required this.initialActivity,
this.initialFilename, this.initialFilename,
this.room, this.room,
required this.builder, required this.builder,
this.onEdit,
}); });
@override @override
@ -206,12 +201,10 @@ class ActivityPlannerBuilderState extends State<ActivityPlannerBuilder> {
if (!formKey.currentState!.validate()) return; if (!formKey.currentState!.validate()) return;
await updateImageURL(); await updateImageURL();
setEditing(false); setEditing(false);
if (widget.onEdit != null) {
await widget.onEdit!( await BookmarkedActivitiesRepo.remove(widget.initialActivity.bookmarkId);
widget.initialActivity.bookmarkId, await BookmarkedActivitiesRepo.save(updatedActivity);
updatedActivity, if (mounted) setState(() {});
);
}
} }
Future<void> clearEdits() async { Future<void> clearEdits() async {

@ -36,15 +36,6 @@ class BookmarkedActivitiesListState extends State<BookmarkedActivitiesList> {
double get cardHeight => _isColumnMode ? 325.0 : 250.0; double get cardHeight => _isColumnMode ? 325.0 : 250.0;
double get cardWidth => _isColumnMode ? 225.0 : 150.0; double get cardWidth => _isColumnMode ? 225.0 : 150.0;
Future<void> _onEdit(
String activityId,
ActivityPlanModel activity,
) async {
await BookmarkedActivitiesRepo.remove(activityId);
await BookmarkedActivitiesRepo.save(activity);
if (mounted) setState(() {});
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final l10n = L10n.of(context); final l10n = L10n.of(context);
@ -77,7 +68,6 @@ class BookmarkedActivitiesListState extends State<BookmarkedActivitiesList> {
builder: (context) { builder: (context) {
return ActivityPlannerBuilder( return ActivityPlannerBuilder(
initialActivity: activity, initialActivity: activity,
onEdit: _onEdit,
room: widget.room, room: widget.room,
builder: (controller) { builder: (controller) {
return ActivitySuggestionDialog( return ActivitySuggestionDialog(

Loading…
Cancel
Save