From 9f032f13c2341503eb84fa165dd6bdf8c614f16d Mon Sep 17 00:00:00 2001 From: Mo Date: Mon, 21 Mar 2022 14:31:42 -0500 Subject: [PATCH] chore: upgrade deps --- .../components/Abstract/PureComponent.tsx | 2 +- .../AttachedFilesPopover.tsx | 2 +- .../javascripts/components/CircleProgress.tsx | 38 ---------- .../components/CircleProgressTime.tsx | 27 ------- app/assets/javascripts/components/Footer.tsx | 7 +- .../components/NotesListOptionsMenu.tsx | 2 +- .../components/OtherSessionsSignOut.tsx | 3 +- .../components/Preferences/PreferencesMenu.ts | 2 +- .../Preferences/panes/Appearance.tsx | 2 +- .../Preferences/panes/Extensions.tsx | 2 +- .../QuickSettingsMenu/QuickSettingsMenu.tsx | 6 +- .../RevisionHistoryModalWrapper.tsx | 4 +- .../components/RevisionPreviewModal.tsx | 4 +- .../components/Tags/TagsSection.tsx | 4 +- app/assets/javascripts/database.ts | 73 +++++++++---------- .../javascripts/services/desktopManager.ts | 2 +- .../javascripts/services/themeManager.ts | 15 ++-- .../ui_models/app_state/account_menu_state.ts | 2 +- .../ui_models/app_state/app_state.ts | 10 ++- .../app_state/no_account_warning_state.ts | 10 +-- .../ui_models/app_state/note_tags_state.ts | 10 +-- .../ui_models/app_state/notes_state.ts | 12 +-- .../ui_models/app_state/notes_view_state.ts | 4 +- .../ui_models/app_state/sync_state.ts | 6 +- .../ui_models/app_state/tags_state.ts | 67 ++++++++++------- package.json | 2 +- yarn.lock | 8 +- 27 files changed, 143 insertions(+), 183 deletions(-) delete mode 100644 app/assets/javascripts/components/CircleProgress.tsx delete mode 100644 app/assets/javascripts/components/CircleProgressTime.tsx diff --git a/app/assets/javascripts/components/Abstract/PureComponent.tsx b/app/assets/javascripts/components/Abstract/PureComponent.tsx index 9a56d834d..ef6fac1f4 100644 --- a/app/assets/javascripts/components/Abstract/PureComponent.tsx +++ b/app/assets/javascripts/components/Abstract/PureComponent.tsx @@ -78,7 +78,7 @@ export abstract class PureComponent< ); } - onAppStateEvent(eventName: any, data: any) { + onAppStateEvent(_eventName: any, _data: any) { /** Optional override */ } diff --git a/app/assets/javascripts/components/AttachedFilesPopover/AttachedFilesPopover.tsx b/app/assets/javascripts/components/AttachedFilesPopover/AttachedFilesPopover.tsx index 4a9cf03aa..203509dc5 100644 --- a/app/assets/javascripts/components/AttachedFilesPopover/AttachedFilesPopover.tsx +++ b/app/assets/javascripts/components/AttachedFilesPopover/AttachedFilesPopover.tsx @@ -68,7 +68,7 @@ export const AttachedFilesPopover: FunctionComponent = observer( ); setAllFiles( - application + application.items .getItems(ContentType.File) .sort((a, b) => a.created_at < b.created_at ? 1 : -1 diff --git a/app/assets/javascripts/components/CircleProgress.tsx b/app/assets/javascripts/components/CircleProgress.tsx deleted file mode 100644 index 16fa917dc..000000000 --- a/app/assets/javascripts/components/CircleProgress.tsx +++ /dev/null @@ -1,38 +0,0 @@ -import { FunctionComponent } from 'preact'; - -export const CircleProgress: FunctionComponent<{ - percent: number; - className?: string; -}> = ({ percent, className = '' }) => { - const size = 16; - const ratioStrokeRadius = 0.25; - const outerRadius = size / 2; - - const radius = outerRadius * (1 - ratioStrokeRadius); - const stroke = outerRadius - radius; - - const circumference = radius * 2 * Math.PI; - const offset = circumference - (percent / 100) * circumference; - - const transition = `transition: 0.35s stroke-dashoffset;`; - const transform = `transform: rotate(-90deg);`; - const transformOrigin = `transform-origin: 50% 50%;`; - const dasharray = `stroke-dasharray: ${circumference} ${circumference};`; - const dashoffset = `stroke-dashoffset: ${offset};`; - const style = `${transition} ${transform} ${transformOrigin} ${dasharray} ${dashoffset}`; - return ( -
- - - -
- ); -}; diff --git a/app/assets/javascripts/components/CircleProgressTime.tsx b/app/assets/javascripts/components/CircleProgressTime.tsx deleted file mode 100644 index 1f7b6b7d9..000000000 --- a/app/assets/javascripts/components/CircleProgressTime.tsx +++ /dev/null @@ -1,27 +0,0 @@ -import { FunctionalComponent } from 'preact'; -import { useEffect, useState } from 'preact/hooks'; -import { CircleProgress } from './CircleProgress'; - -/** - * Circular progress bar which runs in a specified time interval - * @param time - time interval in ms - */ -export const CircleProgressTime: FunctionalComponent<{ time: number }> = ({ - time, -}) => { - const [percent, setPercent] = useState(0); - const interval = time / 100; - useEffect(() => { - const tick = setInterval(() => { - if (percent === 100) { - setPercent(0); - } else { - setPercent(percent + 1); - } - }, interval); - return () => { - clearInterval(tick); - }; - }); - return ; -}; diff --git a/app/assets/javascripts/components/Footer.tsx b/app/assets/javascripts/components/Footer.tsx index b96437a79..150392624 100644 --- a/app/assets/javascripts/components/Footer.tsx +++ b/app/assets/javascripts/components/Footer.tsx @@ -212,7 +212,10 @@ export class Footer extends PureComponent { } if (!this.didCheckForOffline) { this.didCheckForOffline = true; - if (this.state.offline && this.application.getNoteCount() === 0) { + if ( + this.state.offline && + this.application.items.getNoteCount() === 0 + ) { this.appState.accountMenu.setShow(true); } } @@ -244,7 +247,7 @@ export class Footer extends PureComponent { } streamItems() { - this.application.setDisplayOptions( + this.application.items.setDisplayOptions( ContentType.Theme, CollectionSort.Title, 'asc', diff --git a/app/assets/javascripts/components/NotesListOptionsMenu.tsx b/app/assets/javascripts/components/NotesListOptionsMenu.tsx index 05119e31b..a701d6df0 100644 --- a/app/assets/javascripts/components/NotesListOptionsMenu.tsx +++ b/app/assets/javascripts/components/NotesListOptionsMenu.tsx @@ -2,7 +2,7 @@ import { WebApplication } from '@/ui_models/application'; import { CollectionSort, PrefKey } from '@standardnotes/snjs'; import { observer } from 'mobx-react-lite'; import { FunctionComponent } from 'preact'; -import { useRef, useState } from 'preact/hooks'; +import { useState } from 'preact/hooks'; import { Icon } from './Icon'; import { Menu } from './Menu/Menu'; import { MenuItem, MenuItemSeparator, MenuItemType } from './Menu/MenuItem'; diff --git a/app/assets/javascripts/components/OtherSessionsSignOut.tsx b/app/assets/javascripts/components/OtherSessionsSignOut.tsx index c12b6b500..129e6d6ad 100644 --- a/app/assets/javascripts/components/OtherSessionsSignOut.tsx +++ b/app/assets/javascripts/components/OtherSessionsSignOut.tsx @@ -1,4 +1,4 @@ -import { useRef, useState } from 'preact/hooks'; +import { useRef } from 'preact/hooks'; import { AlertDialog, AlertDialogDescription, @@ -7,7 +7,6 @@ import { import { WebApplication } from '@/ui_models/application'; import { AppState } from '@/ui_models/app_state'; import { observer } from 'mobx-react-lite'; -import { FunctionComponent } from 'preact'; type Props = { application: WebApplication; diff --git a/app/assets/javascripts/components/Preferences/PreferencesMenu.ts b/app/assets/javascripts/components/Preferences/PreferencesMenu.ts index 5ddace53f..b9b474f63 100644 --- a/app/assets/javascripts/components/Preferences/PreferencesMenu.ts +++ b/app/assets/javascripts/components/Preferences/PreferencesMenu.ts @@ -113,7 +113,7 @@ export class PreferencesMenu { FeatureIdentifier.CloudLink, ]; this._extensionPanes = ( - this.application.getItems([ + this.application.items.getItems([ ContentType.ActionsExtension, ContentType.Component, ContentType.Theme, diff --git a/app/assets/javascripts/components/Preferences/panes/Appearance.tsx b/app/assets/javascripts/components/Preferences/panes/Appearance.tsx index 1e1a5c6f1..3ca731a9b 100644 --- a/app/assets/javascripts/components/Preferences/panes/Appearance.tsx +++ b/app/assets/javascripts/components/Preferences/panes/Appearance.tsx @@ -62,7 +62,7 @@ export const Appearance: FunctionComponent = observer( useEffect(() => { const themesAsItems: DropdownItem[] = ( - application.getDisplayableItems(ContentType.Theme) as SNTheme[] + application.items.getDisplayableItems(ContentType.Theme) as SNTheme[] ) .filter((theme) => !theme.isLayerable()) .sort(sortThemes) diff --git a/app/assets/javascripts/components/Preferences/panes/Extensions.tsx b/app/assets/javascripts/components/Preferences/panes/Extensions.tsx index 018ef7dca..391fcb359 100644 --- a/app/assets/javascripts/components/Preferences/panes/Extensions.tsx +++ b/app/assets/javascripts/components/Preferences/panes/Extensions.tsx @@ -13,7 +13,7 @@ import { useEffect, useRef, useState } from 'preact/hooks'; import { observer } from 'mobx-react-lite'; const loadExtensions = (application: WebApplication) => - application.getItems( + application.items.getItems( [ContentType.ActionsExtension, ContentType.Component, ContentType.Theme], true ) as SNComponent[]; diff --git a/app/assets/javascripts/components/QuickSettingsMenu/QuickSettingsMenu.tsx b/app/assets/javascripts/components/QuickSettingsMenu/QuickSettingsMenu.tsx index b75f434de..d2cbdcf52 100644 --- a/app/assets/javascripts/components/QuickSettingsMenu/QuickSettingsMenu.tsx +++ b/app/assets/javascripts/components/QuickSettingsMenu/QuickSettingsMenu.tsx @@ -104,7 +104,7 @@ export const QuickSettingsMenu: FunctionComponent = observer( const reloadThemes = useCallback(() => { const themes = ( - application.getDisplayableItems(ContentType.Theme) as SNTheme[] + application.items.getDisplayableItems(ContentType.Theme) as SNTheme[] ).map((item) => { return { name: item.name, @@ -141,7 +141,9 @@ export const QuickSettingsMenu: FunctionComponent = observer( const reloadToggleableComponents = useCallback(() => { const toggleableComponents = ( - application.getDisplayableItems(ContentType.Component) as SNComponent[] + application.items.getDisplayableItems( + ContentType.Component + ) as SNComponent[] ).filter( (component) => [ComponentArea.EditorStack, ComponentArea.TagsList].includes( diff --git a/app/assets/javascripts/components/RevisionHistoryModal/RevisionHistoryModalWrapper.tsx b/app/assets/javascripts/components/RevisionHistoryModal/RevisionHistoryModalWrapper.tsx index 457d0f01c..41ff96645 100644 --- a/app/assets/javascripts/components/RevisionHistoryModal/RevisionHistoryModalWrapper.tsx +++ b/app/assets/javascripts/components/RevisionHistoryModal/RevisionHistoryModalWrapper.tsx @@ -139,7 +139,7 @@ export const RevisionHistoryModal: FunctionComponent const restore = () => { if (selectedRevision) { - const originalNote = application.findItem( + const originalNote = application.items.findItem( selectedRevision.payload.uuid ) as SNNote; @@ -171,7 +171,7 @@ export const RevisionHistoryModal: FunctionComponent const restoreAsCopy = async () => { if (selectedRevision) { - const originalNote = application.findItem( + const originalNote = application.items.findItem( selectedRevision.payload.uuid ) as SNNote; diff --git a/app/assets/javascripts/components/RevisionPreviewModal.tsx b/app/assets/javascripts/components/RevisionPreviewModal.tsx index 1fe3c052f..2889e1498 100644 --- a/app/assets/javascripts/components/RevisionPreviewModal.tsx +++ b/app/assets/javascripts/components/RevisionPreviewModal.tsx @@ -37,7 +37,9 @@ export class RevisionPreviewModal extends PureComponent { this.props.content )) as SNNote; - this.originalNote = this.application.findItem(this.props.uuid) as SNNote; + this.originalNote = this.application.items.findItem( + this.props.uuid + ) as SNNote; const component = this.application.componentManager.editorForNote( this.originalNote diff --git a/app/assets/javascripts/components/Tags/TagsSection.tsx b/app/assets/javascripts/components/Tags/TagsSection.tsx index 5003483fe..40f211a43 100644 --- a/app/assets/javascripts/components/Tags/TagsSection.tsx +++ b/app/assets/javascripts/components/Tags/TagsSection.tsx @@ -16,7 +16,9 @@ export const TagsSection: FunctionComponent = observer( const [hasMigration, setHasMigration] = useState(false); const checkIfMigrationNeeded = useCallback(() => { - setHasMigration(appState.application.hasTagsNeedingFoldersMigration()); + setHasMigration( + appState.application.items.hasTagsNeedingFoldersMigration() + ); }, [appState.application]); useEffect(() => { diff --git a/app/assets/javascripts/database.ts b/app/assets/javascripts/database.ts index 5134c0fd6..ef897968c 100644 --- a/app/assets/javascripts/database.ts +++ b/app/assets/javascripts/database.ts @@ -1,4 +1,4 @@ -import { SNAlertService } from "@standardnotes/snjs"; +import { SNAlertService } from '@standardnotes/snjs'; const STORE_NAME = 'items'; const READ_WRITE = 'readwrite'; @@ -16,14 +16,13 @@ const DB_DELETION_BLOCKED = const QUOTE_EXCEEDED_ERROR = 'QuotaExceededError'; export class Database { - private locked = true - private db?: IDBDatabase + private locked = true; + private db?: IDBDatabase; constructor( public databaseName: string, - private alertService: SNAlertService) { - - } + private alertService: SNAlertService + ) {} public deinit() { (this.alertService as any) = undefined; @@ -43,7 +42,9 @@ export class Database { * as part of the open process. This can happen on new application sessions, or if the * browser deleted the database without the user being aware. */ - public async openDatabase(onNewDatabase?: () => void): Promise { + public async openDatabase( + onNewDatabase?: () => void + ): Promise { if (this.locked) { throw Error('Attempting to open locked database'); } @@ -84,15 +85,10 @@ export class Database { db.close(); }; /* Create an objectStore for this database */ - const objectStore = db.createObjectStore( - STORE_NAME, - { keyPath: 'uuid' } - ); - objectStore.createIndex( - 'uuid', - 'uuid', - { unique: true } - ); + const objectStore = db.createObjectStore(STORE_NAME, { + keyPath: 'uuid', + }); + objectStore.createIndex('uuid', 'uuid', { unique: true }); objectStore.transaction.oncomplete = () => { /* Ready to store values in the newly created objectStore. */ if (db.version === 1 && onNewDatabase) { @@ -106,9 +102,7 @@ export class Database { public async getAllPayloads(): Promise { const db = (await this.openDatabase())!; return new Promise((resolve) => { - const objectStore = - db.transaction(STORE_NAME). - objectStore(STORE_NAME); + const objectStore = db.transaction(STORE_NAME).objectStore(STORE_NAME); const payloads: any = []; const cursorRequest = objectStore.openCursor(); cursorRequest.onsuccess = (event) => { @@ -136,7 +130,7 @@ export class Database { const transaction = db.transaction(STORE_NAME, READ_WRITE); return new Promise((resolve, reject) => { // eslint-disable-next-line @typescript-eslint/no-empty-function - transaction.oncomplete = () => { }; + transaction.oncomplete = () => {}; transaction.onerror = (event) => { const target = event!.target! as any; this.showGenericError(target.error); @@ -156,23 +150,28 @@ export class Database { }); } - private async putItems(objectStore: IDBObjectStore, items: any[]): Promise { - await Promise.all(items.map((item) => { - return new Promise((resolve) => { - const request = objectStore.put(item); - request.onerror = resolve; - request.onsuccess = resolve; - }); - })); + private async putItems( + objectStore: IDBObjectStore, + items: any[] + ): Promise { + await Promise.all( + items.map((item) => { + return new Promise((resolve) => { + const request = objectStore.put(item); + request.onerror = resolve; + request.onsuccess = resolve; + }); + }) + ); } public async deletePayload(uuid: string): Promise { const db = (await this.openDatabase())!; return new Promise((resolve, reject) => { - const request = - db.transaction(STORE_NAME, READ_WRITE) - .objectStore(STORE_NAME) - .delete(uuid); + const request = db + .transaction(STORE_NAME, READ_WRITE) + .objectStore(STORE_NAME) + .delete(uuid); request.onsuccess = () => { resolve(); }; @@ -201,7 +200,7 @@ export class Database { this.alertService!.alert(message); } - private showGenericError(error: { code: number, name: string }) { + private showGenericError(error: { code: number; name: string }) { const message = `Unable to save changes locally due to an unknown system issue. ` + `Issue Code: ${error.code} Issue Name: ${error.name}.`; @@ -210,11 +209,11 @@ export class Database { private displayOfflineAlert() { const message = - "There was an issue loading your offline database. This could happen for two reasons:" + + 'There was an issue loading your offline database. This could happen for two reasons:' + "\n\n1. You're in a private window in your browser. We can't save your data without " + - "access to the local database. Please use a non-private window." + - "\n\n2. You have two windows of the app open at the same time. " + - "Please close any other app instances and reload the page."; + 'access to the local database. Please use a non-private window.' + + '\n\n2. You have two windows of the app open at the same time. ' + + 'Please close any other app instances and reload the page.'; this.alertService!.alert(message); } } diff --git a/app/assets/javascripts/services/desktopManager.ts b/app/assets/javascripts/services/desktopManager.ts index 2e4bfe85d..243c3392c 100644 --- a/app/assets/javascripts/services/desktopManager.ts +++ b/app/assets/javascripts/services/desktopManager.ts @@ -132,7 +132,7 @@ export class DesktopManager componentData: any, error: any ) { - const component = this.application.findItem(componentData.uuid); + const component = this.application.items.findItem(componentData.uuid); if (!component) { return; } diff --git a/app/assets/javascripts/services/themeManager.ts b/app/assets/javascripts/services/themeManager.ts index 95fcf8dce..9d4b8bcb2 100644 --- a/app/assets/javascripts/services/themeManager.ts +++ b/app/assets/javascripts/services/themeManager.ts @@ -40,7 +40,7 @@ export class ThemeManager extends ApplicationService { const preference = prefersDarkColorScheme ? PrefKey.AutoDarkThemeIdentifier : PrefKey.AutoLightThemeIdentifier; - const themes = this.application.getDisplayableItems( + const themes = this.application.items.getDisplayableItems( ContentType.Theme ) as SNTheme[]; @@ -123,7 +123,7 @@ export class ThemeManager extends ApplicationService { private handleFeaturesUpdated(): void { let hasChange = false; for (const themeUuid of this.activeThemes) { - const theme = this.application.findItem(themeUuid) as SNTheme; + const theme = this.application.items.findItem(themeUuid) as SNTheme; if (!theme) { this.deactivateTheme(themeUuid); hasChange = true; @@ -143,7 +143,7 @@ export class ThemeManager extends ApplicationService { } const activeThemes = ( - this.application.getItems(ContentType.Theme) as SNTheme[] + this.application.items.getItems(ContentType.Theme) as SNTheme[] ).filter((theme) => theme.active); for (const theme of activeThemes) { @@ -248,7 +248,9 @@ export class ThemeManager extends ApplicationService { } private async cacheThemeState() { - const themes = this.application.getAll(this.activeThemes) as SNTheme[]; + const themes = this.application.items.findItems( + this.activeThemes + ) as SNTheme[]; const mapped = await Promise.all( themes.map(async (theme) => { const payload = theme.payloadRepresentation(); @@ -275,8 +277,9 @@ export class ThemeManager extends ApplicationService { if (cachedThemes) { const themes = []; for (const cachedTheme of cachedThemes) { - const payload = this.application.createPayloadFromObject(cachedTheme); - const theme = this.application.createItemFromPayload( + const payload = + this.application.items.createPayloadFromObject(cachedTheme); + const theme = this.application.items.createItemFromPayload( payload ) as SNTheme; themes.push(theme); diff --git a/app/assets/javascripts/ui_models/app_state/account_menu_state.ts b/app/assets/javascripts/ui_models/app_state/account_menu_state.ts index 5b007d8f9..ce9064880 100644 --- a/app/assets/javascripts/ui_models/app_state/account_menu_state.ts +++ b/app/assets/javascripts/ui_models/app_state/account_menu_state.ts @@ -89,7 +89,7 @@ export class AccountMenuState { this.appEventListeners.push( this.application.streamItems([ContentType.Note, ContentType.Tag], () => { runInAction(() => { - this.notesAndTags = this.application.getItems([ + this.notesAndTags = this.application.items.getItems([ ContentType.Note, ContentType.Tag, ]); diff --git a/app/assets/javascripts/ui_models/app_state/app_state.ts b/app/assets/javascripts/ui_models/app_state/app_state.ts index 2f479a86a..8c6dc4e27 100644 --- a/app/assets/javascripts/ui_models/app_state/app_state.ts +++ b/app/assets/javascripts/ui_models/app_state/app_state.ts @@ -307,7 +307,7 @@ export class AppState { return; } - if (this.application.isTemplateItem(tag)) { + if (this.application.items.isTemplateItem(tag)) { return; } @@ -436,9 +436,11 @@ export class AppState { /** Returns the tags that are referncing this note */ public getNoteTags(note: SNNote) { - return this.application.referencingForItem(note).filter((ref) => { - return ref.content_type === ContentType.Tag; - }) as SNTag[]; + return this.application.items + .itemsReferencingItem(note.uuid) + .filter((ref) => { + return ref.content_type === ContentType.Tag; + }) as SNTag[]; } panelDidResize(name: string, collapsed: boolean) { diff --git a/app/assets/javascripts/ui_models/app_state/no_account_warning_state.ts b/app/assets/javascripts/ui_models/app_state/no_account_warning_state.ts index 63b17f7ab..654c15054 100644 --- a/app/assets/javascripts/ui_models/app_state/no_account_warning_state.ts +++ b/app/assets/javascripts/ui_models/app_state/no_account_warning_state.ts @@ -1,6 +1,6 @@ -import { storage, StorageKey } from "@/services/localStorage"; -import { SNApplication, ApplicationEvent } from "@standardnotes/snjs"; -import { runInAction, makeObservable, observable, action } from "mobx"; +import { storage, StorageKey } from '@/services/localStorage'; +import { SNApplication, ApplicationEvent } from '@standardnotes/snjs'; +import { runInAction, makeObservable, observable, action } from 'mobx'; export class NoAccountWarningState { show: boolean; @@ -33,9 +33,9 @@ export class NoAccountWarningState { hide = (): void => { this.show = false; storage.set(StorageKey.ShowNoAccountWarning, false); - } + }; reset = (): void => { storage.remove(StorageKey.ShowNoAccountWarning); - } + }; } diff --git a/app/assets/javascripts/ui_models/app_state/note_tags_state.ts b/app/assets/javascripts/ui_models/app_state/note_tags_state.ts index 03ae08bf6..238da65aa 100644 --- a/app/assets/javascripts/ui_models/app_state/note_tags_state.ts +++ b/app/assets/javascripts/ui_models/app_state/note_tags_state.ts @@ -170,7 +170,7 @@ export class NoteTagsState { } searchActiveNoteAutocompleteTags(): void { - const newResults = this.application.searchTags( + const newResults = this.application.items.searchTags( this.autocompleteSearchQuery, this.activeNote ); @@ -184,7 +184,7 @@ export class NoteTagsState { reloadTags(): void { const { activeNote } = this; if (activeNote) { - const tags = this.application.getSortedTagsForNote(activeNote); + const tags = this.application.items.getSortedTagsForNote(activeNote); this.setTags(tags); } } @@ -224,7 +224,7 @@ export class NoteTagsState { } getSortedTagsForNote(note: SNNote): SNTag[] { - const tags = this.application.getSortedTagsForNote(note); + const tags = this.application.items.getSortedTagsForNote(note); const sortFunction = (tagA: SNTag, tagB: SNTag): number => { const a = this.getLongTitle(tagA); @@ -243,10 +243,10 @@ export class NoteTagsState { } getPrefixTitle(tag: SNTag): string | undefined { - return this.application.getTagPrefixTitle(tag); + return this.application.items.getTagPrefixTitle(tag); } getLongTitle(tag: SNTag): string { - return this.application.getTagLongTitle(tag); + return this.application.items.getTagLongTitle(tag); } } diff --git a/app/assets/javascripts/ui_models/app_state/notes_state.ts b/app/assets/javascripts/ui_models/app_state/notes_state.ts index 04feb003e..0dec3b8d0 100644 --- a/app/assets/javascripts/ui_models/app_state/notes_state.ts +++ b/app/assets/javascripts/ui_models/app_state/notes_state.ts @@ -81,11 +81,11 @@ export class NotesState { } get trashedNotesCount(): number { - return this.application.getTrashedItems().length; + return this.application.items.trashedItems.length; } private async selectNotesRange(selectedNote: SNNote): Promise { - const notes = this.application.getDisplayableItems( + const notes = this.application.items.getDisplayableItems( ContentType.Note ) as SNNote[]; const lastSelectedNoteIndex = notes.findIndex( @@ -117,7 +117,7 @@ export class NotesState { } async selectNote(uuid: UuidString, userTriggered?: boolean): Promise { - const note = this.application.findItem(uuid) as SNNote; + const note = this.application.items.findItem(uuid) as SNNote; if (!note) { return; } @@ -163,7 +163,9 @@ export class NotesState { return; } - const note = this.application.findItem(noteUuid) as SNNote | undefined; + const note = this.application.items.findItem(noteUuid) as + | SNNote + | undefined; if (!note) { console.warn('Tried accessing a non-existant note of UUID ' + noteUuid); return; @@ -408,7 +410,7 @@ export class NotesState { async addTagToSelectedNotes(tag: SNTag): Promise { const selectedNotes = Object.values(this.selectedNotes); - const parentChainTags = this.application.getTagParentChain(tag); + const parentChainTags = this.application.items.getTagParentChain(tag.uuid); const tagsToAdd = [...parentChainTags, tag]; await Promise.all( tagsToAdd.map(async (tag) => { diff --git a/app/assets/javascripts/ui_models/app_state/notes_view_state.ts b/app/assets/javascripts/ui_models/app_state/notes_view_state.ts index 60e48b831..f2dd350c8 100644 --- a/app/assets/javascripts/ui_models/app_state/notes_view_state.ts +++ b/app/assets/javascripts/ui_models/app_state/notes_view_state.ts @@ -223,7 +223,7 @@ export class NotesViewState { if (!tag) { return; } - const notes = this.application.getDisplayableItems( + const notes = this.application.items.getDisplayableItems( ContentType.Note ) as SNNote[]; const renderedNotes = notes.slice(0, this.notesToDisplay); @@ -264,7 +264,7 @@ export class NotesViewState { this.appState.searchOptions.includeProtectedContents, }, }); - this.application.setNotesDisplayCriteria(criteria); + this.application.items.setNotesDisplayCriteria(criteria); }; reloadPreferences = () => { diff --git a/app/assets/javascripts/ui_models/app_state/sync_state.ts b/app/assets/javascripts/ui_models/app_state/sync_state.ts index 7bc066454..287bfbf06 100644 --- a/app/assets/javascripts/ui_models/app_state/sync_state.ts +++ b/app/assets/javascripts/ui_models/app_state/sync_state.ts @@ -1,5 +1,5 @@ -import { SyncOpStatus } from "@standardnotes/snjs"; -import { action, makeObservable, observable } from "mobx"; +import { SyncOpStatus } from '@standardnotes/snjs'; +import { action, makeObservable, observable } from 'mobx'; export class SyncState { inProgress = false; @@ -32,5 +32,5 @@ export class SyncState { { style: 'percent' } ); } - } + }; } diff --git a/app/assets/javascripts/ui_models/app_state/tags_state.ts b/app/assets/javascripts/ui_models/app_state/tags_state.ts index bc939dcba..e03dc419c 100644 --- a/app/assets/javascripts/ui_models/app_state/tags_state.ts +++ b/app/assets/javascripts/ui_models/app_state/tags_state.ts @@ -29,9 +29,11 @@ import { FeaturesState, SMART_TAGS_FEATURE_NAME } from './features_state'; type AnyTag = SNTag | SmartView; const rootTags = (application: SNApplication): SNTag[] => { - const hasNoParent = (tag: SNTag) => !application.getTagParent(tag); + const hasNoParent = (tag: SNTag) => !application.items.getTagParent(tag.uuid); - const allTags = application.getDisplayableItems(ContentType.Tag) as SNTag[]; + const allTags = application.items.getDisplayableItems( + ContentType.Tag + ) as SNTag[]; const rootTags = allTags.filter(hasNoParent); return rootTags; @@ -41,11 +43,11 @@ const tagSiblings = (application: SNApplication, tag: SNTag): SNTag[] => { const withoutCurrentTag = (tags: SNTag[]) => tags.filter((other) => other.uuid !== tag.uuid); - const isTemplateTag = application.isTemplateItem(tag); - const parentTag = !isTemplateTag && application.getTagParent(tag); + const isTemplateTag = application.items.isTemplateItem(tag); + const parentTag = !isTemplateTag && application.items.getTagParent(tag.uuid); if (parentTag) { - const siblingsAndTag = application.getTagChildren(parentTag); + const siblingsAndTag = application.items.getTagChildren(parentTag.uuid); return withoutCurrentTag(siblingsAndTag); } @@ -101,7 +103,7 @@ export class TagsState { this.editing_ = undefined; this.addingSubtagTo = undefined; - this.smartViews = this.application.getSmartViews(); + this.smartViews = this.application.items.getSmartViews(); this.selected_ = this.smartViews[0]; makeObservable(this, { @@ -148,10 +150,10 @@ export class TagsState { [ContentType.Tag, ContentType.SmartView], (items) => { runInAction(() => { - this.tags = this.application.getDisplayableItems( + this.tags = this.application.items.getDisplayableItems( ContentType.Tag ); - this.smartViews = this.application.getSmartViews(); + this.smartViews = this.application.items.getSmartViews(); const selectedTag = this.selected_; if (selectedTag && !isSystemView(selectedTag as SmartView)) { @@ -174,12 +176,14 @@ export class TagsState { ); appEventListeners.push( - this.application.addNoteCountChangeObserver((tagUuid) => { + this.application.items.addNoteCountChangeObserver((tagUuid) => { if (!tagUuid) { - this.setAllNotesCount(this.application.allCountableNotesCount()); + this.setAllNotesCount( + this.application.items.allCountableNotesCount() + ); } else { this.tagsCountsState.update([ - this.application.findItem(tagUuid) as SNTag, + this.application.items.findItem(tagUuid) as SNTag, ]); } }) @@ -198,7 +202,7 @@ export class TagsState { title )) as SNTag; - const futureSiblings = this.application.getTagChildren(parent); + const futureSiblings = this.application.items.getTagChildren(parent.uuid); if (!isValidFutureSiblings(this.application, futureSiblings, createdTag)) { this.setAddingSubtagTo(undefined); @@ -299,7 +303,7 @@ export class TagsState { public get allLocalRootTags(): SNTag[] { if ( this.editing_ instanceof SNTag && - this.application.isTemplateItem(this.editing_) + this.application.items.isTemplateItem(this.editing_) ) { return [this.editing_, ...this.rootTags]; } @@ -311,11 +315,11 @@ export class TagsState { } getChildren(tag: SNTag): SNTag[] { - if (this.application.isTemplateItem(tag)) { + if (this.application.items.isTemplateItem(tag)) { return []; } - const children = this.application.getTagChildren(tag); + const children = this.application.items.getTagChildren(tag.uuid); const childrenUuids = children.map((childTag) => childTag.uuid); const childrenTags = this.tags.filter((tag) => @@ -325,11 +329,11 @@ export class TagsState { } isValidTagParent(parentUuid: UuidString, tagUuid: UuidString): boolean { - return this.application.isValidTagParent(parentUuid, tagUuid); + return this.application.items.isValidTagParent(parentUuid, tagUuid); } public hasParent(tagUuid: UuidString): boolean { - const item = this.application.findItem(tagUuid); + const item = this.application.items.findItem(tagUuid); return !!item && !!(item as SNTag).parentId; } @@ -337,9 +341,9 @@ export class TagsState { tagUuid: string, futureParentUuid: string | undefined ): Promise { - const tag = this.application.findItem(tagUuid) as SNTag; + const tag = this.application.items.findItem(tagUuid) as SNTag; - const currentParent = this.application.getTagParent(tag); + const currentParent = this.application.items.getTagParent(tag.uuid); const currentParentUuid = currentParent?.uuid; if (currentParentUuid === futureParentUuid) { @@ -348,7 +352,7 @@ export class TagsState { const futureParent = futureParentUuid && - (this.application.findItem(futureParentUuid) as SNTag); + (this.application.items.findItem(futureParentUuid) as SNTag); if (!futureParent) { const futureSiblings = rootTags(this.application); @@ -357,7 +361,9 @@ export class TagsState { } await this.application.mutator.unsetTagParent(tag); } else { - const futureSiblings = this.application.getTagChildren(futureParent); + const futureSiblings = this.application.items.getTagChildren( + futureParent.uuid + ); if (!isValidFutureSiblings(this.application, futureSiblings, tag)) { return; } @@ -368,7 +374,9 @@ export class TagsState { } get rootTags(): SNTag[] { - return this.tags.filter((tag) => !this.application.getTagParent(tag)); + return this.tags.filter( + (tag) => !this.application.items.getTagParent(tag.uuid) + ); } get tagsCount(): number { @@ -432,7 +440,7 @@ export class TagsState { public async createNewTemplate() { const isAlreadyEditingATemplate = - this.editing_ && this.application.isTemplateItem(this.editing_); + this.editing_ && this.application.items.isTemplateItem(this.editing_); if (isAlreadyEditingATemplate) { return; @@ -470,7 +478,7 @@ export class TagsState { public async save(tag: SNTag | SmartView, newTitle: string) { const hasEmptyTitle = newTitle.length === 0; const hasNotChangedTitle = newTitle === tag.title; - const isTemplateChange = this.application.isTemplateItem(tag); + const isTemplateChange = this.application.items.isTemplateItem(tag); const siblings = tag instanceof SNTag ? tagSiblings(this.application, tag) : []; @@ -500,7 +508,8 @@ export class TagsState { } if (isTemplateChange) { - const isSmartViewTitle = this.application.isSmartViewTitle(newTitle); + const isSmartViewTitle = + this.application.items.isSmartViewTitle(newTitle); if (isSmartViewTitle) { if (!this.features.hasSmartViews) { @@ -541,7 +550,7 @@ export class TagsState { item.content_type === ContentType.Tag || item.content_type === ContentType.SmartView ) { - const matchingTag = this.application.findItem(item.uuid); + const matchingTag = this.application.items.findItem(item.uuid); if (matchingTag) { this.selected = matchingTag as AnyTag; @@ -554,7 +563,9 @@ export class TagsState { } public get hasAtLeastOneFolder(): boolean { - return this.tags.some((tag) => !!this.application.getTagParent(tag)); + return this.tags.some( + (tag) => !!this.application.items.getTagParent(tag.uuid) + ); } } @@ -575,7 +586,7 @@ class TagsCountsState { ); tags.forEach((tag) => { - newCounts[tag.uuid] = this.application.countableNotesForTag(tag); + newCounts[tag.uuid] = this.application.items.countableNotesForTag(tag); }); this.counts = newCounts; diff --git a/package.json b/package.json index 651552a19..66d6bc629 100644 --- a/package.json +++ b/package.json @@ -76,7 +76,7 @@ "@standardnotes/filepicker": "1.10.1", "@standardnotes/settings": "1.13.1", "@standardnotes/sncrypto-web": "1.8.0", - "@standardnotes/snjs": "2.89.1", + "@standardnotes/snjs": "2.89.3", "@zip.js/zip.js": "^2.4.7", "mobx": "^6.5.0", "mobx-react-lite": "^3.3.0", diff --git a/yarn.lock b/yarn.lock index ea95085ba..caf0d0d18 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2484,10 +2484,10 @@ buffer "^6.0.3" libsodium-wrappers "^0.7.9" -"@standardnotes/snjs@2.89.1": - version "2.89.1" - resolved "https://registry.yarnpkg.com/@standardnotes/snjs/-/snjs-2.89.1.tgz#73694f24e748d51abf72255c57545006c8882aec" - integrity sha512-KHwxyhCx4W+ba6QgqEEkIxxbm8D7O8BdIZFVbawPhMfvnp0rX7pd7EclqG8rOD2dTzb74cA7IHp2/MJsj3i0vw== +"@standardnotes/snjs@2.89.3": + version "2.89.3" + resolved "https://registry.yarnpkg.com/@standardnotes/snjs/-/snjs-2.89.3.tgz#cdf4030772308df0572eb9de21dae3c03a96a906" + integrity sha512-UYiO9cNntlxB/0CkLPvWMNves8TUuANx2jliKlVbHbPjuECh0MDa5ZBPoSKFWrDE51oU41GqjUp05mr6FK7Skw== dependencies: "@standardnotes/applications" "^1.2.5" "@standardnotes/auth" "^3.17.10"