Able to edit post alias

This commit is contained in:
LittleSheep 2024-12-22 00:41:41 +08:00
parent 8c8ab24c9e
commit 7fc18b40db
7 changed files with 49 additions and 24 deletions

View File

@ -139,6 +139,8 @@
"fieldPostTitle": "Title", "fieldPostTitle": "Title",
"fieldPostDescription": "Description", "fieldPostDescription": "Description",
"fieldPostTags": "Tags", "fieldPostTags": "Tags",
"fieldPostAlias": "Alias",
"fieldPostAliasHint": "Optional, used to represent the post in URL, should follow URL-Safe.",
"postPublish": "Publish", "postPublish": "Publish",
"postPosted": "Post has been posted.", "postPosted": "Post has been posted.",
"postPublishedAt": "Published At", "postPublishedAt": "Published At",

View File

@ -123,6 +123,8 @@
"fieldPostTitle": "标题", "fieldPostTitle": "标题",
"fieldPostDescription": "描述", "fieldPostDescription": "描述",
"fieldPostTags": "标签", "fieldPostTags": "标签",
"fieldPostAlias": "别名",
"fieldPostAliasHint": "可选项,用于在 URL 中表示该帖子,应遵循 URL-Safe 的原则。",
"postPublish": "发布", "postPublish": "发布",
"postPublishedAt": "发布于", "postPublishedAt": "发布于",
"postPublishedUntil": "取消发布于", "postPublishedUntil": "取消发布于",

View File

@ -152,6 +152,7 @@ class PostWriteController extends ChangeNotifier {
final TextEditingController contentController = TextEditingController(); final TextEditingController contentController = TextEditingController();
final TextEditingController titleController = TextEditingController(); final TextEditingController titleController = TextEditingController();
final TextEditingController descriptionController = TextEditingController(); final TextEditingController descriptionController = TextEditingController();
final TextEditingController aliasController = TextEditingController();
PostWriteController() { PostWriteController() {
titleController.addListener(() => notifyListeners()); titleController.addListener(() => notifyListeners());
@ -198,6 +199,7 @@ class PostWriteController extends ChangeNotifier {
titleController.text = post.body['title'] ?? ''; titleController.text = post.body['title'] ?? '';
descriptionController.text = post.body['description'] ?? ''; descriptionController.text = post.body['description'] ?? '';
contentController.text = post.body['content'] ?? ''; contentController.text = post.body['content'] ?? '';
aliasController.text = post.alias ?? '';
publishedAt = post.publishedAt; publishedAt = post.publishedAt;
publishedUntil = post.publishedUntil; publishedUntil = post.publishedUntil;
visibleUsers = List.from(post.visibleUsersList ?? []); visibleUsers = List.from(post.visibleUsersList ?? []);
@ -269,7 +271,7 @@ class PostWriteController extends ChangeNotifier {
notifyListeners(); notifyListeners();
} }
Future<void> post(BuildContext context) async { Future<void> sendPost(BuildContext context) async {
if (isBusy || publisher == null) return; if (isBusy || publisher == null) return;
final sn = context.read<SnNetworkProvider>(); final sn = context.read<SnNetworkProvider>();
@ -334,6 +336,7 @@ class PostWriteController extends ChangeNotifier {
data: { data: {
'publisher': publisher!.id, 'publisher': publisher!.id,
'content': contentController.text, 'content': contentController.text,
if (aliasController.text.isNotEmpty) 'alias': aliasController.text,
if (titleController.text.isNotEmpty) 'title': titleController.text, if (titleController.text.isNotEmpty) 'title': titleController.text,
if (descriptionController.text.isNotEmpty) 'description': descriptionController.text, if (descriptionController.text.isNotEmpty) 'description': descriptionController.text,
if (thumbnail != null && thumbnail!.attachment != null) 'thumbnail': thumbnail!.attachment!.rid, if (thumbnail != null && thumbnail!.attachment != null) 'thumbnail': thumbnail!.attachment!.rid,

View File

@ -496,7 +496,7 @@ class _PostEditorScreenState extends State<PostEditorScreen> {
onPressed: (_writeController.isBusy || _writeController.publisher == null) onPressed: (_writeController.isBusy || _writeController.publisher == null)
? null ? null
: () { : () {
_writeController.post(context).then((_) { _writeController.sendPost(context).then((_) {
if (!context.mounted) return; if (!context.mounted) return;
Navigator.pop(context, true); Navigator.pop(context, true);
}); });

View File

@ -189,16 +189,19 @@ class PostMediaPendingList extends StatelessWidget {
child: AspectRatio( child: AspectRatio(
aspectRatio: 1, aspectRatio: 1,
child: switch (thumbnail!.type) { child: switch (thumbnail!.type) {
PostWriteMediaType.image => LayoutBuilder(builder: (context, constraints) { PostWriteMediaType.image => Container(
return Image( color: Theme.of(context).colorScheme.surfaceContainer,
image: thumbnail!.getImageProvider( child: LayoutBuilder(builder: (context, constraints) {
context, return Image(
width: (constraints.maxWidth * devicePixelRatio).round(), image: thumbnail!.getImageProvider(
height: (constraints.maxHeight * devicePixelRatio).round(), context,
)!, width: (constraints.maxWidth * devicePixelRatio).round(),
fit: BoxFit.contain, height: (constraints.maxHeight * devicePixelRatio).round(),
); )!,
}), fit: BoxFit.contain,
);
}),
),
_ => Container( _ => Container(
color: Theme.of(context).colorScheme.surface, color: Theme.of(context).colorScheme.surface,
child: const Icon(Symbols.docs).center(), child: const Icon(Symbols.docs).center(),
@ -236,18 +239,21 @@ class PostMediaPendingList extends StatelessWidget {
child: AspectRatio( child: AspectRatio(
aspectRatio: 1, aspectRatio: 1,
child: switch (media.type) { child: switch (media.type) {
PostWriteMediaType.image => LayoutBuilder(builder: (context, constraints) { PostWriteMediaType.image => Container(
return Image( color: Theme.of(context).colorScheme.surfaceContainer,
image: media.getImageProvider( child: LayoutBuilder(builder: (context, constraints) {
context, return Image(
width: (constraints.maxWidth * devicePixelRatio).round(), image: media.getImageProvider(
height: (constraints.maxHeight * devicePixelRatio).round(), context,
)!, width: (constraints.maxWidth * devicePixelRatio).round(),
fit: BoxFit.cover, height: (constraints.maxHeight * devicePixelRatio).round(),
); )!,
}), fit: BoxFit.contain,
);
}),
),
_ => Container( _ => Container(
color: Theme.of(context).colorScheme.surface, color: Theme.of(context).colorScheme.surfaceContainer,
child: const Icon(Symbols.docs).center(), child: const Icon(Symbols.docs).center(),
), ),
}, },

View File

@ -114,6 +114,18 @@ class PostMetaEditor extends StatelessWidget {
controller.setTags(value); controller.setTags(value);
}, },
).padding(horizontal: 24), ).padding(horizontal: 24),
const Gap(4),
TextField(
controller: controller.aliasController,
decoration: InputDecoration(
labelText: 'fieldPostAlias'.tr(),
helperText: 'fieldPostAliasHint'.tr(),
helperMaxLines: 2,
border: UnderlineInputBorder(),
),
onTapOutside: (_) =>
FocusManager.instance.primaryFocus?.unfocus(),
).padding(horizontal: 24),
const Gap(12), const Gap(12),
ListTile( ListTile(
contentPadding: const EdgeInsets.symmetric(horizontal: 24), contentPadding: const EdgeInsets.symmetric(horizontal: 24),

View File

@ -217,7 +217,7 @@ class _PostMiniEditorState extends State<PostMiniEditor> {
_writeController.publisher == null) _writeController.publisher == null)
? null ? null
: () { : () {
_writeController.post(context).then((_) { _writeController.sendPost(context).then((_) {
if (!context.mounted) return; if (!context.mounted) return;
if (widget.onPost != null) widget.onPost!(); if (widget.onPost != null) widget.onPost!();
context.showSnackbar('postPosted'.tr()); context.showSnackbar('postPosted'.tr());