Skip to content

Commit

Permalink
refactor: remove old code
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasn committed Mar 4, 2025
1 parent c182cc1 commit 346fe32
Showing 1 changed file with 2 additions and 90 deletions.
92 changes: 2 additions & 90 deletions lib/features/ai/ui/ai_response_summary.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:gpt_markdown/gpt_markdown.dart';
import 'package:lotti/classes/checklist_item_data.dart';
import 'package:lotti/classes/journal_entities.dart';
import 'package:lotti/features/tasks/repository/checklist_repository.dart';
import 'package:lotti/features/tasks/ui/checklists/checklist_item_widget.dart';
import 'package:lotti/utils/modals.dart';

class AiResponseSummary extends StatelessWidget {
Expand Down Expand Up @@ -139,16 +135,8 @@ class AiResponseSummaryModalContent extends StatelessWidget {
SingleChildScrollView(
child: Padding(
padding: padding,
child: Column(
children: [
SelectionArea(
child: GptMarkdown(aiResponse.data.response),
),
NewChecklistItemWidget(
response: aiResponse.data.response,
linkedFromId: linkedFromId,
),
],
child: SelectionArea(
child: GptMarkdown(aiResponse.data.response),
),
),
),
Expand All @@ -159,79 +147,3 @@ class AiResponseSummaryModalContent extends StatelessWidget {
);
}
}

class NewChecklistItemWidget extends ConsumerStatefulWidget {
const NewChecklistItemWidget({
required this.response,
required this.linkedFromId,
super.key,
});

final String response;
final String? linkedFromId;

@override
ConsumerState<NewChecklistItemWidget> createState() =>
_NewChecklistItemWidgetState();
}

class _NewChecklistItemWidgetState
extends ConsumerState<NewChecklistItemWidget> {
final _selected = <ChecklistItemData>{};

@override
Widget build(BuildContext context) {
final exp = RegExp(
r'TODO:\s(.+)',
multiLine: true,
);

final checklistItems = exp
.allMatches(widget.response)
.map((e) {
final title = e.group(1);
if (title != null) {
return ChecklistItemData(
title: title,
isChecked: false,
linkedChecklists: [],
);
}
})
.nonNulls
.toList();

return Column(
children: [
const Text('Select the items that are relevant to you:'),
...checklistItems.map(
(checklistItem) => ChecklistItemWidget(
title: checklistItem.title,
isChecked: checklistItem.isChecked,
onChanged: (checked) {
if (checked) {
_selected.add(checklistItem);
} else {
_selected.remove(checklistItem);
}
},
),
),
TextButton(
onPressed: () {
ref.read(checklistRepositoryProvider).createChecklist(
taskId: widget.linkedFromId,
title: 'AI generated checklist',
items: checklistItems.where(_selected.contains).toList(),
);

if (context.mounted) {
Navigator.of(context).pop();
}
},
child: const Text('Create checklist'),
),
],
);
}
}

0 comments on commit 346fe32

Please sign in to comment.