✨ Post editor able to edit article
This commit is contained in:
		@@ -94,6 +94,7 @@ class PostEditorController extends GetxController {
 | 
				
			|||||||
        'repost_to': repostTo.value?.toJson(),
 | 
					        'repost_to': repostTo.value?.toJson(),
 | 
				
			||||||
        'edit_to': editTo.value?.toJson(),
 | 
					        'edit_to': editTo.value?.toJson(),
 | 
				
			||||||
        'realm': realmZone.value?.toJson(),
 | 
					        'realm': realmZone.value?.toJson(),
 | 
				
			||||||
 | 
					        'type': type,
 | 
				
			||||||
      }),
 | 
					      }),
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@@ -131,6 +132,7 @@ class PostEditorController extends GetxController {
 | 
				
			|||||||
      return;
 | 
					      return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    type = value.type;
 | 
				
			||||||
    editTo.value = value;
 | 
					    editTo.value = value;
 | 
				
			||||||
    isDraft.value = value.isDraft ?? false;
 | 
					    isDraft.value = value.isDraft ?? false;
 | 
				
			||||||
    titleController.text = value.body['title'] ?? '';
 | 
					    titleController.text = value.body['title'] ?? '';
 | 
				
			||||||
@@ -142,6 +144,37 @@ class PostEditorController extends GetxController {
 | 
				
			|||||||
    contentLength.value = contentController.text.length;
 | 
					    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 {
 | 
					  String? get title {
 | 
				
			||||||
    if (titleController.text.isEmpty) return null;
 | 
					    if (titleController.text.isEmpty) return null;
 | 
				
			||||||
    return titleController.text;
 | 
					    return titleController.text;
 | 
				
			||||||
@@ -168,6 +201,7 @@ class PostEditorController extends GetxController {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  set payload(Map<String, dynamic> value) {
 | 
					  set payload(Map<String, dynamic> value) {
 | 
				
			||||||
 | 
					    type = value['type'];
 | 
				
			||||||
    titleController.text = value['title'] ?? '';
 | 
					    titleController.text = value['title'] ?? '';
 | 
				
			||||||
    descriptionController.text = value['description'] ?? '';
 | 
					    descriptionController.text = value['description'] ?? '';
 | 
				
			||||||
    contentController.text = value['content'] ?? '';
 | 
					    contentController.text = value['content'] ?? '';
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -12,6 +12,7 @@ class Post {
 | 
				
			|||||||
  List<Tag>? tags;
 | 
					  List<Tag>? tags;
 | 
				
			||||||
  List<Category>? categories;
 | 
					  List<Category>? categories;
 | 
				
			||||||
  List<Post>? replies;
 | 
					  List<Post>? replies;
 | 
				
			||||||
 | 
					  String type;
 | 
				
			||||||
  int? replyId;
 | 
					  int? replyId;
 | 
				
			||||||
  int? repostId;
 | 
					  int? repostId;
 | 
				
			||||||
  int? realmId;
 | 
					  int? realmId;
 | 
				
			||||||
@@ -31,6 +32,7 @@ class Post {
 | 
				
			|||||||
    required this.updatedAt,
 | 
					    required this.updatedAt,
 | 
				
			||||||
    required this.editedAt,
 | 
					    required this.editedAt,
 | 
				
			||||||
    required this.deletedAt,
 | 
					    required this.deletedAt,
 | 
				
			||||||
 | 
					    required this.type,
 | 
				
			||||||
    required this.body,
 | 
					    required this.body,
 | 
				
			||||||
    required this.tags,
 | 
					    required this.tags,
 | 
				
			||||||
    required this.categories,
 | 
					    required this.categories,
 | 
				
			||||||
@@ -56,6 +58,7 @@ class Post {
 | 
				
			|||||||
        deletedAt: json['deleted_at'] != null
 | 
					        deletedAt: json['deleted_at'] != null
 | 
				
			||||||
            ? DateTime.parse(json['deleted_at'])
 | 
					            ? DateTime.parse(json['deleted_at'])
 | 
				
			||||||
            : null,
 | 
					            : null,
 | 
				
			||||||
 | 
					        type: json['type'],
 | 
				
			||||||
        body: json['body'],
 | 
					        body: json['body'],
 | 
				
			||||||
        tags: json['tags']?.map((x) => Tag.fromJson(x)).toList().cast<Tag>(),
 | 
					        tags: json['tags']?.map((x) => Tag.fromJson(x)).toList().cast<Tag>(),
 | 
				
			||||||
        categories: json['categories']
 | 
					        categories: json['categories']
 | 
				
			||||||
@@ -93,6 +96,7 @@ class Post {
 | 
				
			|||||||
        'updated_at': updatedAt.toIso8601String(),
 | 
					        'updated_at': updatedAt.toIso8601String(),
 | 
				
			||||||
        'edited_at': editedAt?.toIso8601String(),
 | 
					        'edited_at': editedAt?.toIso8601String(),
 | 
				
			||||||
        'deleted_at': deletedAt?.toIso8601String(),
 | 
					        'deleted_at': deletedAt?.toIso8601String(),
 | 
				
			||||||
 | 
					        'type': type,
 | 
				
			||||||
        'body': body,
 | 
					        'body': body,
 | 
				
			||||||
        'tags': tags,
 | 
					        'tags': tags,
 | 
				
			||||||
        'categories': categories,
 | 
					        'categories': categories,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -59,12 +59,12 @@ class _PostPublishScreenState extends State<PostPublishScreen> {
 | 
				
			|||||||
    Response resp;
 | 
					    Response resp;
 | 
				
			||||||
    if (widget.edit != null) {
 | 
					    if (widget.edit != null) {
 | 
				
			||||||
      resp = await client.put(
 | 
					      resp = await client.put(
 | 
				
			||||||
        '/stories/${widget.edit!.id}',
 | 
					        '/${_editorController.typeEndpoint}/${widget.edit!.id}',
 | 
				
			||||||
        _editorController.payload,
 | 
					        _editorController.payload,
 | 
				
			||||||
      );
 | 
					      );
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
      resp = await client.post(
 | 
					      resp = await client.post(
 | 
				
			||||||
        '/stories',
 | 
					        '/${_editorController.typeEndpoint}',
 | 
				
			||||||
        _editorController.payload,
 | 
					        _editorController.payload,
 | 
				
			||||||
      );
 | 
					      );
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user