Skip to content

Commit

Permalink
Merge pull request #2440 from acterglobal/kumar/boost-share-improvements
Browse files Browse the repository at this point in the history
RefDetail enhancement on Space Objects
  • Loading branch information
kumarpalsinh25 authored Dec 26, 2024
2 parents 49f31e0 + 74a559d commit 39dd072
Show file tree
Hide file tree
Showing 23 changed files with 422 additions and 647 deletions.
2 changes: 2 additions & 0 deletions .changes/2440-ref-space-objects.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- [New] : Boost Actions : Now you can share space objects as boost action of any space in which you are part of. There is not selected space restriction anymore.
- [Enhancement] : Attachment List on space object details screen got event better by having separate reference attachments list from general attachment list.
48 changes: 48 additions & 0 deletions app/lib/common/widgets/reference_details_item.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import 'package:acter_flutter_sdk/acter_flutter_sdk_ffi.dart';
import 'package:atlas_icons/atlas_icons.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:flutter/material.dart';
import 'package:phosphor_flutter/phosphor_flutter.dart';

class ReferenceDetailsItem extends StatelessWidget {
final RefDetails refDetails;

const ReferenceDetailsItem({
super.key,
required this.refDetails,
});

@override
Widget build(BuildContext context) {
final refTitle = refDetails.title() ?? L10n.of(context).unknown;
final refType = refDetails.typeStr();
final roomName = refDetails.roomDisplayName().toString();
return Card(
margin: EdgeInsets.symmetric(vertical: 6, horizontal: 12),
child: ListTile(
leading: Icon(getIconByType(refType), size: 25),
title: Text(refTitle),
subtitle: Text(refType),
onTap: () => EasyLoading.showError(
L10n.of(context).noObjectAccess(refType, roomName),
duration: const Duration(seconds: 3),
),
),
);
}

IconData getIconByType(String refType) {
final defaultIcon = PhosphorIconsThin.tagChevron;
switch (refType) {
case 'pin':
return Atlas.pin;
case 'calendar-event':
return Atlas.calendar;
case 'task-list':
return Atlas.list;
default:
return defaultIcon;
}
}
}
23 changes: 12 additions & 11 deletions app/lib/common/widgets/share/action/share_space_object_action.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,21 @@ class ShareSpaceObjectActionUI extends ConsumerWidget {
WidgetRef ref,
SpaceObjectDetails spaceObjectDetails,
) {
String spaceId = spaceObjectDetails.spaceId;
ObjectType objectType = spaceObjectDetails.objectType;
String objectId = spaceObjectDetails.objectId;

final newsRefType = getNewsRefTypeFromObjType(objectType);
return AttachOptions(
onTapBoost: () {
Navigator.pop(context);
onTapBoost: () async {
String spaceId = spaceObjectDetails.spaceId;
final refDetails = await getRefDetails(
ref: ref,
objectDetails: spaceObjectDetails,
);
if (!context.mounted) return;
context.pushNamed(
Routes.actionAddUpdate.name,
queryParameters: {'spaceId': spaceId},
extra: newsRefType != null
? NewsReferencesModel(type: newsRefType, id: objectId)
: null,
extra: refDetails,
);
if (!context.mounted) return;
Navigator.pop(context);
},
onTapPin: () async {
final refDetails = await getRefDetails(
Expand Down Expand Up @@ -234,7 +234,8 @@ class ShareSpaceObjectActionUI extends ConsumerWidget {
await ref.watch(calendarEventProvider(objectId).future);
return await sourceEvent.refDetails();
case ObjectType.taskList:
final sourceTaskList = await ref.watch(taskListProvider(objectId).future);
final sourceTaskList =
await ref.watch(taskListProvider(objectId).future);
return await sourceTaskList.refDetails();
default:
return null;
Expand Down
18 changes: 18 additions & 0 deletions app/lib/features/attachments/providers/attachment_providers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@ final attachmentsProvider = FutureProvider.family
return (await manager.attachments()).toList();
});

/// Provider for getting reference attachments
final referenceAttachmentsProvider = FutureProvider.family
.autoDispose<List<Attachment>, AttachmentsManager>((ref, manager) async {
final attachmentList = await ref.watch(attachmentsProvider(manager).future);
final refAttachmentList =
attachmentList.where((item) => item.refDetails() != null).toList();
return refAttachmentList;
});

/// Provider for getting msgContent attachments
final msgContentAttachmentsProvider = FutureProvider.family
.autoDispose<List<Attachment>, AttachmentsManager>((ref, manager) async {
final attachmentList = await ref.watch(attachmentsProvider(manager).future);
final msgContentAttachmentList =
attachmentList.where((item) => item.msgContent() != null).toList();
return msgContentAttachmentList;
});

final attachmentMediaStateProvider = StateNotifierProvider.family
.autoDispose<AttachmentMediaNotifier, AttachmentMediaState, Attachment>(
(ref, attachment) =>
Expand Down
59 changes: 0 additions & 59 deletions app/lib/features/attachments/widgets/attachment_item.dart

This file was deleted.

127 changes: 88 additions & 39 deletions app/lib/features/attachments/widgets/attachment_section.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import 'package:acter/features/attachments/actions/handle_selected_attachments.d
import 'package:acter/features/attachments/actions/select_attachment.dart';
import 'package:acter/features/attachments/providers/attachment_providers.dart';
import 'package:acter/features/attachments/types.dart';
import 'package:acter/features/attachments/widgets/attachment_item.dart';
import 'package:acter/features/attachments/widgets/msg_content_attachment_item.dart';
import 'package:acter/features/attachments/widgets/reference_attachment_item.dart';
import 'package:acter_flutter_sdk/acter_flutter_sdk_ffi.dart'
show Attachment, AttachmentsManager;
show AttachmentsManager;
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
Expand Down Expand Up @@ -79,9 +80,52 @@ class FoundAttachmentSectionWidget extends ConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
final attachmentsLoader = ref.watch(attachmentsProvider(attachmentManager));
return attachmentsLoader.when(
data: (attachments) => attachmentData(attachments, context, ref),
return Padding(
padding: const EdgeInsets.all(12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
referenceAttachmentsUI(context, ref),
msgContentAttachmentsUI(context, ref),
],
),
);
}

Widget referenceAttachmentsUI(
BuildContext context,
WidgetRef ref,
) {
final referenceAttachmentsLoader =
ref.watch(referenceAttachmentsProvider(attachmentManager));
bool canEdit = attachmentManager.canEditAttachments();

return referenceAttachmentsLoader.when(
data: (refAttachmentList) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
L10n.of(context).references,
style: Theme.of(context).textTheme.titleSmall,
),
const SizedBox(height: 10),
ListView.builder(
shrinkWrap: true,
itemCount: refAttachmentList.length,
padding: EdgeInsets.zero,
physics: NeverScrollableScrollPhysics(),
itemBuilder: (context, index) {
return ReferenceAttachmentItem(
attachment: refAttachmentList[index],
canEdit: canEdit,
);
},
),
const SizedBox(height: 20),
],
);
},
error: (e, s) {
_log.severe('Failed to load attachments', e, s);
return Text(L10n.of(context).errorLoadingAttachments(e));
Expand All @@ -96,36 +140,54 @@ class FoundAttachmentSectionWidget extends ConsumerWidget {
);
}

Widget attachmentData(
List<Attachment> list,
Widget msgContentAttachmentsUI(
BuildContext context,
WidgetRef ref,
) {
final msgContentAttachmentsLoader =
ref.watch(msgContentAttachmentsProvider(attachmentManager));
bool canEdit = attachmentManager.canEditAttachments();
return Padding(
padding: const EdgeInsets.all(12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
attachmentHeader(context, ref),
if (list.isEmpty) ...[
const SizedBox(height: 10),
Text(L10n.of(context).attachmentEmptyStateTitle),
],
Wrap(
spacing: 5.0,
runSpacing: 10.0,
children: <Widget>[
for (final item in list)
_buildAttachmentItem(context, item, canEdit),
return msgContentAttachmentsLoader.when(
data: (msgContentAttachmentList) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
generalAttachmentHeader(context, ref),
if (msgContentAttachmentList.isNotEmpty)
ListView.builder(
shrinkWrap: true,
itemCount: msgContentAttachmentList.length,
padding: EdgeInsets.zero,
physics: NeverScrollableScrollPhysics(),
itemBuilder: (context, index) {
return MsgContentAttachmentItem(
attachment: msgContentAttachmentList[index],
canEdit: canEdit,
);
},
),
if (msgContentAttachmentList.isEmpty) ...[
const SizedBox(height: 10),
Text(L10n.of(context).attachmentEmptyStateTitle),
],
),
],
],
);
},
error: (e, s) {
_log.severe('Failed to load attachments', e, s);
return Text(L10n.of(context).errorLoadingAttachments(e));
},
loading: () => const Skeletonizer(
child: Wrap(
spacing: 5.0,
runSpacing: 10.0,
children: [],
),
),
);
}

Widget attachmentHeader(BuildContext context, WidgetRef ref) {
Widget generalAttachmentHeader(BuildContext context, WidgetRef ref) {
final lang = L10n.of(context);
final attachmentTitleTextStyle = Theme.of(context).textTheme.titleSmall;
return Row(
Expand Down Expand Up @@ -162,17 +224,4 @@ class FoundAttachmentSectionWidget extends ConsumerWidget {
],
);
}

Widget _buildAttachmentItem(
BuildContext context,
Attachment item,
bool canEdit,
) {
final eventId = item.attachmentIdStr();
return AttachmentItem(
key: Key('$eventId-attachment'),
attachment: item,
canEdit: canEdit,
);
}
}
Loading

0 comments on commit 39dd072

Please sign in to comment.