Compare commits

...

2 Commits

Author SHA1 Message Date
bb77b74356 Able to post article 2024-07-30 16:53:13 +08:00
fc77c8693f Post editor able to edit article 2024-07-30 16:44:04 +08:00
5 changed files with 67 additions and 5 deletions

View File

@ -94,6 +94,7 @@ class PostEditorController extends GetxController {
'repost_to': repostTo.value?.toJson(),
'edit_to': editTo.value?.toJson(),
'realm': realmZone.value?.toJson(),
'type': type,
}),
);
}
@ -131,6 +132,7 @@ class PostEditorController extends GetxController {
return;
}
type = value.type;
editTo.value = value;
isDraft.value = value.isDraft ?? false;
titleController.text = value.body['title'] ?? '';
@ -142,6 +144,37 @@ class PostEditorController extends GetxController {
contentLength.value = contentController.text.length;
}
String get typeEndpoint {
switch(mode.value) {
case 0:
return 'stories';
case 1:
return 'articles';
default:
return 'stories';
}
}
String get type {
switch(mode.value) {
case 0:
return 'story';
case 1:
return 'article';
default:
return 'story';
}
}
set type(String value) {
switch (value) {
case 'story':
mode.value = 0;
case 'article':
mode.value = 1;
}
}
String? get title {
if (titleController.text.isEmpty) return null;
return titleController.text;
@ -168,6 +201,7 @@ class PostEditorController extends GetxController {
}
set payload(Map<String, dynamic> value) {
type = value['type'];
titleController.text = value['title'] ?? '';
descriptionController.text = value['description'] ?? '';
contentController.text = value['content'] ?? '';

View File

@ -12,6 +12,7 @@ class Post {
List<Tag>? tags;
List<Category>? categories;
List<Post>? replies;
String type;
int? replyId;
int? repostId;
int? realmId;
@ -31,6 +32,7 @@ class Post {
required this.updatedAt,
required this.editedAt,
required this.deletedAt,
required this.type,
required this.body,
required this.tags,
required this.categories,
@ -56,6 +58,7 @@ class Post {
deletedAt: json['deleted_at'] != null
? DateTime.parse(json['deleted_at'])
: null,
type: json['type'],
body: json['body'],
tags: json['tags']?.map((x) => Tag.fromJson(x)).toList().cast<Tag>(),
categories: json['categories']
@ -93,6 +96,7 @@ class Post {
'updated_at': updatedAt.toIso8601String(),
'edited_at': editedAt?.toIso8601String(),
'deleted_at': deletedAt?.toIso8601String(),
'type': type,
'body': body,
'tags': tags,
'categories': categories,

View File

@ -83,6 +83,7 @@ abstract class AppRouter {
reply: arguments?.reply,
repost: arguments?.repost,
realm: arguments?.realm,
mode: int.tryParse(state.uri.queryParameters['mode'] ?? '0') ?? 0,
);
},
),

View File

@ -136,11 +136,25 @@ class PostCreatePopup extends StatelessWidget {
final List<dynamic> actionList = [
(
icon: const Icon(Icons.edit_square),
icon: const Icon(Icons.post_add),
label: 'postEditorModeStory'.tr,
onTap: () {
Navigator.pop(context);
AppRouter.instance.pushNamed('postEditor').then((val) {
AppRouter.instance.pushNamed('postEditor', queryParameters: {
'mode': 0.toString(),
}).then((val) {
if (val != null && onCreated != null) onCreated!();
});
},
),
(
icon: const Icon(Icons.description),
label: 'postEditorModeArticle'.tr,
onTap: () {
Navigator.pop(context);
AppRouter.instance.pushNamed('postEditor', queryParameters: {
'mode': 1.toString(),
}).then((val) {
if (val != null && onCreated != null) onCreated!();
});
},

View File

@ -29,6 +29,7 @@ class PostPublishScreen extends StatefulWidget {
final Post? reply;
final Post? repost;
final Realm? realm;
final int mode;
const PostPublishScreen({
super.key,
@ -36,6 +37,7 @@ class PostPublishScreen extends StatefulWidget {
this.reply,
this.repost,
this.realm,
required this.mode,
});
@override
@ -59,12 +61,12 @@ class _PostPublishScreenState extends State<PostPublishScreen> {
Response resp;
if (widget.edit != null) {
resp = await client.put(
'/stories/${widget.edit!.id}',
'/${_editorController.typeEndpoint}/${widget.edit!.id}',
_editorController.payload,
);
} else {
resp = await client.post(
'/stories',
'/${_editorController.typeEndpoint}',
_editorController.payload,
);
}
@ -79,6 +81,7 @@ class _PostPublishScreenState extends State<PostPublishScreen> {
}
void syncWidget() {
_editorController.mode.value = widget.mode;
if (widget.edit != null) {
_editorController.editTarget = widget.edit;
}
@ -108,7 +111,13 @@ class _PostPublishScreenState extends State<PostPublishScreen> {
child: Scaffold(
appBar: AppBar(
leading: AppBarLeadingButton.adaptive(context),
title: AppBarTitle('postEditorModeStory'.tr),
title: Obx(
() => AppBarTitle(
_editorController.mode.value == 0
? 'postEditorModeStory'.tr
: 'postEditorModeArticle'.tr,
),
),
centerTitle: false,
toolbarHeight: SolianTheme.toolbarHeight(context),
actions: [