Hide attachments list on article

This commit is contained in:
LittleSheep 2025-07-03 01:06:01 +08:00
parent a20c2598fc
commit ee72d79c93
5 changed files with 60 additions and 19 deletions

View File

@ -358,6 +358,10 @@ class ArticleComposeScreen extends HookConsumerWidget {
delta, delta,
); );
}, },
onInsert: () => ComposeLogic.insertAttachment(
state,
idx,
),
), ),
), ),
], ],

View File

@ -15,6 +15,7 @@ class AttachmentPreview extends StatelessWidget {
final double? progress; final double? progress;
final Function(int)? onMove; final Function(int)? onMove;
final Function? onDelete; final Function? onDelete;
final Function? onInsert;
final Function? onRequestUpload; final Function? onRequestUpload;
const AttachmentPreview({ const AttachmentPreview({
super.key, super.key,
@ -23,6 +24,7 @@ class AttachmentPreview extends StatelessWidget {
this.onRequestUpload, this.onRequestUpload,
this.onMove, this.onMove,
this.onDelete, this.onDelete,
this.onInsert,
}); });
@override @override
@ -166,6 +168,18 @@ class AttachmentPreview extends StatelessWidget {
onMove?.call(1); onMove?.call(1);
}, },
), ),
if (onInsert != null)
InkWell(
borderRadius: BorderRadius.circular(8),
child: const Icon(
Symbols.add,
size: 14,
color: Colors.white,
).padding(horizontal: 8, vertical: 6),
onTap: () {
onInsert?.call();
},
),
], ],
), ),
), ),

View File

@ -474,6 +474,23 @@ class ComposeLogic {
state.attachments.value = clone; state.attachments.value = clone;
} }
static void insertAttachment(ComposeState state, int index) {
final attachment = state.attachments.value[index];
if (!attachment.isOnCloud) {
return;
}
final cloudFile = attachment.data as SnCloudFile;
final markdown = '![${cloudFile.name}](${cloudFile.id})';
final controller = state.contentController;
final text = controller.text;
final selection = controller.selection;
final newText = text.replaceRange(selection.start, selection.end, markdown);
controller.text = newText;
controller.selection = TextSelection.fromPosition(
TextPosition(offset: selection.start + markdown.length),
);
}
static Future<void> performAction( static Future<void> performAction(
WidgetRef ref, WidgetRef ref,
ComposeState state, ComposeState state,

View File

@ -163,7 +163,7 @@ class PostItem extends HookConsumerWidget {
if ((item.repliedPost != null || item.forwardedPost != null) && if ((item.repliedPost != null || item.forwardedPost != null) &&
showReferencePost) showReferencePost)
_buildReferencePost(context, item), _buildReferencePost(context, item),
if (item.attachments.isNotEmpty) if (item.attachments.isNotEmpty && item.type != 1)
CloudFileList( CloudFileList(
files: item.attachments, files: item.attachments,
maxWidth: math.min( maxWidth: math.min(
@ -389,7 +389,7 @@ class PostItem extends HookConsumerWidget {
item.forwardedPost != null) && item.forwardedPost != null) &&
showReferencePost) showReferencePost)
_buildReferencePost(context, item), _buildReferencePost(context, item),
if (item.attachments.isNotEmpty) if (item.attachments.isNotEmpty && item.type != 1)
CloudFileList( CloudFileList(
files: item.attachments, files: item.attachments,
maxWidth: math.min( maxWidth: math.min(
@ -696,7 +696,7 @@ Widget _buildReferencePost(BuildContext context, SnPost item) {
isCompact: true, isCompact: true,
margin: const EdgeInsets.only(top: 4, bottom: 8), margin: const EdgeInsets.only(top: 4, bottom: 8),
), ),
if (referencePost.attachments.isNotEmpty) if (referencePost.attachments.isNotEmpty && referencePost.type != 1)
Row( Row(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [

View File

@ -1,6 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:island/models/post.dart'; import 'package:island/models/post.dart';
import 'package:island/pods/userinfo.dart';
import 'package:island/widgets/content/sheet.dart'; import 'package:island/widgets/content/sheet.dart';
import 'package:island/widgets/post/post_replies.dart'; import 'package:island/widgets/post/post_replies.dart';
import 'package:island/widgets/post/post_quick_reply.dart'; import 'package:island/widgets/post/post_quick_reply.dart';
@ -14,6 +15,8 @@ class PostRepliesSheet extends HookConsumerWidget {
@override @override
Widget build(BuildContext context, WidgetRef ref) { Widget build(BuildContext context, WidgetRef ref) {
final user = ref.watch(userInfoProvider);
return SheetScaffold( return SheetScaffold(
titleText: 'repliesCount'.plural(post.repliesCount), titleText: 'repliesCount'.plural(post.repliesCount),
child: Column( child: Column(
@ -21,26 +24,29 @@ class PostRepliesSheet extends HookConsumerWidget {
// Replies list // Replies list
Expanded( Expanded(
child: CustomScrollView( child: CustomScrollView(
slivers: [PostRepliesList( slivers: [
postId: post.id.toString(), PostRepliesList(
backgroundColor: Colors.transparent, postId: post.id.toString(),
)], backgroundColor: Colors.transparent,
),
],
), ),
), ),
// Quick reply section // Quick reply section
Material( if (user.value != null)
elevation: 2, Material(
child: PostQuickReply( elevation: 2,
parent: post, child: PostQuickReply(
onPosted: () { parent: post,
ref.invalidate(postRepliesNotifierProvider(post.id)); onPosted: () {
}, ref.invalidate(postRepliesNotifierProvider(post.id));
).padding( },
bottom: MediaQuery.of(context).padding.bottom + 16, ).padding(
top: 16, bottom: MediaQuery.of(context).padding.bottom + 16,
horizontal: 16, top: 16,
horizontal: 16,
),
), ),
),
], ],
), ),
); );