Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/common/actions/notes/labels.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ Future<List<Label>?> selectLabels(BuildContext context, WidgetRef ref, {required
.editLabels(note, selectedLabels);

currentNoteNotifier.value = note;
// Forcefully notify the listeners
// because the note object as been modified in memory
currentNoteNotifier.notify();

return selectedLabels;
}
Expand Down
7 changes: 7 additions & 0 deletions lib/pages/notes/notes_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ class NotesPage extends ConsumerStatefulWidget {
}

class _NotesPageState extends ConsumerState<NotesPage> {
@override
void initState() {
super.initState();

currentLabelFilter = widget.label;
}

@override
void dispose() {
currentLabelFilter = null;
Expand Down
15 changes: 15 additions & 0 deletions lib/providers/notes/notes_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ class Notes extends _$Notes {
Future<bool> editLabels(Note note, Iterable<Label> selectedLabels) async {
_checkStatus([NoteStatus.available, NoteStatus.archived]);

final removedLabels = note.labels.toList().where((label) => !selectedLabels.contains(label));

try {
await _notesService.putLabels(note, selectedLabels);
} catch (exception, stackTrace) {
Expand All @@ -104,6 +106,7 @@ class Notes extends _$Notes {

state = AsyncData(notes.sorted());
_updateUnlabeledProvider();
_updateLabeledProviders([...removedLabels, ...selectedLabels]);

return true;
}
Expand All @@ -126,6 +129,7 @@ class Notes extends _$Notes {

state = AsyncData(notes.sorted());
_updateUnlabeledProvider();
_updateLabeledProviders(selectedLabels);

return true;
}
Expand Down Expand Up @@ -333,6 +337,17 @@ class Notes extends _$Notes {
}
}

/// Updates the labeled notes providers except this one it is a provider filtered by a label.
void _updateLabeledProviders(Iterable<Label> labels) {
for (final label in labels) {
if (label == this.label) {
continue;
}

ref.read(notesProvider(status: status, label: label).notifier).get();
}
}

/// Updates the notes provider with the [status].
void _updateStatusProvider(NoteStatus status) {
ref.read(notesProvider(status: status).notifier).get();
Expand Down
12 changes: 5 additions & 7 deletions lib/providers/notifiers/current_note_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@ class CurrentNoteNotifier extends ValueNotifier<Note?> {
/// Sets the current note to [newNote].
@override
set value(Note? newNote) {
if (newNote == null) {
return;
}
_value = newNote;

if (_value == newNote && _value?.labels == newNote.labels) {
return;
}
notifyListeners();
}

_value = newNote;
/// Notifies the listeners.
void notify() {
notifyListeners();
}
}
2 changes: 1 addition & 1 deletion lib/providers/notifiers/notifiers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ final lockAppNotifier = LockNotifier(PreferenceKey.lockApp.preferenceOrDefault);
/// Notifier for whether the current note is locked.
final lockNoteNotifier = LockNotifier(false);

/// Notifier for the value of the current label filter on the notes.
/// The value of the current label filter on the notes.
Label? currentLabelFilter;

/// Notifier for whether the notes selection mode is active.
Expand Down
Loading