Skip to content

Commit

Permalink
Merge pull request #2046 from bitfriend/activate-integration-test
Browse files Browse the repository at this point in the history
Replace tasks list providers with id-based providing
  • Loading branch information
bitfriend authored Aug 13, 2024
2 parents e6dbde6 + 5ae0510 commit e479f21
Show file tree
Hide file tree
Showing 17 changed files with 152 additions and 150 deletions.
10 changes: 2 additions & 8 deletions app/lib/common/actions/redact_content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:acter/common/providers/space_providers.dart';
import 'package:acter/common/toolkit/buttons/primary_action_button.dart';
import 'package:acter/common/widgets/default_dialog.dart';
import 'package:acter/common/widgets/input_text_field.dart';
import 'package:acter/features/events/providers/event_providers.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
Expand Down Expand Up @@ -118,19 +117,14 @@ class _RedactContentWidget extends ConsumerWidget {
if (isSpace) {
final space = await ref.read(spaceProvider(roomId).future);
final redactedId = await space.redactContent(eventId, reason);
_log.info(
'Content from $redactedId reason:$reason}',
);
_log.info('Content from $redactedId reason:$reason}');
} else {
final room = await ref.read(chatProvider(roomId).future);
if (room == null) {
throw RoomNotFound();
}
final redactedId = await room.redactContent(eventId, reason);
ref.invalidate(allEventListProvider(roomId));
_log.info(
'Content from $redactedId reason:$reason}',
);
_log.info('Content from $redactedId reason:$reason}');
}

if (!context.mounted) {
Expand Down
4 changes: 0 additions & 4 deletions app/lib/features/events/widgets/change_date_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,6 @@ class _ChangeDateSheetState extends ConsumerState<ChangeDateSheet> {

EasyLoading.dismiss();

ref.invalidate(calendarEventProvider(eventId.toString())); // edit page
final spaceId = calendarEvent.roomIdStr();
ref.invalidate(allEventListProvider(spaceId)); // events page in space

if (mounted) Navigator.pop(context);
} catch (e, st) {
_log.severe('Failed to update calendar event', e, st);
Expand Down
21 changes: 10 additions & 11 deletions app/lib/features/home/widgets/my_tasks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,34 @@ class MyTasksSection extends ConsumerWidget {
data: (tasks) => tasks.isEmpty
? const SizedBox.shrink()
: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
myTaskHeader(context),
ListView.separated(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
myTaskHeader(context),
ListView.separated(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
separatorBuilder: (context, index) =>
const Divider(color: Colors.white24, indent: 30),
itemCount: tasks.length,
itemBuilder: (context, index) {
return TaskItem(
task: tasks[index],
taskListId: tasks[index].taskListIdStr(),
taskId: tasks[index].eventIdStr(),
showBreadCrumb: true,
onDone: () => EasyLoading.showToast(
L10n.of(context).markedAsDone,
),
);
},
),
],
),
error: (error, stack) =>
Text(L10n.of(context).loadingTasksFailed(error)),
],
),
error: (error, stack) => Text(L10n.of(context).loadingTasksFailed(error)),
loading: () => Text(L10n.of(context).loading),
);
}

Widget myTaskHeader(BuildContext context){
Widget myTaskHeader(BuildContext context) {
return Row(
children: [
Text(
Expand All @@ -62,5 +62,4 @@ class MyTasksSection extends ConsumerWidget {
],
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import 'package:acter/common/utils/routes.dart';
import 'package:acter/features/space/widgets/space_sections/section_header.dart';
import 'package:acter/features/tasks/providers/tasklists_providers.dart';
import 'package:acter/features/tasks/widgets/task_list_item_card.dart';
import 'package:acter_flutter_sdk/acter_flutter_sdk_ffi.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';

class TasksSection extends ConsumerWidget {
Expand All @@ -31,7 +30,7 @@ class TasksSection extends ConsumerWidget {
);
}

Widget buildTasksSectionUI(BuildContext context, List<TaskList> tasks) {
Widget buildTasksSectionUI(BuildContext context, List<String> tasks) {
int taskLimit = (tasks.length > limit) ? limit : tasks.length;
bool isShowSeeAllButton = tasks.length > taskLimit;
return Column(
Expand All @@ -51,15 +50,15 @@ class TasksSection extends ConsumerWidget {
);
}

Widget taskListUI(List<TaskList> tasks, int taskLimit) {
Widget taskListUI(List<String> tasks, int taskLimit) {
return ListView.builder(
shrinkWrap: true,
itemCount: taskLimit,
padding: EdgeInsets.zero,
physics: const NeverScrollableScrollPhysics(),
itemBuilder: (context, index) {
return TaskListItemCard(
taskList: tasks[index],
taskListId: tasks[index],
initiallyExpanded: false,
);
},
Expand Down
11 changes: 7 additions & 4 deletions app/lib/features/tasks/models/tasks.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import 'package:acter_flutter_sdk/acter_flutter_sdk_ffi.dart';
import 'package:flutter/material.dart';

@immutable
class TasksOverview {
final List<Task> openTasks;
final List<Task> doneTasks;
const TasksOverview({required this.openTasks, required this.doneTasks});
final List<String> openTasks;
final List<String> doneTasks;

const TasksOverview({
required this.openTasks,
required this.doneTasks,
});
}
15 changes: 8 additions & 7 deletions app/lib/features/tasks/pages/tasks_list_page.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:math';

import 'package:acter/common/providers/space_providers.dart';
import 'package:acter/common/toolkit/buttons/primary_action_button.dart';
import 'package:acter/common/widgets/acter_search_widget.dart';
Expand All @@ -9,7 +10,6 @@ import 'package:acter/features/tasks/providers/tasklists_providers.dart';
import 'package:acter/features/tasks/sheets/create_update_task_list.dart';
import 'package:acter/features/tasks/widgets/skeleton/tasks_list_skeleton.dart';
import 'package:acter/features/tasks/widgets/task_list_item_card.dart';
import 'package:acter_flutter_sdk/acter_flutter_sdk_ffi.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
Expand Down Expand Up @@ -91,7 +91,7 @@ class _TasksListPageConsumerState extends ConsumerState<TasksListPage> {
}

Widget _buildBody() {
AsyncValue<List<TaskList>> tasksList;
AsyncValue<List<String>> tasksList;

tasksList = ref.watch(
tasksListSearchProvider(
Expand All @@ -108,16 +108,17 @@ class _TasksListPageConsumerState extends ConsumerState<TasksListPage> {
Expanded(
child: tasksList.when(
data: (tasks) => _buildTasksList(tasks),
error: (error, stack) =>
Center(child: Text(L10n.of(context).loadingFailed(error))),
error: (error, stack) => Center(
child: Text(L10n.of(context).loadingFailed(error)),
),
loading: () => const TasksListSkeleton(),
),
),
],
);
}

Widget _buildTasksList(List<TaskList> tasksList) {
Widget _buildTasksList(List<String> tasksList) {
final size = MediaQuery.of(context).size;
final widthCount = (size.width ~/ 500).toInt();
const int minCount = 2;
Expand All @@ -129,12 +130,12 @@ class _TasksListPageConsumerState extends ConsumerState<TasksListPage> {
child: StaggeredGrid.count(
crossAxisCount: max(1, min(widthCount, minCount)),
children: [
for (var taskList in tasksList)
for (var taskListId in tasksList)
ValueListenableBuilder(
valueListenable: showCompletedTask,
builder: (context, value, child) {
return TaskListItemCard(
taskList: taskList,
taskListId: taskListId,
showCompletedTask: value,
showSpace: widget.spaceId == null,
);
Expand Down
8 changes: 4 additions & 4 deletions app/lib/features/tasks/providers/notifiers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ class TaskItemsListNotifier

Future<TasksOverview> _refresh(TaskList taskList) async {
final tasks = (await taskList.tasks()).toList();
List<Task> openTasks = [];
List<Task> doneTasks = [];
List<String> openTasks = [];
List<String> doneTasks = [];
for (final task in tasks) {
if (task.isDone()) {
doneTasks.add(task);
doneTasks.add(task.eventIdStr());
} else {
openTasks.add(task);
openTasks.add(task.eventIdStr());
}
}

Expand Down
29 changes: 20 additions & 9 deletions app/lib/features/tasks/providers/tasklists_providers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,44 +16,55 @@ final allTasksListsProvider =
);

final taskListProvider =
FutureProvider.family<List<TaskList>, String?>((ref, spaceId) async {
FutureProvider.family<List<String>, String?>((ref, spaceId) async {
final allTaskLists = await ref.watch(allTasksListsProvider.future);
if (spaceId == null) {
return allTaskLists;
return allTaskLists.map((e) => e.eventIdStr()).toList();
} else {
return allTaskLists.where((t) => t.spaceIdStr() == spaceId).toList();
return allTaskLists
.where((t) => t.spaceIdStr() == spaceId)
.map((e) => e.eventIdStr())
.toList();
}
});

//Search any tasks list
typedef TasksListSearchParams = ({String? spaceId, String searchText});

final tasksListSearchProvider = FutureProvider.autoDispose
.family<List<TaskList>, TasksListSearchParams>((ref, params) async {
.family<List<String>, TasksListSearchParams>((ref, params) async {
final tasksList = await ref.watch(taskListProvider(params.spaceId).future);

//Return all task list if search text is empty
if (params.searchText.isEmpty) return tasksList;

//Return all task list filter if search text is given
List<TaskList> filteredTaskList = [];
for (final taskListItem in tasksList) {
List<String> filteredTaskList = [];
for (final taskListId in tasksList) {
//Check search param in task list
final taskListItem =
await ref.watch(taskListItemProvider(taskListId).future);
if (taskListItem
.name()
.toLowerCase()
.contains(params.searchText.toLowerCase())) {
filteredTaskList.add(taskListItem);
filteredTaskList.add(taskListId);
continue;
}

//Check search param in task list items data
final tasks = await ref.watch(taskItemsListProvider(taskListItem).future);
for (final openTaskItem in tasks.openTasks) {
for (final openTaskItemId in tasks.openTasks) {
final openTaskItem = await ref.watch(
taskItemProvider((taskListId: taskListId, taskId: openTaskItemId))
.future,
);
if (openTaskItem
.title()
.toLowerCase()
.contains(params.searchText.toLowerCase())) {
filteredTaskList.add(taskListItem);
filteredTaskList.add(taskListId);
break;
}
}
}
Expand Down
3 changes: 0 additions & 3 deletions app/lib/features/tasks/sheets/create_update_task_item.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:acter/common/toolkit/buttons/inline_text_button.dart';
import 'package:acter/common/utils/utils.dart';
import 'package:acter/features/tasks/providers/tasklists_providers.dart';
import 'package:acter/features/tasks/widgets/due_picker.dart';
import 'package:acter_flutter_sdk/acter_flutter_sdk_ffi.dart';
import 'package:dart_date/dart_date.dart';
Expand Down Expand Up @@ -260,7 +259,6 @@ class _CreateUpdateItemListConsumerState
if (!mounted) return;
if (widget.cancel != null) widget.cancel!();
Navigator.pop(context);
ref.invalidate(taskListProvider);
} catch (e) {
EasyLoading.dismiss();
if (!mounted) return;
Expand Down Expand Up @@ -291,7 +289,6 @@ class _CreateUpdateItemListConsumerState
EasyLoading.dismiss();
if (!mounted) return;
Navigator.pop(context);
ref.invalidate(taskListProvider);
} catch (e) {
EasyLoading.dismiss();
if (!mounted) return;
Expand Down
2 changes: 0 additions & 2 deletions app/lib/features/tasks/sheets/create_update_task_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'package:acter/common/providers/space_providers.dart';
import 'package:acter/common/toolkit/buttons/inline_text_button.dart';
import 'package:acter/common/widgets/html_editor.dart';
import 'package:acter/common/widgets/spaces/select_space_form_field.dart';
import 'package:acter/features/tasks/providers/tasklists_providers.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
Expand Down Expand Up @@ -202,7 +201,6 @@ class _CreateUpdateTaskListConsumerState
EasyLoading.dismiss();
if (!mounted) return;
Navigator.pop(context);
ref.invalidate(taskListProvider);
} catch (e) {
if (!mounted) {
EasyLoading.dismiss();
Expand Down
Loading

0 comments on commit e479f21

Please sign in to comment.