✨ Post reactions
This commit is contained in:
@ -2,11 +2,11 @@ import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:auto_route/auto_route.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:flutter_quill/flutter_quill.dart';
|
||||
import 'package:gap/gap.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
@ -21,6 +21,7 @@ import 'package:island/widgets/alert.dart';
|
||||
import 'package:island/widgets/app_scaffold.dart';
|
||||
import 'package:island/widgets/content/cloud_files.dart';
|
||||
import 'package:island/widgets/post/publishers_modal.dart';
|
||||
import 'package:markdown_editor_plus/widgets/markdown_auto_preview.dart';
|
||||
import 'package:material_symbols_icons/symbols.dart';
|
||||
import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';
|
||||
import 'package:styled_widget/styled_widget.dart';
|
||||
@ -88,14 +89,9 @@ class PostComposeScreen extends HookConsumerWidget {
|
||||
final descriptionController = useTextEditingController(
|
||||
text: originalPost?.description,
|
||||
);
|
||||
final contentController = useMemoized(() => QuillController.basic());
|
||||
|
||||
useEffect(() {
|
||||
if (originalPost?.content != null) {
|
||||
contentController.document = Document.fromJson(originalPost!.content!);
|
||||
}
|
||||
return null;
|
||||
}, [originalPost]);
|
||||
final contentController = useTextEditingController(
|
||||
text: originalPost?.content,
|
||||
);
|
||||
|
||||
final submitting = useState(false);
|
||||
|
||||
@ -192,14 +188,14 @@ class PostComposeScreen extends HookConsumerWidget {
|
||||
await Future.wait(
|
||||
attachments.value
|
||||
.where((e) => e.isOnDevice)
|
||||
.map((e) => uploadAttachment(e.data)),
|
||||
.mapIndexed((idx, e) => uploadAttachment(idx)),
|
||||
);
|
||||
|
||||
final client = ref.watch(apiClientProvider);
|
||||
await client.request(
|
||||
originalPost == null ? '/posts' : '/posts/${originalPost!.id}',
|
||||
data: {
|
||||
'content': contentController.document.toDelta().toJson(),
|
||||
'content': contentController.text,
|
||||
'attachments':
|
||||
attachments.value
|
||||
.where((e) => e.isOnCloud)
|
||||
@ -255,10 +251,15 @@ class PostComposeScreen extends HookConsumerWidget {
|
||||
GestureDetector(
|
||||
child: ProfilePictureWidget(
|
||||
fileId: currentPublisher.value?.pictureId,
|
||||
radius: 24,
|
||||
radius: 20,
|
||||
fallbackIcon:
|
||||
currentPublisher.value == null
|
||||
? Symbols.question_mark
|
||||
: null,
|
||||
),
|
||||
onTap: () {
|
||||
showCupertinoModalBottomSheet(
|
||||
showModalBottomSheet(
|
||||
isScrollControlled: true,
|
||||
context: context,
|
||||
builder: (context) => PublisherModal(),
|
||||
).then((value) {
|
||||
@ -292,11 +293,18 @@ class PostComposeScreen extends HookConsumerWidget {
|
||||
FocusManager.instance.primaryFocus?.unfocus(),
|
||||
),
|
||||
const Gap(12),
|
||||
QuillEditor.basic(
|
||||
controller: contentController,
|
||||
config: QuillEditorConfig(
|
||||
placeholder: 'postPlaceholder'.tr(),
|
||||
TapRegion(
|
||||
child: MarkdownAutoPreview(
|
||||
controller: contentController,
|
||||
emojiConvert: true,
|
||||
hintText: 'postPlaceholder'.tr(),
|
||||
decoration: InputDecoration(
|
||||
border: InputBorder.none,
|
||||
),
|
||||
),
|
||||
onTapOutside:
|
||||
(_) =>
|
||||
FocusManager.instance.primaryFocus?.unfocus(),
|
||||
),
|
||||
const Gap(8),
|
||||
Column(
|
||||
@ -337,29 +345,17 @@ class PostComposeScreen extends HookConsumerWidget {
|
||||
),
|
||||
Material(
|
||||
elevation: 2,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
child: Row(
|
||||
children: [
|
||||
SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: QuillSimpleToolbar(
|
||||
controller: contentController,
|
||||
config: QuillSimpleToolbarConfig(showFontFamily: false),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: pickPhotoMedia,
|
||||
icon: const Icon(Symbols.add_a_photo),
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
IconButton(
|
||||
onPressed: pickPhotoMedia,
|
||||
icon: const Icon(Symbols.add_a_photo),
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
IconButton(
|
||||
onPressed: pickVideoMedia,
|
||||
icon: const Icon(Symbols.videocam),
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
],
|
||||
IconButton(
|
||||
onPressed: pickVideoMedia,
|
||||
icon: const Icon(Symbols.videocam),
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
],
|
||||
).padding(
|
||||
@ -510,49 +506,46 @@ class AttachmentPreview extends StatelessWidget {
|
||||
Positioned(
|
||||
top: 8,
|
||||
right: 8,
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
onTap: () => onRequestUpload?.call(),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
onTap: () => onRequestUpload?.call(),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: Container(
|
||||
color: Colors.black.withOpacity(0.5),
|
||||
padding: EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
child:
|
||||
(item.isOnCloud)
|
||||
? Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
Symbols.cloud,
|
||||
size: 16,
|
||||
color: Colors.white,
|
||||
),
|
||||
const Gap(8),
|
||||
Text(
|
||||
'On-cloud',
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
],
|
||||
)
|
||||
: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
Symbols.cloud_off,
|
||||
size: 16,
|
||||
color: Colors.white,
|
||||
),
|
||||
const Gap(8),
|
||||
Text(
|
||||
'On-device',
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
child: Container(
|
||||
color: Colors.black.withOpacity(0.5),
|
||||
padding: EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
child:
|
||||
(item.isOnCloud)
|
||||
? Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
Symbols.cloud,
|
||||
size: 16,
|
||||
color: Colors.white,
|
||||
),
|
||||
const Gap(8),
|
||||
Text(
|
||||
'On-cloud',
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
],
|
||||
)
|
||||
: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
Symbols.cloud_off,
|
||||
size: 16,
|
||||
color: Colors.white,
|
||||
),
|
||||
const Gap(8),
|
||||
Text(
|
||||
'On-device',
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
Reference in New Issue
Block a user