feat: use snjs tag notes index for note counts (#810)
* feat: use snjs tag notes index for note counts * style: clean up style * fix: typo on parent check (#811) * feat: use snjs tag notes index for note counts * chore: bump deps
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import { confirmDialog } from '@/services/alertService';
|
||||
import { STRING_DELETE_TAG, STRING_MISSING_SYSTEM_TAG } from '@/strings';
|
||||
import { STRING_DELETE_TAG } from '@/strings';
|
||||
import {
|
||||
ApplicationEvent,
|
||||
ComponentAction,
|
||||
ContentType,
|
||||
MessageData,
|
||||
@@ -9,7 +8,7 @@ import {
|
||||
SNSmartTag,
|
||||
SNTag,
|
||||
TagMutator,
|
||||
UuidString,
|
||||
UuidString
|
||||
} from '@standardnotes/snjs';
|
||||
import {
|
||||
action,
|
||||
@@ -17,7 +16,7 @@ import {
|
||||
makeAutoObservable,
|
||||
makeObservable,
|
||||
observable,
|
||||
runInAction,
|
||||
runInAction
|
||||
} from 'mobx';
|
||||
import { WebApplication } from '../application';
|
||||
import { FeaturesState, SMART_TAGS_FEATURE_NAME } from './features_state';
|
||||
@@ -126,9 +125,6 @@ export class TagsState {
|
||||
) as SNTag[];
|
||||
this.smartTags = this.application.getSmartTags();
|
||||
|
||||
this.tagsCountsState.update(this.tags);
|
||||
this.allNotesCount_ = this.countAllNotes();
|
||||
|
||||
const selectedTag = this.selected_;
|
||||
if (selectedTag) {
|
||||
const matchingTag = items.find(
|
||||
@@ -150,13 +146,13 @@ export class TagsState {
|
||||
);
|
||||
|
||||
appEventListeners.push(
|
||||
this.application.addEventObserver(async (eventName) => {
|
||||
switch (eventName) {
|
||||
case ApplicationEvent.CompletedIncrementalSync:
|
||||
runInAction(() => {
|
||||
this.allNotesCount_ = this.countAllNotes();
|
||||
});
|
||||
break;
|
||||
this.application.addNoteCountChangeObserver((tagUuid) => {
|
||||
if (!tagUuid) {
|
||||
this.allNotesCount_ = this.application.allCountableNotesCount();
|
||||
} else {
|
||||
this.tagsCountsState.update([
|
||||
this.application.findItem(tagUuid) as SNTag,
|
||||
]);
|
||||
}
|
||||
})
|
||||
);
|
||||
@@ -391,23 +387,6 @@ export class TagsState {
|
||||
}
|
||||
}
|
||||
|
||||
private countAllNotes(): number {
|
||||
const allTag = this.application.getSmartTags().find((tag) => tag.isAllTag);
|
||||
|
||||
if (!allTag) {
|
||||
console.error(STRING_MISSING_SYSTEM_TAG);
|
||||
return -1;
|
||||
}
|
||||
|
||||
const notes = this.application
|
||||
.notesMatchingSmartTag(allTag)
|
||||
.filter((note) => {
|
||||
return !note.archived && !note.trashed;
|
||||
});
|
||||
|
||||
return notes.length;
|
||||
}
|
||||
|
||||
public onFoldersComponentMessage(
|
||||
action: ComponentAction,
|
||||
data: MessageData
|
||||
@@ -440,9 +419,6 @@ export class TagsState {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Bug fix for issue 1201550111577311,
|
||||
*/
|
||||
class TagsCountsState {
|
||||
public counts: { [uuid: string]: number } = {};
|
||||
|
||||
@@ -454,13 +430,13 @@ class TagsCountsState {
|
||||
}
|
||||
|
||||
public update(tags: SNTag[]) {
|
||||
const newCounts: { [uuid: string]: number } = {};
|
||||
const newCounts: { [uuid: string]: number } = Object.assign(
|
||||
{},
|
||||
this.counts
|
||||
);
|
||||
|
||||
tags.forEach((tag) => {
|
||||
newCounts[tag.uuid] = this.application.referencesForItem(
|
||||
tag,
|
||||
ContentType.Note
|
||||
).length;
|
||||
newCounts[tag.uuid] = this.application.countableNotesForTag(tag);
|
||||
});
|
||||
|
||||
this.counts = newCounts;
|
||||
|
||||
Reference in New Issue
Block a user