Post editing

This commit is contained in:
LittleSheep 2025-04-26 17:55:32 +08:00
parent 7646a51cd9
commit a7d4975e18
2 changed files with 60 additions and 32 deletions

View File

@ -185,8 +185,8 @@ class PostComposeScreen extends HookConsumerWidget {
); );
final client = ref.watch(apiClientProvider); final client = ref.watch(apiClientProvider);
await client.post( await client.request(
'/posts', originalPost == null ? '/posts' : '/posts/${originalPost!.id}',
data: { data: {
'content': contentController.text, 'content': contentController.text,
'attachments': 'attachments':
@ -195,7 +195,10 @@ class PostComposeScreen extends HookConsumerWidget {
.map((e) => e.data.id) .map((e) => e.data.id)
.toList(), .toList(),
}, },
options: Options(headers: {'X-Pub': currentPublisher.value?.name}), options: Options(
headers: {'X-Pub': currentPublisher.value?.name},
method: originalPost == null ? 'POST' : 'PATCH',
),
); );
if (context.mounted) { if (context.mounted) {
context.maybePop(true); context.maybePop(true);
@ -223,6 +226,8 @@ class PostComposeScreen extends HookConsumerWidget {
strokeWidth: 2.5, strokeWidth: 2.5,
), ),
).center() ).center()
: originalPost != null
? const Icon(LucideIcons.edit)
: const Icon(LucideIcons.upload), : const Icon(LucideIcons.upload),
), ),
const Gap(8), const Gap(8),
@ -357,7 +362,8 @@ class _AttachmentPreview extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return AspectRatio( return AspectRatio(
aspectRatio: 1, aspectRatio:
(item.isOnCloud ? (item.data.fileMeta?['ratio'] ?? 1) : 1).toDouble(),
child: ClipRRect( child: ClipRRect(
borderRadius: BorderRadius.circular(8), borderRadius: BorderRadius.circular(8),
child: Stack( child: Stack(
@ -485,7 +491,7 @@ class _AttachmentPreview extends StatelessWidget {
color: Colors.black.withOpacity(0.5), color: Colors.black.withOpacity(0.5),
padding: EdgeInsets.symmetric(horizontal: 8, vertical: 4), padding: EdgeInsets.symmetric(horizontal: 8, vertical: 4),
child: child:
(item is SnCloudFile) (item.isOnCloud)
? Row( ? Row(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [

View File

@ -1,10 +1,12 @@
import 'package:auto_route/auto_route.dart'; import 'package:auto_route/auto_route.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:island/models/post.dart'; import 'package:island/models/post.dart';
import 'package:island/route.gr.dart'; import 'package:island/route.gr.dart';
import 'package:island/widgets/content/cloud_file_collection.dart'; import 'package:island/widgets/content/cloud_file_collection.dart';
import 'package:island/widgets/content/cloud_files.dart'; import 'package:island/widgets/content/cloud_files.dart';
import 'package:island/widgets/content/markdown.dart'; import 'package:island/widgets/content/markdown.dart';
import 'package:lucide_icons/lucide_icons.dart';
import 'package:styled_widget/styled_widget.dart'; import 'package:styled_widget/styled_widget.dart';
class PostItem extends StatelessWidget { class PostItem extends StatelessWidget {
@ -23,12 +25,28 @@ class PostItem extends StatelessWidget {
final renderingPadding = final renderingPadding =
padding ?? EdgeInsets.symmetric(horizontal: 12, vertical: 16); padding ?? EdgeInsets.symmetric(horizontal: 12, vertical: 16);
return Padding( return CupertinoContextMenu.builder(
actions: [
CupertinoContextMenuAction(
trailingIcon: LucideIcons.edit,
onPressed: () {
context.router.push(PostEditRoute(id: item.id));
},
child: Text('Edit'),
),
],
builder: (context, animation) {
return Material(
color: Theme.of(context).colorScheme.surface,
child: SingleChildScrollView(
physics: const NeverScrollableScrollPhysics(),
child: Padding(
padding: renderingPadding, padding: renderingPadding,
child: Column( child: Column(
spacing: 8, spacing: 8,
children: [ children: [
Row( Row(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
spacing: 12, spacing: 12,
children: [ children: [
@ -56,6 +74,10 @@ class PostItem extends StatelessWidget {
CloudFileList(files: item.attachments), CloudFileList(files: item.attachments),
], ],
), ),
),
),
);
},
); );
} }
} }