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:
Mo
2022-01-17 07:47:25 -06:00
committed by GitHub
parent b0544dc2ef
commit 5e0769745c
3 changed files with 38 additions and 62 deletions

View File

@@ -1,7 +1,6 @@
import { confirmDialog } from '@/services/alertService'; import { confirmDialog } from '@/services/alertService';
import { STRING_DELETE_TAG, STRING_MISSING_SYSTEM_TAG } from '@/strings'; import { STRING_DELETE_TAG } from '@/strings';
import { import {
ApplicationEvent,
ComponentAction, ComponentAction,
ContentType, ContentType,
MessageData, MessageData,
@@ -9,7 +8,7 @@ import {
SNSmartTag, SNSmartTag,
SNTag, SNTag,
TagMutator, TagMutator,
UuidString, UuidString
} from '@standardnotes/snjs'; } from '@standardnotes/snjs';
import { import {
action, action,
@@ -17,7 +16,7 @@ import {
makeAutoObservable, makeAutoObservable,
makeObservable, makeObservable,
observable, observable,
runInAction, runInAction
} from 'mobx'; } from 'mobx';
import { WebApplication } from '../application'; import { WebApplication } from '../application';
import { FeaturesState, SMART_TAGS_FEATURE_NAME } from './features_state'; import { FeaturesState, SMART_TAGS_FEATURE_NAME } from './features_state';
@@ -126,9 +125,6 @@ export class TagsState {
) as SNTag[]; ) as SNTag[];
this.smartTags = this.application.getSmartTags(); this.smartTags = this.application.getSmartTags();
this.tagsCountsState.update(this.tags);
this.allNotesCount_ = this.countAllNotes();
const selectedTag = this.selected_; const selectedTag = this.selected_;
if (selectedTag) { if (selectedTag) {
const matchingTag = items.find( const matchingTag = items.find(
@@ -150,13 +146,13 @@ export class TagsState {
); );
appEventListeners.push( appEventListeners.push(
this.application.addEventObserver(async (eventName) => { this.application.addNoteCountChangeObserver((tagUuid) => {
switch (eventName) { if (!tagUuid) {
case ApplicationEvent.CompletedIncrementalSync: this.allNotesCount_ = this.application.allCountableNotesCount();
runInAction(() => { } else {
this.allNotesCount_ = this.countAllNotes(); this.tagsCountsState.update([
}); this.application.findItem(tagUuid) as SNTag,
break; ]);
} }
}) })
); );
@@ -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( public onFoldersComponentMessage(
action: ComponentAction, action: ComponentAction,
data: MessageData data: MessageData
@@ -440,9 +419,6 @@ export class TagsState {
} }
} }
/**
* Bug fix for issue 1201550111577311,
*/
class TagsCountsState { class TagsCountsState {
public counts: { [uuid: string]: number } = {}; public counts: { [uuid: string]: number } = {};
@@ -454,13 +430,13 @@ class TagsCountsState {
} }
public update(tags: SNTag[]) { public update(tags: SNTag[]) {
const newCounts: { [uuid: string]: number } = {}; const newCounts: { [uuid: string]: number } = Object.assign(
{},
this.counts
);
tags.forEach((tag) => { tags.forEach((tag) => {
newCounts[tag.uuid] = this.application.referencesForItem( newCounts[tag.uuid] = this.application.countableNotesForTag(tag);
tag,
ContentType.Note
).length;
}); });
this.counts = newCounts; this.counts = newCounts;

View File

@@ -86,8 +86,8 @@
"@reach/listbox": "^0.16.2", "@reach/listbox": "^0.16.2",
"@reach/tooltip": "^0.16.2", "@reach/tooltip": "^0.16.2",
"@standardnotes/components": "1.4.0", "@standardnotes/components": "1.4.0",
"@standardnotes/features": "1.24.0", "@standardnotes/features": "1.24.3",
"@standardnotes/snjs": "2.38.0", "@standardnotes/snjs": "2.40.0",
"@standardnotes/settings": "^1.9.0", "@standardnotes/settings": "^1.9.0",
"@standardnotes/sncrypto-web": "1.6.0", "@standardnotes/sncrypto-web": "1.6.0",
"mobx": "^6.3.5", "mobx": "^6.3.5",

View File

@@ -2597,10 +2597,10 @@
dependencies: dependencies:
"@sinonjs/commons" "^1.7.0" "@sinonjs/commons" "^1.7.0"
"@standardnotes/auth@^3.14.1": "@standardnotes/auth@^3.15.2":
version "3.14.1" version "3.15.2"
resolved "https://registry.yarnpkg.com/@standardnotes/auth/-/auth-3.14.1.tgz#4719dd60590bbf8062aa83a293e1fcd8a616f13e" resolved "https://registry.yarnpkg.com/@standardnotes/auth/-/auth-3.15.2.tgz#63a47785191e2a9f6761320375c76d9b3a0caf64"
integrity sha512-Phnp0FtP11ZhqByRyuIEFJxT0Z20KfcTn2yTwi6XIkPBuQFR152p924pFbv57w9/rVN6Tr10kCZ32Y5rk5owRQ== integrity sha512-fN497p0eyG4mp13vvhRD6ULyPMT7QAl3wRyBZMsNlNBuGQJNMS1rfSsU9u59AeAifkyARnfl+8SzVtwXKHlSSg==
dependencies: dependencies:
"@standardnotes/common" "^1.8.0" "@standardnotes/common" "^1.8.0"
jsonwebtoken "^8.5.1" jsonwebtoken "^8.5.1"
@@ -2615,19 +2615,19 @@
resolved "https://registry.yarnpkg.com/@standardnotes/components/-/components-1.4.0.tgz#0bb790965683b3fa56e3231b95cad9871e1db271" resolved "https://registry.yarnpkg.com/@standardnotes/components/-/components-1.4.0.tgz#0bb790965683b3fa56e3231b95cad9871e1db271"
integrity sha512-8Zo2WV7Q+pWdmAf+rG3NCNtVM4N1P52T1sDijapz8xqtArT28wxWZkJ+qfBJ0lT5GmXxYZl8rY/tAkx4hQ5zSA== integrity sha512-8Zo2WV7Q+pWdmAf+rG3NCNtVM4N1P52T1sDijapz8xqtArT28wxWZkJ+qfBJ0lT5GmXxYZl8rY/tAkx4hQ5zSA==
"@standardnotes/domain-events@^2.16.5": "@standardnotes/domain-events@^2.16.8":
version "2.16.5" version "2.16.8"
resolved "https://registry.yarnpkg.com/@standardnotes/domain-events/-/domain-events-2.16.5.tgz#9f7817100885ea55ccc0f49501c4e4c7bf32c649" resolved "https://registry.yarnpkg.com/@standardnotes/domain-events/-/domain-events-2.16.8.tgz#74e6a9879c9b4476d92a16253ae9d75cab4b8162"
integrity sha512-v4r/btJbv1AQ/NLs3AtiEbNKxOyujYmSD/DbUX7F9Td/DqBFNhIzrFQx7GB1hRDvVFwq9iIY3oAIZShEOlLJSg== integrity sha512-VHXEtXSNb01ensASq0d1iB4yMUdgBVlfeHp2LQNwK8fwtvdQOyPCfnOFdMaUjW+Y/nBFRz6swDtrLFLeknzlcw==
dependencies: dependencies:
"@standardnotes/auth" "^3.14.1" "@standardnotes/auth" "^3.15.2"
"@standardnotes/features@1.24.0", "@standardnotes/features@^1.24.0": "@standardnotes/features@1.24.3", "@standardnotes/features@^1.24.3":
version "1.24.0" version "1.24.3"
resolved "https://registry.yarnpkg.com/@standardnotes/features/-/features-1.24.0.tgz#1d5060971d3cfb19dd44e598aa1f7e2f9800a3a0" resolved "https://registry.yarnpkg.com/@standardnotes/features/-/features-1.24.3.tgz#f59616b1de7dba30a05e983ac53e6d86e6e2a503"
integrity sha512-566hhMohQlH6lLZYlfaI4j2+iGOwZh7DBQ0wC9chdchbJtmzmwA8c7m6d2sHpziM6qj234EO7xbtjE4m8CPQuQ== integrity sha512-WgI+aUcPZgJexir1ceAR5aumsnXUiLL3VtFHPlIOoSKsnfbcTYgizMkdhxI+CeBV+kKCOUGqTGEjXdaXZajO7g==
dependencies: dependencies:
"@standardnotes/auth" "^3.14.1" "@standardnotes/auth" "^3.15.2"
"@standardnotes/common" "^1.8.0" "@standardnotes/common" "^1.8.0"
"@standardnotes/settings@^1.9.0": "@standardnotes/settings@^1.9.0":
@@ -2649,15 +2649,15 @@
buffer "^6.0.3" buffer "^6.0.3"
libsodium-wrappers "^0.7.9" libsodium-wrappers "^0.7.9"
"@standardnotes/snjs@2.38.0": "@standardnotes/snjs@2.40.0":
version "2.38.0" version "2.40.0"
resolved "https://registry.yarnpkg.com/@standardnotes/snjs/-/snjs-2.38.0.tgz#8ed8a43efed40635e92e1f08162b29f59bee5027" resolved "https://registry.yarnpkg.com/@standardnotes/snjs/-/snjs-2.40.0.tgz#8b4e96bd11bdf4ea7f5c9d1cff869ad1a309245a"
integrity sha512-5O5fNZ1O4u3t1Jjfs54k7bzpxusGXr9+R598OJXk5O4TdFlMxSxIiZReY/SpAq2qUMgUOpyGnsYsYXbxTiQh9A== integrity sha512-UBlMFp8Dj88snSKmi9vUVn97/EM5aidIWhZXQcFa1/OZHg7HVUbIPrLSVy8ftY6WNCPDXjNSE0cy2fozN9W2rQ==
dependencies: dependencies:
"@standardnotes/auth" "^3.14.1" "@standardnotes/auth" "^3.15.2"
"@standardnotes/common" "^1.8.0" "@standardnotes/common" "^1.8.0"
"@standardnotes/domain-events" "^2.16.5" "@standardnotes/domain-events" "^2.16.8"
"@standardnotes/features" "^1.24.0" "@standardnotes/features" "^1.24.3"
"@standardnotes/settings" "^1.9.0" "@standardnotes/settings" "^1.9.0"
"@standardnotes/sncrypto-common" "^1.6.0" "@standardnotes/sncrypto-common" "^1.6.0"