diff --git a/packages/snjs/lib/Client/NoteViewController.ts b/packages/snjs/lib/Client/NoteViewController.ts index dc59039d9..cb0329607 100644 --- a/packages/snjs/lib/Client/NoteViewController.ts +++ b/packages/snjs/lib/Client/NoteViewController.ts @@ -1,3 +1,4 @@ +import { InfoStrings } from '../Strings/Info' import { NoteType } from '@standardnotes/features' import { NoteMutator, @@ -11,14 +12,6 @@ import { removeFromArray } from '@standardnotes/utils' import { ContentType } from '@standardnotes/common' import { UuidString } from '@Lib/Types/UuidString' import { SNApplication } from '../Application/Application' -import { - STRING_SAVING_WHILE_DOCUMENT_HIDDEN, - STRING_INVALID_NOTE, - NOTE_PREVIEW_CHAR_LIMIT, - STRING_ELLIPSES, - SAVE_TIMEOUT_NO_DEBOUNCE, - SAVE_TIMEOUT_DEBOUNCE, -} from './Types' import { ItemViewControllerInterface } from './ItemViewControllerInterface' import { TemplateNoteViewControllerOptions } from './TemplateNoteViewControllerOptions' @@ -27,6 +20,15 @@ export type EditorValues = { text: string } +const StringEllipses = '...' +const NotePreviewCharLimit = 160 + +const SaveTimeoutDebounc = { + Desktop: 350, + ImmediateChange: 100, + NativeMobileWeb: 700, +} + export class NoteViewController implements ItemViewControllerInterface { public item!: SNNote public dealloced = false @@ -182,7 +184,7 @@ export class NoteViewController implements ItemViewControllerInterface { const isTemplate = this.isTemplateNote if (typeof document !== 'undefined' && document.hidden) { - void this.application.alertService.alert(STRING_SAVING_WHILE_DOCUMENT_HIDDEN) + void this.application.alertService.alert(InfoStrings.SavingWhileDocumentHidden) return } @@ -191,7 +193,7 @@ export class NoteViewController implements ItemViewControllerInterface { } if (!this.application.items.findItem(this.item.uuid)) { - void this.application.alertService.alert(STRING_INVALID_NOTE) + void this.application.alertService.alert(InfoStrings.InvalidNote) return } @@ -207,9 +209,9 @@ export class NoteViewController implements ItemViewControllerInterface { if (!dto.dontUpdatePreviews) { const noteText = text || '' - const truncate = noteText.length > NOTE_PREVIEW_CHAR_LIMIT - const substring = noteText.substring(0, NOTE_PREVIEW_CHAR_LIMIT) - const previewPlain = substring + (truncate ? STRING_ELLIPSES : '') + const truncate = noteText.length > NotePreviewCharLimit + const substring = noteText.substring(0, NotePreviewCharLimit) + const previewPlain = substring + (truncate ? StringEllipses : '') // eslint-disable-next-line camelcase noteMutator.preview_plain = previewPlain @@ -225,7 +227,13 @@ export class NoteViewController implements ItemViewControllerInterface { } const noDebounce = dto.bypassDebouncer || this.application.noAccount() - const syncDebouceMs = noDebounce ? SAVE_TIMEOUT_NO_DEBOUNCE : SAVE_TIMEOUT_DEBOUNCE + + const syncDebouceMs = noDebounce + ? SaveTimeoutDebounc.ImmediateChange + : this.application.isNativeMobileWeb() + ? SaveTimeoutDebounc.NativeMobileWeb + : SaveTimeoutDebounc.Desktop + this.saveTimeout = setTimeout(() => { void this.application.sync.sync() }, syncDebouceMs) diff --git a/packages/snjs/lib/Client/Types.ts b/packages/snjs/lib/Client/Types.ts deleted file mode 100644 index d21177df3..000000000 --- a/packages/snjs/lib/Client/Types.ts +++ /dev/null @@ -1,8 +0,0 @@ -export const STRING_SAVING_WHILE_DOCUMENT_HIDDEN = - 'Attempting to save an item while the application is hidden. To protect data integrity, please refresh the application window and try again.' -export const STRING_INVALID_NOTE = - "The note you are attempting to save can not be found or has been deleted. Changes you make will not be synced. Please copy this note's text and start a new note." -export const STRING_ELLIPSES = '...' -export const NOTE_PREVIEW_CHAR_LIMIT = 160 -export const SAVE_TIMEOUT_DEBOUNCE = 350 -export const SAVE_TIMEOUT_NO_DEBOUNCE = 100 diff --git a/packages/snjs/lib/Strings/Info.ts b/packages/snjs/lib/Strings/Info.ts index 310d58155..421f2fe8c 100644 --- a/packages/snjs/lib/Strings/Info.ts +++ b/packages/snjs/lib/Strings/Info.ts @@ -4,4 +4,8 @@ export const InfoStrings = { 'This backup file was created using a newer version of the application and cannot be imported here. Please update your application and try again.', BackupFileMoreRecentThanAccount: "This backup file was created using a newer encryption version than your account's. Please run the available encryption upgrade and try again.", + SavingWhileDocumentHidden: + 'Attempting to save an item while the application is hidden. To protect data integrity, please refresh the application window and try again.', + InvalidNote: + "The note you are attempting to save can not be found or has been deleted. Changes you make will not be synced. Please copy this note's text and start a new note.", }