Skip to content

Commit

Permalink
make ui related changes
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-ishita-g committed Jun 6, 2024
1 parent 108c151 commit 3551e2c
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 111 deletions.
3 changes: 1 addition & 2 deletions app/lib/ui/flow/home/components/home_top_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,7 @@ class _HomeTopBarState extends State<HomeTopBar> with TickerProviderStateMixin {
.copyWith(color: context.colorScheme.textPrimary),
),
),
const Spacer(),
if (widget.fetchingInviteCode || widget.selectedSpace == null) ...[
if (widget.fetchingInviteCode || (widget.selectedSpace == null && widget.spaces.isNotEmpty)) ...[
const AppProgressIndicator(size: AppProgressIndicatorSize.small)
] else ...[
Icon(
Expand Down
61 changes: 23 additions & 38 deletions app/lib/ui/flow/setting/contact_support/contact_support_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,16 @@ class _ContactSupportScreenState extends ConsumerState<ContactSupportScreen> {
@override
Widget build(BuildContext context) {
notifier = ref.watch(contactSupportViewStateProvider.notifier);
final state = ref.watch(contactSupportViewStateProvider);
_observePop();

return AppPage(
title: context.l10n.contact_support_title,
body: _body(context),
body: _body(context, state),
);
}

Widget _body(BuildContext context) {
final state = ref.watch(contactSupportViewStateProvider);

Widget _body(BuildContext context, ContactSupportViewState state) {
return Builder(
builder: (context) => Stack(
children: [
Expand All @@ -50,14 +49,16 @@ class _ContactSupportScreenState extends ConsumerState<ContactSupportScreen> {
const EdgeInsets.all(16) +
BottomStickyOverlay.padding,
children: [
_titleView(
context: context,
AppTextField(
controller: state.title,
label: context.l10n.contact_support_title_field,
),
const SizedBox(height: 40),
_descriptionView(
context: context,
AppTextField(
label: context.l10n.contact_support_description_title,
borderType: AppTextFieldBorderType.outline,
controller: state.description,
maxLines: 8,
),
const SizedBox(height: 40),
_attachmentButton(
Expand All @@ -80,14 +81,19 @@ class _ContactSupportScreenState extends ConsumerState<ContactSupportScreen> {
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: state.attachments.length,
itemBuilder: (context, index) => _attachmentItem(
itemBuilder: (context, index) {
final file = state.attachments[index];
final isLoading = state.attachmentUploading.contains(file);
return _attachmentItem(
context: context,
path: state.attachments[index].path,
name: state.attachments[index].path.split('/').last,
loading: false,
path: file.path,
name: file.path.split('/').last,
loading: isLoading,
onCancelTap: () {
notifier.onAttachmentRemoved(index);
}),
},
);
},
separatorBuilder: (context, index) => const SizedBox(height: 8),
);
}
Expand Down Expand Up @@ -158,29 +164,6 @@ class _ContactSupportScreenState extends ConsumerState<ContactSupportScreen> {
);
}

Widget _titleView({
required BuildContext context,
required TextEditingController controller,
}) {
return AppTextField(
label: context.l10n.contact_support_title_field,
controller: controller,
onChanged: (value) => notifier.onTitleChanged(value),
);
}

Widget _descriptionView({
required BuildContext context,
required TextEditingController controller,
}) {
return AppTextField(
label: context.l10n.contact_support_description_title,
borderType: AppTextFieldBorderType.outline,
controller: controller,
maxLines: 8,
);
}

Widget _attachmentButton({
required BuildContext context,
required VoidCallback onAttachmentTap,
Expand All @@ -207,7 +190,7 @@ class _ContactSupportScreenState extends ConsumerState<ContactSupportScreen> {
Widget _submitButton(BuildContext context, ContactSupportViewState state) {
return BottomStickyOverlay(
child: PrimaryButton(
enabled: !state.submitting && state.title.text.length >= 3,
enabled: !state.submitting && state.enableSubmit,
progress: state.submitting,
context.l10n.contact_support_submit_title,
onPressed: () {
Expand All @@ -218,7 +201,9 @@ class _ContactSupportScreenState extends ConsumerState<ContactSupportScreen> {
}

void _observePop() {
ref.listen(contactSupportViewStateProvider.select((state) => state.requestSent), (previous, next) {
ref.listen(
contactSupportViewStateProvider.select((state) => state.requestSent),
(previous, next) {
if (next) {
context.pop();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:io';
import 'package:data/api/support/api_support_service.dart';
import 'package:data/log/logger.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:image_picker/image_picker.dart';
Expand All @@ -24,22 +25,21 @@ class ContactSupportViewNotifier

ContactSupportViewNotifier(this.supportService, this.picker)
: super(
ContactSupportViewState(
title: TextEditingController(),
description: TextEditingController(),
),
);
ContactSupportViewState(
title: TextEditingController(),
description: TextEditingController(),
),
) {
state.title.addListener(verifySubmitButton);
}

final List<File> attachmentsToUpload = [];
final Map<File, String?> uploadedAttachments = {};

void onTitleChanged(String title) {
state = state.copyWith(title: TextEditingController(text: title));
}

void onDescriptionChanged(String description) {
state =
state.copyWith(description: TextEditingController(text: description));
void verifySubmitButton() {
state = state.copyWith(
enableSubmit: state.title.text.trim().isNotEmpty && state.attachmentUploading.isEmpty,
);
}

void pickAttachments() async {
Expand All @@ -52,7 +52,7 @@ class ContactSupportViewNotifier
onAttachmentAdded(files);
} catch (error, stackTrace) {
logger.e(
"ContactSupportViewStateNotifier: Error while pick image!",
"ContactSupportViewNotifier: Error while picking image!",
error: error,
stackTrace: stackTrace,
);
Expand All @@ -72,6 +72,7 @@ class ContactSupportViewNotifier
state = state.copyWith(
attachments: attachments, attachmentSizeLimitExceed: false);
uploadPendingAttachments();
verifySubmitButton();
}

void uploadPendingAttachments() async {
Expand All @@ -84,38 +85,45 @@ class ContactSupportViewNotifier
_uploadedAttachment(file, uri);
} catch (error, stack) {
logger.e(
'ContactSupportViewNotifier: error while upload attachments',
error: error,
'ContactSupportViewNotifier: error while uploading attachments',
error: error,
stackTrace: stack,
);
_uploadedAttachment(file, null);
state = state.copyWith(error: error);
}
}
verifySubmitButton();
}

void _uploadingAttachment(File file) {
final uploading = state.attachmentUploading.toList();
uploading.add(file);
state = state.copyWith(attachmentUploading: uploading);
verifySubmitButton();
}

void _uploadedAttachment(File file, String? uri) {
final uploading = state.attachmentUploading.toList();
uploading.remove(file);
uploadedAttachments[file] = uri;
state = state.copyWith(attachmentUploading: uploading);
verifySubmitButton();
}

void onAttachmentRemoved(int index) {
state = state.copyWith(attachments: state.attachments.toList()..removeAt(index));
final attachments = state.attachments.toList();
final removedFile = attachments.removeAt(index);
uploadedAttachments.remove(removedFile);
state = state.copyWith(attachments: attachments);
verifySubmitButton();
}

void submitSupportRequest() async {
try {
state = state.copyWith(submitting: true, error: null, attachmentSizeLimitExceed: false);
final attachments =
uploadedAttachments.values.whereType<String>().toList();
uploadedAttachments.values.whereType<String>().toList();
await supportService.submitSupportRequest(
state.title.text,
state.description.text,
Expand All @@ -124,7 +132,7 @@ class ContactSupportViewNotifier
state = state.copyWith(requestSent: true, submitting: false);
} catch (error, stack) {
logger.e(
'ContactSupportViewNotifier: error while submit response',
'ContactSupportViewNotifier: error while submitting response',
error: error,
stackTrace: stack,
);
Expand All @@ -139,9 +147,10 @@ class ContactSupportViewState with _$ContactSupportViewState {
@Default(false) bool submitting,
@Default(false) bool requestSent,
@Default(false) bool attachmentSizeLimitExceed,
@Default(false) bool enableSubmit,
Object? error,
required TextEditingController title,
required TextEditingController description,
required TextEditingController title,
@Default([]) List<File> attachments,
@Default([]) List<File> attachmentUploading,
}) = _ContactSupportViewState;
Expand Down
Loading

0 comments on commit 3551e2c

Please sign in to comment.