mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-29 10:17:16 +08:00
Note: Store when last modified
Also sort the notes based on when last modified. Now that we're moving towards being a more note-taking app, it makes sense that a recently modified note goes on top. Of course, the sorting should be controllable by the user, but the default probably should be by when modified.
This commit is contained in:
@ -18,6 +18,7 @@ class Note with ChangeNotifier implements Comparable<Note> {
|
|||||||
String filePath = "";
|
String filePath = "";
|
||||||
|
|
||||||
DateTime _created;
|
DateTime _created;
|
||||||
|
DateTime _modified;
|
||||||
NoteData _data = NoteData();
|
NoteData _data = NoteData();
|
||||||
|
|
||||||
DateTime _fileLastModified;
|
DateTime _fileLastModified;
|
||||||
@ -44,6 +45,25 @@ class Note with ChangeNotifier implements Comparable<Note> {
|
|||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DateTime get modified {
|
||||||
|
return _modified;
|
||||||
|
}
|
||||||
|
|
||||||
|
set modified(DateTime dt) {
|
||||||
|
_modified = dt;
|
||||||
|
|
||||||
|
if (hasValidDate()) {
|
||||||
|
_data.props['modified'] = toIso8601WithTimezone(_modified);
|
||||||
|
} else {
|
||||||
|
_data.props.remove('modified');
|
||||||
|
}
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateModified() {
|
||||||
|
modified = DateTime.now();
|
||||||
|
}
|
||||||
|
|
||||||
String get body {
|
String get body {
|
||||||
return data.body;
|
return data.body;
|
||||||
}
|
}
|
||||||
@ -153,7 +173,7 @@ class Note with ChangeNotifier implements Comparable<Note> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'Note{filePath: $filePath, created: $created, data: $data}';
|
return 'Note{filePath: $filePath, created: $created, modified: $modified, data: $data}';
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -161,7 +181,7 @@ class Note with ChangeNotifier implements Comparable<Note> {
|
|||||||
if (other == null) {
|
if (other == null) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (created == other.created) return filePath.compareTo(other.filePath);
|
if (modified == other.modified) return filePath.compareTo(other.filePath);
|
||||||
return created.compareTo(other.created);
|
return modified.compareTo(other.modified);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -154,6 +154,7 @@ class StateContainerState extends State<StateContainer> {
|
|||||||
note.filePath = p.join(parentPath, getFileName(note));
|
note.filePath = p.join(parentPath, getFileName(note));
|
||||||
}
|
}
|
||||||
note.parent.insert(index, note);
|
note.parent.insert(index, note);
|
||||||
|
note.updateModified();
|
||||||
_gitRepo.addNote(note).then((NoteRepoResult _) {
|
_gitRepo.addNote(note).then((NoteRepoResult _) {
|
||||||
syncNotes();
|
syncNotes();
|
||||||
});
|
});
|
||||||
@ -161,6 +162,7 @@ class StateContainerState extends State<StateContainer> {
|
|||||||
|
|
||||||
void updateNote(Note note) {
|
void updateNote(Note note) {
|
||||||
Fimber.d("State Container updateNote");
|
Fimber.d("State Container updateNote");
|
||||||
|
note.updateModified();
|
||||||
_gitRepo.updateNote(note).then((NoteRepoResult _) {
|
_gitRepo.updateNote(note).then((NoteRepoResult _) {
|
||||||
syncNotes();
|
syncNotes();
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user