Skip to content

Commit

Permalink
PR Feedback Points
Browse files Browse the repository at this point in the history
  • Loading branch information
kumarpalsinh25 committed Aug 13, 2024
1 parent 0734f17 commit 00a9e3b
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 65 deletions.
2 changes: 1 addition & 1 deletion app/lib/common/utils/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ Future<bool> openLink(String target, BuildContext context) async {
}
}

String getFileSize(int bytes) {
String getHumanReadableFileSize(int bytes) {
if (bytes <= 0) return '0 B';
const suffixes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
var i = (log(bytes) / log(1024)).floor();
Expand Down
13 changes: 6 additions & 7 deletions app/lib/common/widgets/spaces/select_space_form_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class SelectSpaceFormField extends ConsumerWidget {
final String? emptyText;
final String canCheck;
final bool mandatory;
final bool isCompactView;
final bool useCompatView;

const SelectSpaceFormField({
super.key,
Expand All @@ -24,18 +24,17 @@ class SelectSpaceFormField extends ConsumerWidget {
this.emptyText,
this.mandatory = true,
required this.canCheck,
this.isCompactView = false,
this.useCompatView = false,
});

void selectSpace(BuildContext context, WidgetRef ref) async {
final spaceNotifier = ref.watch(selectedSpaceIdProvider.notifier);
final newSelectedSpaceId = await selectSpaceDrawer(
context: context,
currentSpaceId: ref.read(selectedSpaceIdProvider),
canCheck: canCheck,
title: Text(selectTitle ?? L10n.of(context).selectSpace),
);
spaceNotifier.state = newSelectedSpaceId;
ref.read(selectedSpaceIdProvider.notifier).state = newSelectedSpaceId;
}

@override
Expand All @@ -57,7 +56,7 @@ class SelectSpaceFormField extends ConsumerWidget {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (!isCompactView)
if (!useCompatView)
Text(
title ?? L10n.of(context).space,
style: Theme.of(context).textTheme.bodyMedium,
Expand Down Expand Up @@ -99,9 +98,9 @@ class SelectSpaceFormField extends ConsumerWidget {
? SpaceChip(
space: space,
onTapOpenSpaceDetail: false,
isCompactView: isCompactView,
useCompatView: useCompatView,
onTapSelectSpace: () =>
isCompactView ? selectSpace(context, ref) : null,
useCompatView ? selectSpace(context, ref) : null,
)
: Text(currentSelectedSpace!),
error: (e, s) => Text(L10n.of(context).errorLoading(e)),
Expand Down
8 changes: 3 additions & 5 deletions app/lib/features/attachments/widgets/attachment_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class AttachmentItem extends ConsumerWidget {
final fileNameSplit = fileName.split('.');
final title = fileNameSplit.first;
final fileExtension = fileNameSplit.last;
String fileSize = getFileSize(msgContent.size() ?? 0);
String fileSize = getHumanReadableFileSize(msgContent.size() ?? 0);
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expand Down Expand Up @@ -135,10 +135,8 @@ class AttachmentItem extends ConsumerWidget {
// Open attachment link
if (attachmentType == AttachmentType.link) {
openLink(attachment.link() ?? '', context);
}

// If attachment is media then check media is downloaded
else if (mediaState.mediaFile == null) {
} else if (mediaState.mediaFile == null) {
// If attachment is media then check media is downloaded
// If attachment not downloaded
ref
.read(attachmentMediaStateProvider(attachment).notifier)
Expand Down
5 changes: 2 additions & 3 deletions app/lib/features/attachments/widgets/attachment_section.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,8 @@ class FoundAttachmentSectionWidget extends ConsumerWidget {
spacing: 5.0,
runSpacing: 10.0,
children: <Widget>[
if (list.isNotEmpty)
for (var item in list)
_buildAttachmentItem(context, item, canEdit),
for (var item in list)
_buildAttachmentItem(context, item, canEdit),
],
),
],
Expand Down
6 changes: 3 additions & 3 deletions app/lib/features/home/widgets/space_chip.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ class SpaceChip extends ConsumerWidget {
final SpaceItem? space;
final String? spaceId;
final bool onTapOpenSpaceDetail;
final bool isCompactView;
final bool useCompatView;
final VoidCallback? onTapSelectSpace;

const SpaceChip({
super.key,
this.space,
this.spaceId,
this.onTapOpenSpaceDetail = true,
this.isCompactView = false,
this.useCompatView = false,
this.onTapSelectSpace,
});

Expand Down Expand Up @@ -64,7 +64,7 @@ class SpaceChip extends ConsumerWidget {
return InkWell(
onTap:
onTapOpenSpaceDetail ? () => goToSpace(context, space.roomId) : null,
child: isCompactView
child: useCompatView
? Row(
children: [
const Text('In'),
Expand Down
23 changes: 9 additions & 14 deletions app/lib/features/pins/actions/attachment_leading_icon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,13 @@ import 'package:atlas_icons/atlas_icons.dart';
import 'package:flutter/material.dart';

Widget attachmentLeadingIcon(AttachmentType pinAttachmentType) {
switch (pinAttachmentType) {
case AttachmentType.link:
return const Icon(Atlas.link);
case AttachmentType.image:
return const Icon(Atlas.image_gallery);
case AttachmentType.video:
return const Icon(Atlas.video_camera);
case AttachmentType.audio:
return const Icon(Atlas.audio_headphones);
case AttachmentType.file:
return const Icon(Atlas.file);
default:
return const SizedBox.shrink();
}
return switch (pinAttachmentType) {
AttachmentType.link => const Icon(Atlas.link),
AttachmentType.image => const Icon(Atlas.image_gallery),
AttachmentType.video => const Icon(Atlas.video_camera),
AttachmentType.audio => const Icon(Atlas.audio_headphones),
AttachmentType.file => const Icon(Atlas.file),
AttachmentType.camera => const Icon(Atlas.camera),
AttachmentType.location => const Icon(Atlas.location)
};
}
29 changes: 10 additions & 19 deletions app/lib/features/pins/actions/select_pin_attachments.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,13 @@ import 'package:logging/logging.dart';
final _log = Logger('a3::pins::select::attachment');

FileType attachmentFileType(AttachmentType pinAttachmentType) {
switch (pinAttachmentType) {
case AttachmentType.image:
return FileType.image;
case AttachmentType.video:
return FileType.video;
case AttachmentType.audio:
return FileType.audio;
case AttachmentType.file:
return FileType.custom;
default:
return FileType.any;
}
return switch (pinAttachmentType) {
AttachmentType.image => FileType.image,
AttachmentType.video => FileType.video,
AttachmentType.audio => FileType.audio,
AttachmentType.file => FileType.custom,
_ => FileType.any
};
}

//Select Attachment
Expand All @@ -31,14 +26,10 @@ Future<void> selectAttachment(
AttachmentType attachmentType,
) async {
try {
final fileType = attachmentFileType(attachmentType);
FilePickerResult? result = await FilePicker.platform.pickFiles(
type: fileType,
allowedExtensions: fileType == FileType.custom ? ['pdf', 'txt'] : null,
);
FilePickerResult? result = await FilePicker.platform.pickFiles();
if (result != null && result.files.isNotEmpty) {
final file = result.files.first;
String fileSize = getFileSize(file.size);
String fileSize = getHumanReadableFileSize(file.size);
final fileNameSplit = file.name.split('.');
final title = fileNameSplit.first;
final fileExtension = fileNameSplit.last;
Expand All @@ -53,6 +44,6 @@ Future<void> selectAttachment(
}
} catch (e, st) {
debugPrint('Error => $e');
_log.severe('Error => $e', st);
_log.severe('Error selecting attachment', e, st);
}
}
2 changes: 1 addition & 1 deletion app/lib/features/pins/pages/create_pin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class _CreatePinConsumerState extends ConsumerState<CreatePin> {
alignment: Alignment.centerLeft,
child: SelectSpaceFormField(
canCheck: 'CanPostPin',
isCompactView: true,
useCompatView: true,
),
),
const SizedBox(height: 14),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import 'package:acter/features/pins/models/create_pin_state/pin_attachment_model
import 'package:flutter_riverpod/flutter_riverpod.dart';

class CreatePinNotifier extends StateNotifier<CreatePinState> {
final Ref ref;

CreatePinNotifier({required this.ref}) : super(const CreatePinState());
CreatePinNotifier() : super(const CreatePinState());

void setPinTitleValue(String title) {
state = state.copyWith(pinTitle: title);
Expand Down
4 changes: 2 additions & 2 deletions app/lib/features/pins/providers/pins_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ final pinEditProvider = StateNotifierProvider.family
// Create Pin State
final createPinStateProvider =
StateNotifierProvider.autoDispose<CreatePinNotifier, CreatePinState>(
(ref) => CreatePinNotifier(ref: ref),
);
(ref) => CreatePinNotifier(),
);
13 changes: 7 additions & 6 deletions app/lib/features/pins/widgets/pin_attachment_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:acter/features/pins/providers/pins_provider.dart';
import 'package:atlas_icons/atlas_icons.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';

class PinAttachmentOptions extends ConsumerWidget {
final bool isBottomSheetOpen;
Expand All @@ -28,7 +29,7 @@ class PinAttachmentOptions extends ConsumerWidget {
children: [
_pinAttachmentOptionItem(
context: context,
title: 'Text',
title: L10n.of(context).text,
iconData: Atlas.text,
onTap: () {
showEditPinDescriptionBottomSheet(
Expand All @@ -44,7 +45,7 @@ class PinAttachmentOptions extends ConsumerWidget {
),
_pinAttachmentOptionItem(
context: context,
title: 'Link',
title: L10n.of(context).link,
iconData: Atlas.link,
onTap: () => showAddPinLinkBottomSheet(
context: context,
Expand All @@ -54,7 +55,7 @@ class PinAttachmentOptions extends ConsumerWidget {
),
_pinAttachmentOptionItem(
context: context,
title: 'File',
title: L10n.of(context).file,
iconData: Atlas.file,
onTap: () => selectAttachmentOnTap(
ref,
Expand All @@ -69,7 +70,7 @@ class PinAttachmentOptions extends ConsumerWidget {
children: [
_pinAttachmentOptionItem(
context: context,
title: 'Image',
title: L10n.of(context).image,
iconData: Atlas.image_gallery,
onTap: () => selectAttachmentOnTap(
ref,
Expand All @@ -79,7 +80,7 @@ class PinAttachmentOptions extends ConsumerWidget {
),
_pinAttachmentOptionItem(
context: context,
title: 'Video',
title: L10n.of(context).video,
iconData: Atlas.video_camera,
onTap: () => selectAttachmentOnTap(
ref,
Expand All @@ -89,7 +90,7 @@ class PinAttachmentOptions extends ConsumerWidget {
),
_pinAttachmentOptionItem(
context: context,
title: 'Audio',
title: L10n.of(context).audio,
iconData: Atlas.audio_headphones,
onTap: () => selectAttachmentOnTap(
ref,
Expand Down
4 changes: 3 additions & 1 deletion app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -2065,5 +2065,7 @@
"pleaseEnterALink": "Please enter a link",
"pleaseEnterAValidLink": "Please enter a valid link",
"addLink": "Add Link",
"attachmentEmptyStateTitle": "No attachments found."
"attachmentEmptyStateTitle": "No attachments found.",
"text": "text",
"audio": "Audio"
}

0 comments on commit 00a9e3b

Please sign in to comment.