💄 Better auto save
This commit is contained in:
parent
59c4d667f6
commit
db43b7dca5
@ -140,7 +140,7 @@
|
||||
"clear": "Clear",
|
||||
"pinPost": "Pin this post",
|
||||
"unpinPost": "Unpin this post",
|
||||
"postRestoreFromLocal": "Restore from local",
|
||||
"postRestoreFromLocal": "Restored",
|
||||
"postAutoSaveAt": "Auto saved at @date",
|
||||
"postCategoriesAndTags": "Categories n' Tags",
|
||||
"postPublishDate": "Publish Date",
|
||||
|
@ -43,14 +43,17 @@ class PostEditorController extends GetxController {
|
||||
|
||||
RxBool isRestoreFromLocal = false.obs;
|
||||
Rx<DateTime?> lastSaveTime = Rx(null);
|
||||
Timer? _saveTimer;
|
||||
Future? _saveFuture;
|
||||
|
||||
PostEditorController() {
|
||||
SharedPreferences.getInstance().then((inst) {
|
||||
_prefs = inst;
|
||||
_saveTimer = Timer.periodic(
|
||||
const Duration(seconds: 3),
|
||||
(Timer t) {
|
||||
});
|
||||
contentController.addListener(() {
|
||||
contentLength.value = contentController.text.length;
|
||||
_saveFuture ??= Future.delayed(
|
||||
const Duration(seconds: 1),
|
||||
() {
|
||||
if (isNotEmpty) {
|
||||
localSave();
|
||||
lastSaveTime.value = DateTime.now();
|
||||
@ -59,12 +62,10 @@ class PostEditorController extends GetxController {
|
||||
localClear();
|
||||
lastSaveTime.value = null;
|
||||
}
|
||||
_saveFuture = null;
|
||||
},
|
||||
);
|
||||
});
|
||||
contentController.addListener(() {
|
||||
contentLength.value = contentController.text.length;
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> editOverview(BuildContext context) {
|
||||
@ -355,8 +356,6 @@ class PostEditorController extends GetxController {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_saveTimer?.cancel();
|
||||
|
||||
titleController.dispose();
|
||||
descriptionController.dispose();
|
||||
contentController.dispose();
|
||||
|
Loading…
Reference in New Issue
Block a user