From 2b3a58b55e0dd4961659fdb6a8bab23aad1cbed9 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Mon, 6 Jan 2025 22:12:10 +0800 Subject: [PATCH] :wheelchair: Optimize temporary save post scenario --- lib/controllers/post_write_controller.dart | 8 ++++++-- lib/screens/post/post_editor.dart | 4 +++- lib/widgets/post/post_mini_editor.dart | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/controllers/post_write_controller.dart b/lib/controllers/post_write_controller.dart index 77749ff..0593eb5 100644 --- a/lib/controllers/post_write_controller.dart +++ b/lib/controllers/post_write_controller.dart @@ -154,7 +154,10 @@ class PostWriteController extends ChangeNotifier { final TextEditingController descriptionController = TextEditingController(); final TextEditingController aliasController = TextEditingController(); - PostWriteController() { + bool _temporarySaveActive = false; + + PostWriteController({bool doLoadFromTemporary = true}) { + _temporarySaveActive = doLoadFromTemporary; titleController.addListener(() { _temporaryPlanSave(); notifyListeners(); @@ -166,7 +169,7 @@ class PostWriteController extends ChangeNotifier { contentController.addListener(() { _temporaryPlanSave(); }); - _temporaryLoad(); + if (doLoadFromTemporary) _temporaryLoad(); } String mode = kTitleMap.keys.first; @@ -317,6 +320,7 @@ class PostWriteController extends ChangeNotifier { Timer? _temporarySaveTimer; void _temporaryPlanSave() { + if (!_temporarySaveActive) return; _temporarySaveTimer?.cancel(); _temporarySaveTimer = Timer(const Duration(seconds: 1), () { _temporarySave(); diff --git a/lib/screens/post/post_editor.dart b/lib/screens/post/post_editor.dart index 47e2770..309223c 100644 --- a/lib/screens/post/post_editor.dart +++ b/lib/screens/post/post_editor.dart @@ -54,7 +54,9 @@ class PostEditorScreen extends StatefulWidget { } class _PostEditorScreenState extends State { - final PostWriteController _writeController = PostWriteController(); + late final PostWriteController _writeController = PostWriteController( + doLoadFromTemporary: widget.postEditId == null, + ); bool _isFetching = false; diff --git a/lib/widgets/post/post_mini_editor.dart b/lib/widgets/post/post_mini_editor.dart index 676a211..a9fd8b8 100644 --- a/lib/widgets/post/post_mini_editor.dart +++ b/lib/widgets/post/post_mini_editor.dart @@ -25,7 +25,7 @@ class PostMiniEditor extends StatefulWidget { } class _PostMiniEditorState extends State { - final PostWriteController _writeController = PostWriteController(); + final PostWriteController _writeController = PostWriteController(doLoadFromTemporary: false); bool _isFetching = false;