fix: do not display single note tags when viewing said tag

This commit is contained in:
Baptiste Grob
2020-10-26 15:50:44 +01:00
parent d1e0101675
commit 5cd7aa908b

View File

@@ -355,15 +355,12 @@ class NotesViewCtrl extends PureViewCtrl<{}, NotesState> {
if (!tag) {
return;
}
const notes = this.application.getDisplayableItems(ContentType.Note) as SNNote[];
const notes = this.application.getDisplayableItems(
ContentType.Note
) as SNNote[];
const renderedNotes = notes.slice(0, this.notesToDisplay);
const renderedNotesTags = this.state.hideTags
? []
: renderedNotes.map((note) =>
this.appState.getNoteTags(note)
.map(tag => "#" + tag.title)
.join(" ")
);
const renderedNotesTags = this.notesTagsList(renderedNotes);
await this.setNotesState({
notes,
renderedNotesTags,
@@ -372,6 +369,33 @@ class NotesViewCtrl extends PureViewCtrl<{}, NotesState> {
this.reloadPanelTitle();
}
private notesTagsList(notes: SNNote[]): string[] {
if (this.state.hideTags) {
return [];
} else {
const selectedTag = this.appState.selectedTag;
if (!selectedTag) {
return [];
} else if (selectedTag?.isSmartTag()) {
return notes.map((note) =>
this.appState
.getNoteTags(note)
.map((tag) => '#' + tag.title)
.join(' ')
);
} else {
/**
* Displaying a normal tag, hide the note's tag when there's only one
*/
return notes.map((note) => {
const tags = this.appState.getNoteTags(note);
if (tags.length === 1) return '';
return tags.map((tag) => '#' + tag.title).join(' ');
});
}
}
}
setShowMenuFalse() {
this.setNotesState({
mutable: {