✨ Post repost, reply and even more optimization!
This commit is contained in:
@ -98,7 +98,8 @@ class _AttachmentListState extends State<AttachmentList> {
|
||||
return AspectRatio(
|
||||
aspectRatio: _aspectRatio,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(color: Theme.of(context).colorScheme.surfaceVariant),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.surfaceContainerHigh),
|
||||
child: const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
@ -118,14 +119,18 @@ class _AttachmentListState extends State<AttachmentList> {
|
||||
return GestureDetector(
|
||||
child: Container(
|
||||
width: MediaQuery.of(context).size.width,
|
||||
decoration: BoxDecoration(color: Theme.of(context).colorScheme.surfaceVariant),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.surfaceContainerHigh,
|
||||
),
|
||||
child: Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
AttachmentItem(
|
||||
key: Key('a${element!.uuid}'),
|
||||
item: element,
|
||||
badge: _attachmentsMeta.length > 1 ? '${idx + 1}/${_attachmentsMeta.length}' : null,
|
||||
badge: _attachmentsMeta.length > 1
|
||||
? '${idx + 1}/${_attachmentsMeta.length}'
|
||||
: null,
|
||||
showHideButton: !element.isMature || _showMature,
|
||||
onHide: () {
|
||||
setState(() => _showMature = false);
|
||||
@ -147,11 +152,15 @@ class _AttachmentListState extends State<AttachmentList> {
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(Icons.visibility_off, color: Colors.white, size: 32),
|
||||
const Icon(Icons.visibility_off,
|
||||
color: Colors.white, size: 32),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'matureContent'.tr,
|
||||
style: const TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 16),
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 16),
|
||||
),
|
||||
Text(
|
||||
'matureContentCaption'.tr,
|
||||
|
@ -1,7 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:solian/models/attachment.dart';
|
||||
import 'package:solian/providers/content/attachment_item.dart';
|
||||
import 'package:solian/services.dart';
|
||||
|
||||
class AttachmentListFullscreen extends StatefulWidget {
|
||||
final Attachment attachment;
|
||||
@ -9,7 +8,8 @@ class AttachmentListFullscreen extends StatefulWidget {
|
||||
const AttachmentListFullscreen({super.key, required this.attachment});
|
||||
|
||||
@override
|
||||
State<AttachmentListFullscreen> createState() => _AttachmentListFullscreenState();
|
||||
State<AttachmentListFullscreen> createState() =>
|
||||
_AttachmentListFullscreenState();
|
||||
}
|
||||
|
||||
class _AttachmentListFullscreenState extends State<AttachmentListFullscreen> {
|
||||
@ -21,7 +21,7 @@ class _AttachmentListFullscreenState extends State<AttachmentListFullscreen> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Material(
|
||||
color: Theme.of(context).colorScheme.background,
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
child: GestureDetector(
|
||||
child: SizedBox(
|
||||
height: MediaQuery.of(context).size.height,
|
||||
|
@ -35,7 +35,8 @@ class AttachmentPublishingPopup extends StatefulWidget {
|
||||
});
|
||||
|
||||
@override
|
||||
State<AttachmentPublishingPopup> createState() => _AttachmentPublishingPopupState();
|
||||
State<AttachmentPublishingPopup> createState() =>
|
||||
_AttachmentPublishingPopupState();
|
||||
}
|
||||
|
||||
class _AttachmentPublishingPopupState extends State<AttachmentPublishingPopup> {
|
||||
@ -97,7 +98,8 @@ class _AttachmentPublishingPopupState extends State<AttachmentPublishingPopup> {
|
||||
final AuthProvider auth = Get.find();
|
||||
if (!await auth.isAuthorized) return;
|
||||
|
||||
FilePickerResult? result = await FilePicker.platform.pickFiles(allowMultiple: true);
|
||||
FilePickerResult? result =
|
||||
await FilePicker.platform.pickFiles(allowMultiple: true);
|
||||
if (result == null) return;
|
||||
|
||||
List<File> files = result.paths.map((path) => File(path!)).toList();
|
||||
@ -157,7 +159,8 @@ class _AttachmentPublishingPopupState extends State<AttachmentPublishingPopup> {
|
||||
client.httpClient.baseUrl = ServiceFinder.services['paperclip'];
|
||||
client.httpClient.addAuthenticator(auth.reqAuthenticator);
|
||||
|
||||
final filePayload = MultipartFile(await file.readAsBytes(), filename: basename(file.path));
|
||||
final filePayload =
|
||||
MultipartFile(await file.readAsBytes(), filename: basename(file.path));
|
||||
final fileAlt = basename(file.path).contains('.')
|
||||
? basename(file.path).substring(0, basename(file.path).lastIndexOf('.'))
|
||||
: basename(file.path);
|
||||
@ -187,7 +190,17 @@ class _AttachmentPublishingPopupState extends State<AttachmentPublishingPopup> {
|
||||
if (bytes == 0) return '0 Bytes';
|
||||
const k = 1024;
|
||||
final dm = decimals < 0 ? 0 : decimals;
|
||||
final sizes = ['Bytes', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];
|
||||
final sizes = [
|
||||
'Bytes',
|
||||
'KiB',
|
||||
'MiB',
|
||||
'GiB',
|
||||
'TiB',
|
||||
'PiB',
|
||||
'EiB',
|
||||
'ZiB',
|
||||
'YiB'
|
||||
];
|
||||
final i = (math.log(bytes) / math.log(k)).floor().toInt();
|
||||
return '${(bytes / math.pow(k, i)).toStringAsFixed(dm)} ${sizes[i]}';
|
||||
}
|
||||
@ -240,7 +253,7 @@ class _AttachmentPublishingPopupState extends State<AttachmentPublishingPopup> {
|
||||
'attachmentAdd'.tr,
|
||||
style: Theme.of(context).textTheme.headlineSmall,
|
||||
).paddingOnly(left: 24, right: 24, top: 32, bottom: 16),
|
||||
_isBusy ? const LinearProgressIndicator().animate().scaleX() : Container(),
|
||||
if (_isBusy) const LinearProgressIndicator().animate().scaleX(),
|
||||
Expanded(
|
||||
child: Builder(builder: (context) {
|
||||
if (_isFirstTimeBusy && _isBusy) {
|
||||
@ -255,7 +268,8 @@ class _AttachmentPublishingPopupState extends State<AttachmentPublishingPopup> {
|
||||
final element = _attachments[index];
|
||||
final fileType = element!.mimetype.split('/').first;
|
||||
return Container(
|
||||
padding: const EdgeInsets.only(left: 16, right: 8, bottom: 16),
|
||||
padding:
|
||||
const EdgeInsets.only(left: 16, right: 8, bottom: 16),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
@ -266,7 +280,8 @@ class _AttachmentPublishingPopupState extends State<AttachmentPublishingPopup> {
|
||||
element.alt,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
maxLines: 1,
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold),
|
||||
),
|
||||
Text(
|
||||
'${fileType[0].toUpperCase()}${fileType.substring(1)} · ${formatBytes(element.size)}',
|
||||
@ -287,12 +302,18 @@ class _AttachmentPublishingPopupState extends State<AttachmentPublishingPopup> {
|
||||
return AttachmentEditingPopup(
|
||||
item: element,
|
||||
onDelete: () {
|
||||
setState(() => _attachments.removeAt(index));
|
||||
widget.onUpdate(_attachments.map((e) => e!.id).toList());
|
||||
setState(
|
||||
() => _attachments.removeAt(index));
|
||||
widget.onUpdate(_attachments
|
||||
.map((e) => e!.id)
|
||||
.toList());
|
||||
},
|
||||
onUpdate: (item) {
|
||||
setState(() => _attachments[index] = item);
|
||||
widget.onUpdate(_attachments.map((e) => e!.id).toList());
|
||||
setState(
|
||||
() => _attachments[index] = item);
|
||||
widget.onUpdate(_attachments
|
||||
.map((e) => e!.id)
|
||||
.toList());
|
||||
},
|
||||
);
|
||||
},
|
||||
@ -363,7 +384,11 @@ class AttachmentEditingPopup extends StatefulWidget {
|
||||
final Function onDelete;
|
||||
final Function(Attachment item) onUpdate;
|
||||
|
||||
const AttachmentEditingPopup({super.key, required this.item, required this.onDelete, required this.onUpdate});
|
||||
const AttachmentEditingPopup(
|
||||
{super.key,
|
||||
required this.item,
|
||||
required this.onDelete,
|
||||
required this.onUpdate});
|
||||
|
||||
@override
|
||||
State<AttachmentEditingPopup> createState() => _AttachmentEditingPopupState();
|
||||
@ -387,7 +412,8 @@ class _AttachmentEditingPopupState extends State<AttachmentEditingPopup> {
|
||||
setState(() => _isBusy = true);
|
||||
var resp = await client.put('/api/attachments/${widget.item.id}', {
|
||||
'metadata': {
|
||||
if (_hasAspectRatio) 'ratio': double.tryParse(_ratioController.value.text) ?? 1,
|
||||
if (_hasAspectRatio)
|
||||
'ratio': double.tryParse(_ratioController.value.text) ?? 1,
|
||||
},
|
||||
'alt': _altController.value.text,
|
||||
'usage': widget.item.usage,
|
||||
@ -426,7 +452,8 @@ class _AttachmentEditingPopupState extends State<AttachmentEditingPopup> {
|
||||
_altController.text = widget.item.alt;
|
||||
|
||||
if (['image', 'video'].contains(widget.item.mimetype.split('/').first)) {
|
||||
_ratioController.text = widget.item.metadata?['ratio']?.toString() ?? 1.toString();
|
||||
_ratioController.text =
|
||||
widget.item.metadata?['ratio']?.toString() ?? 1.toString();
|
||||
_hasAspectRatio = true;
|
||||
}
|
||||
}
|
||||
@ -446,12 +473,11 @@ class _AttachmentEditingPopupState extends State<AttachmentEditingPopup> {
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
_isBusy
|
||||
? ClipRRect(
|
||||
borderRadius: const BorderRadius.all(Radius.circular(8)),
|
||||
child: const LinearProgressIndicator().animate().scaleX(),
|
||||
)
|
||||
: Container(),
|
||||
if (_isBusy)
|
||||
ClipRRect(
|
||||
borderRadius: const BorderRadius.all(Radius.circular(8)),
|
||||
child: const LinearProgressIndicator().animate().scaleX(),
|
||||
),
|
||||
const SizedBox(height: 18),
|
||||
TextField(
|
||||
controller: _altController,
|
||||
@ -461,7 +487,8 @@ class _AttachmentEditingPopupState extends State<AttachmentEditingPopup> {
|
||||
border: const OutlineInputBorder(),
|
||||
labelText: 'attachmentAlt'.tr,
|
||||
),
|
||||
onTapOutside: (_) => FocusManager.instance.primaryFocus?.unfocus(),
|
||||
onTapOutside: (_) =>
|
||||
FocusManager.instance.primaryFocus?.unfocus(),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextField(
|
||||
@ -473,7 +500,8 @@ class _AttachmentEditingPopupState extends State<AttachmentEditingPopup> {
|
||||
border: const OutlineInputBorder(),
|
||||
labelText: 'aspectRatio'.tr,
|
||||
),
|
||||
onTapOutside: (_) => FocusManager.instance.primaryFocus?.unfocus(),
|
||||
onTapOutside: (_) =>
|
||||
FocusManager.instance.primaryFocus?.unfocus(),
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
SingleChildScrollView(
|
||||
@ -483,7 +511,8 @@ class _AttachmentEditingPopupState extends State<AttachmentEditingPopup> {
|
||||
runSpacing: 0,
|
||||
children: [
|
||||
ActionChip(
|
||||
avatar: Icon(Icons.square_rounded, color: Theme.of(context).colorScheme.onSurfaceVariant),
|
||||
avatar: Icon(Icons.square_rounded,
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant),
|
||||
label: Text('aspectRatioSquare'.tr),
|
||||
onPressed: () {
|
||||
if (_hasAspectRatio) {
|
||||
@ -492,20 +521,24 @@ class _AttachmentEditingPopupState extends State<AttachmentEditingPopup> {
|
||||
},
|
||||
),
|
||||
ActionChip(
|
||||
avatar: Icon(Icons.portrait, color: Theme.of(context).colorScheme.onSurfaceVariant),
|
||||
avatar: Icon(Icons.portrait,
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant),
|
||||
label: Text('aspectRatioPortrait'.tr),
|
||||
onPressed: () {
|
||||
if (_hasAspectRatio) {
|
||||
setState(() => _ratioController.text = (9 / 16).toString());
|
||||
setState(
|
||||
() => _ratioController.text = (9 / 16).toString());
|
||||
}
|
||||
},
|
||||
),
|
||||
ActionChip(
|
||||
avatar: Icon(Icons.landscape, color: Theme.of(context).colorScheme.onSurfaceVariant),
|
||||
avatar: Icon(Icons.landscape,
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant),
|
||||
label: Text('aspectRatioLandscape'.tr),
|
||||
onPressed: () {
|
||||
if (_hasAspectRatio) {
|
||||
setState(() => _ratioController.text = (16 / 9).toString());
|
||||
setState(
|
||||
() => _ratioController.text = (16 / 9).toString());
|
||||
}
|
||||
},
|
||||
),
|
||||
@ -514,7 +547,8 @@ class _AttachmentEditingPopupState extends State<AttachmentEditingPopup> {
|
||||
),
|
||||
Card(
|
||||
child: CheckboxListTile(
|
||||
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(10))),
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.all(Radius.circular(10))),
|
||||
title: Text('matureContent'.tr),
|
||||
secondary: const Icon(Icons.visibility_off),
|
||||
value: _isMature,
|
||||
@ -530,7 +564,8 @@ class _AttachmentEditingPopupState extends State<AttachmentEditingPopup> {
|
||||
actionsAlignment: MainAxisAlignment.spaceBetween,
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
style: TextButton.styleFrom(foregroundColor: Theme.of(context).colorScheme.error),
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: Theme.of(context).colorScheme.error),
|
||||
onPressed: () {
|
||||
deleteAttachment().then((_) {
|
||||
Navigator.pop(context);
|
||||
@ -542,7 +577,9 @@ class _AttachmentEditingPopupState extends State<AttachmentEditingPopup> {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
TextButton(
|
||||
style: TextButton.styleFrom(foregroundColor: Theme.of(context).colorScheme.onSurfaceVariant),
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor:
|
||||
Theme.of(context).colorScheme.onSurfaceVariant),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: Text('cancel'.tr),
|
||||
),
|
||||
|
@ -1,115 +1,192 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_animate/flutter_animate.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:solian/exts.dart';
|
||||
import 'package:solian/models/post.dart';
|
||||
import 'package:solian/models/reaction.dart';
|
||||
import 'package:solian/providers/auth.dart';
|
||||
import 'package:solian/router.dart';
|
||||
import 'package:solian/screens/posts/publish.dart';
|
||||
import 'package:solian/services.dart';
|
||||
import 'package:solian/widgets/posts/post_reaction.dart';
|
||||
|
||||
class PostQuickAction extends StatefulWidget {
|
||||
class PostAction extends StatefulWidget {
|
||||
final Post item;
|
||||
final void Function(String symbol, int num) onReact;
|
||||
|
||||
const PostQuickAction({super.key, required this.item, required this.onReact});
|
||||
const PostAction({super.key, required this.item});
|
||||
|
||||
@override
|
||||
State<PostQuickAction> createState() => _PostQuickActionState();
|
||||
State<PostAction> createState() => _PostActionState();
|
||||
}
|
||||
|
||||
class _PostQuickActionState extends State<PostQuickAction> {
|
||||
bool _isSubmitting = false;
|
||||
class _PostActionState extends State<PostAction> {
|
||||
bool _isBusy = true;
|
||||
bool _canModifyContent = false;
|
||||
|
||||
void showReactMenu() {
|
||||
showModalBottomSheet(
|
||||
useRootNavigator: true,
|
||||
isScrollControlled: true,
|
||||
context: context,
|
||||
builder: (context) => PostReactionPopup(
|
||||
item: widget.item,
|
||||
onReact: (key, value) {
|
||||
doWidgetReact(key, value.attitude);
|
||||
},
|
||||
void checkAbleToModifyContent() async {
|
||||
final AuthProvider provider = Get.find();
|
||||
if (!await provider.isAuthorized) return;
|
||||
|
||||
setState(() => _isBusy = true);
|
||||
|
||||
final prof = await provider.getProfile();
|
||||
setState(() {
|
||||
_canModifyContent = prof.body?['id'] == widget.item.author.externalId;
|
||||
_isBusy = false;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
checkAbleToModifyContent();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SafeArea(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'postActionList'.tr,
|
||||
style: Theme.of(context).textTheme.headlineSmall,
|
||||
),
|
||||
Text(
|
||||
'#${widget.item.id.toString().padLeft(8, '0')}',
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
],
|
||||
).paddingOnly(left: 24, right: 24, top: 32, bottom: 16),
|
||||
if (_isBusy) const LinearProgressIndicator().animate().scaleX(),
|
||||
Expanded(
|
||||
child: ListView(
|
||||
children: [
|
||||
ListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
leading: const Icon(Icons.reply),
|
||||
title: Text('reply'.tr),
|
||||
onTap: () async {
|
||||
final value = await AppRouter.instance.pushNamed(
|
||||
'postPublishing',
|
||||
extra: PostPublishingArguments(reply: widget.item),
|
||||
);
|
||||
if (value != null) {
|
||||
Navigator.pop(context, true);
|
||||
}
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
leading: const Icon(Icons.redo),
|
||||
title: Text('repost'.tr),
|
||||
onTap: () async {
|
||||
final value = await AppRouter.instance.pushNamed(
|
||||
'postPublishing',
|
||||
extra: PostPublishingArguments(repost: widget.item),
|
||||
);
|
||||
if (value != null) {
|
||||
Navigator.pop(context, true);
|
||||
}
|
||||
},
|
||||
),
|
||||
if (_canModifyContent)
|
||||
const Divider(thickness: 0.3, height: 0.3)
|
||||
.paddingSymmetric(vertical: 16),
|
||||
if (_canModifyContent)
|
||||
ListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
leading: const Icon(Icons.edit),
|
||||
title: Text('edit'.tr),
|
||||
onTap: () async {
|
||||
final value = await AppRouter.instance.pushNamed(
|
||||
'postPublishing',
|
||||
extra: PostPublishingArguments(edit: widget.item),
|
||||
);
|
||||
if (value != null) {
|
||||
Navigator.pop(context, true);
|
||||
}
|
||||
},
|
||||
),
|
||||
if (_canModifyContent)
|
||||
ListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
leading: const Icon(Icons.delete),
|
||||
title: Text('delete'.tr),
|
||||
onTap: () async {
|
||||
final value = await showDialog(
|
||||
context: context,
|
||||
builder: (context) =>
|
||||
PostDeletionDialog(item: widget.item),
|
||||
);
|
||||
if (value != null) {
|
||||
Navigator.pop(context, true);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> doWidgetReact(String symbol, int attitude) async {
|
||||
class PostDeletionDialog extends StatefulWidget {
|
||||
final Post item;
|
||||
|
||||
const PostDeletionDialog({super.key, required this.item});
|
||||
|
||||
@override
|
||||
State<PostDeletionDialog> createState() => _PostDeletionDialogState();
|
||||
}
|
||||
|
||||
class _PostDeletionDialogState extends State<PostDeletionDialog> {
|
||||
bool _isBusy = false;
|
||||
|
||||
void performAction() async {
|
||||
final AuthProvider auth = Get.find();
|
||||
|
||||
if (_isSubmitting) return;
|
||||
if (!await auth.isAuthorized) return;
|
||||
|
||||
final client = GetConnect();
|
||||
client.httpClient.baseUrl = ServiceFinder.services['interactive'];
|
||||
client.httpClient.addAuthenticator(auth.reqAuthenticator);
|
||||
|
||||
setState(() => _isSubmitting = true);
|
||||
setState(() => _isBusy = true);
|
||||
final resp = await client.delete('/api/posts/${widget.item.id}');
|
||||
setState(() => _isBusy = false);
|
||||
|
||||
final resp = await client.post('/api/posts/${widget.item.alias}/react', {
|
||||
'symbol': symbol,
|
||||
'attitude': attitude,
|
||||
});
|
||||
if (resp.statusCode == 201) {
|
||||
widget.onReact(symbol, 1);
|
||||
context.showSnackbar('reactCompleted'.tr);
|
||||
} else if (resp.statusCode == 204) {
|
||||
widget.onReact(symbol, -1);
|
||||
context.showSnackbar('reactUncompleted'.tr);
|
||||
} else {
|
||||
if (resp.statusCode != 200) {
|
||||
context.showErrorDialog(resp.bodyString);
|
||||
} else {
|
||||
Navigator.pop(context, true);
|
||||
}
|
||||
|
||||
setState(() => _isSubmitting = false);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
const density = VisualDensity(horizontal: -4, vertical: -3);
|
||||
|
||||
return SizedBox(
|
||||
height: 32,
|
||||
width: double.infinity,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
ActionChip(
|
||||
avatar: const Icon(Icons.comment),
|
||||
label: Text(widget.item.replyCount.toString()),
|
||||
visualDensity: density,
|
||||
onPressed: () {},
|
||||
),
|
||||
const VerticalDivider(thickness: 0.3, width: 0.3, indent: 8, endIndent: 8).paddingOnly(left: 8),
|
||||
Expanded(
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
scrollDirection: Axis.horizontal,
|
||||
children: [
|
||||
...widget.item.reactionList.entries.map((x) {
|
||||
final info = reactions[x.key];
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(right: 8),
|
||||
child: ActionChip(
|
||||
avatar: Text(info!.icon),
|
||||
label: Text(x.value.toString()),
|
||||
tooltip: ':${x.key}:',
|
||||
visualDensity: density,
|
||||
onPressed: _isSubmitting ? null : () => doWidgetReact(x.key, info.attitude),
|
||||
),
|
||||
);
|
||||
}),
|
||||
ActionChip(
|
||||
avatar: const Icon(Icons.add_reaction, color: Colors.teal),
|
||||
label: Text('reactAdd'.tr),
|
||||
visualDensity: density,
|
||||
onPressed: () => showReactMenu(),
|
||||
),
|
||||
],
|
||||
).paddingOnly(left: 8),
|
||||
)
|
||||
],
|
||||
),
|
||||
return AlertDialog(
|
||||
title: Text('postDeletionConfirm'.tr),
|
||||
content: Text('postDeletionConfirmCaption'.trParams({
|
||||
'content': widget.item.content
|
||||
.substring(0, min(widget.item.content.length, 60))
|
||||
.trim(),
|
||||
})),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
onPressed: _isBusy ? null : () => Navigator.pop(context),
|
||||
child: Text('cancel'.tr),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: _isBusy ? null : () => performAction(),
|
||||
child: Text('confirm'.tr),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -5,13 +5,18 @@ import 'package:get/get_utils/get_utils.dart';
|
||||
import 'package:solian/models/post.dart';
|
||||
import 'package:solian/widgets/account/account_avatar.dart';
|
||||
import 'package:solian/widgets/attachments/attachment_list.dart';
|
||||
import 'package:solian/widgets/posts/post_action.dart';
|
||||
import 'package:solian/widgets/posts/post_quick_action.dart';
|
||||
import 'package:timeago/timeago.dart' show format;
|
||||
|
||||
class PostItem extends StatefulWidget {
|
||||
final Post item;
|
||||
final bool isReactable;
|
||||
|
||||
const PostItem({super.key, required this.item});
|
||||
const PostItem({
|
||||
super.key,
|
||||
required this.item,
|
||||
this.isReactable = true,
|
||||
});
|
||||
|
||||
@override
|
||||
State<PostItem> createState() => _PostItemState();
|
||||
@ -45,7 +50,8 @@ class _PostItemState extends State<PostItem> {
|
||||
item.author.nick,
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
).paddingOnly(left: 12),
|
||||
Text(format(item.createdAt, locale: 'en_short')).paddingOnly(left: 4),
|
||||
Text(format(item.createdAt, locale: 'en_short'))
|
||||
.paddingOnly(left: 4),
|
||||
],
|
||||
),
|
||||
Markdown(
|
||||
@ -59,17 +65,19 @@ class _PostItemState extends State<PostItem> {
|
||||
)
|
||||
],
|
||||
).paddingOnly(
|
||||
top: 18,
|
||||
top: 10,
|
||||
bottom: hasAttachment ? 10 : 0,
|
||||
right: 16,
|
||||
left: 16,
|
||||
),
|
||||
AttachmentList(attachmentsId: item.attachments ?? List.empty()),
|
||||
PostQuickAction(
|
||||
isReactable: widget.isReactable,
|
||||
item: widget.item,
|
||||
onReact: (symbol, changes) {
|
||||
setState(() {
|
||||
item.reactionList[symbol] = (item.reactionList[symbol] ?? 0) + changes;
|
||||
item.reactionList[symbol] =
|
||||
(item.reactionList[symbol] ?? 0) + changes;
|
||||
});
|
||||
},
|
||||
).paddingOnly(
|
||||
|
141
lib/widgets/posts/post_quick_action.dart
Normal file
141
lib/widgets/posts/post_quick_action.dart
Normal file
@ -0,0 +1,141 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:solian/exts.dart';
|
||||
import 'package:solian/models/post.dart';
|
||||
import 'package:solian/models/reaction.dart';
|
||||
import 'package:solian/providers/auth.dart';
|
||||
import 'package:solian/services.dart';
|
||||
import 'package:solian/widgets/posts/post_reaction.dart';
|
||||
|
||||
class PostQuickAction extends StatefulWidget {
|
||||
final Post item;
|
||||
final bool isReactable;
|
||||
final void Function(String symbol, int num) onReact;
|
||||
|
||||
const PostQuickAction({
|
||||
super.key,
|
||||
required this.item,
|
||||
this.isReactable = true,
|
||||
required this.onReact,
|
||||
});
|
||||
|
||||
@override
|
||||
State<PostQuickAction> createState() => _PostQuickActionState();
|
||||
}
|
||||
|
||||
class _PostQuickActionState extends State<PostQuickAction> {
|
||||
bool _isSubmitting = false;
|
||||
|
||||
void showReactMenu() {
|
||||
showModalBottomSheet(
|
||||
useRootNavigator: true,
|
||||
isScrollControlled: true,
|
||||
context: context,
|
||||
builder: (context) => PostReactionPopup(
|
||||
item: widget.item,
|
||||
onReact: (key, value) {
|
||||
doWidgetReact(key, value.attitude);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> doWidgetReact(String symbol, int attitude) async {
|
||||
if (!widget.isReactable) return;
|
||||
|
||||
final AuthProvider auth = Get.find();
|
||||
|
||||
if (_isSubmitting) return;
|
||||
if (!await auth.isAuthorized) return;
|
||||
|
||||
final client = GetConnect();
|
||||
client.httpClient.baseUrl = ServiceFinder.services['interactive'];
|
||||
client.httpClient.addAuthenticator(auth.reqAuthenticator);
|
||||
|
||||
setState(() => _isSubmitting = true);
|
||||
|
||||
final resp = await client.post('/api/posts/${widget.item.alias}/react', {
|
||||
'symbol': symbol,
|
||||
'attitude': attitude,
|
||||
});
|
||||
if (resp.statusCode == 201) {
|
||||
widget.onReact(symbol, 1);
|
||||
context.showSnackbar('reactCompleted'.tr);
|
||||
} else if (resp.statusCode == 204) {
|
||||
widget.onReact(symbol, -1);
|
||||
context.showSnackbar('reactUncompleted'.tr);
|
||||
} else {
|
||||
context.showErrorDialog(resp.bodyString);
|
||||
}
|
||||
|
||||
setState(() => _isSubmitting = false);
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
if (!widget.isReactable && widget.item.reactionList.isEmpty) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
widget.onReact('thumb_up', 0);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
const density = VisualDensity(horizontal: -4, vertical: -3);
|
||||
|
||||
return SizedBox(
|
||||
height: 32,
|
||||
width: double.infinity,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
if (widget.isReactable)
|
||||
ActionChip(
|
||||
avatar: const Icon(Icons.comment),
|
||||
label: Text(widget.item.replyCount.toString()),
|
||||
visualDensity: density,
|
||||
onPressed: () {},
|
||||
),
|
||||
if (widget.isReactable)
|
||||
const VerticalDivider(
|
||||
thickness: 0.3, width: 0.3, indent: 8, endIndent: 8)
|
||||
.paddingOnly(left: 8),
|
||||
Expanded(
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
scrollDirection: Axis.horizontal,
|
||||
children: [
|
||||
...widget.item.reactionList.entries.map((x) {
|
||||
final info = reactions[x.key];
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(right: 8),
|
||||
child: ActionChip(
|
||||
avatar: Text(info!.icon),
|
||||
label: Text(x.value.toString()),
|
||||
tooltip: ':${x.key}:',
|
||||
visualDensity: density,
|
||||
onPressed: _isSubmitting
|
||||
? null
|
||||
: () => doWidgetReact(x.key, info.attitude),
|
||||
),
|
||||
);
|
||||
}),
|
||||
if (widget.isReactable)
|
||||
ActionChip(
|
||||
avatar: const Icon(Icons.add_reaction, color: Colors.teal),
|
||||
label: Text('reactAdd'.tr),
|
||||
visualDensity: density,
|
||||
onPressed: () => showReactMenu(),
|
||||
),
|
||||
],
|
||||
).paddingOnly(left: 8),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user