fix(mobile): increase save debounce timeout
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import { InfoStrings } from '../Strings/Info'
|
||||||
import { NoteType } from '@standardnotes/features'
|
import { NoteType } from '@standardnotes/features'
|
||||||
import {
|
import {
|
||||||
NoteMutator,
|
NoteMutator,
|
||||||
@@ -11,14 +12,6 @@ import { removeFromArray } from '@standardnotes/utils'
|
|||||||
import { ContentType } from '@standardnotes/common'
|
import { ContentType } from '@standardnotes/common'
|
||||||
import { UuidString } from '@Lib/Types/UuidString'
|
import { UuidString } from '@Lib/Types/UuidString'
|
||||||
import { SNApplication } from '../Application/Application'
|
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 { ItemViewControllerInterface } from './ItemViewControllerInterface'
|
||||||
import { TemplateNoteViewControllerOptions } from './TemplateNoteViewControllerOptions'
|
import { TemplateNoteViewControllerOptions } from './TemplateNoteViewControllerOptions'
|
||||||
|
|
||||||
@@ -27,6 +20,15 @@ export type EditorValues = {
|
|||||||
text: string
|
text: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const StringEllipses = '...'
|
||||||
|
const NotePreviewCharLimit = 160
|
||||||
|
|
||||||
|
const SaveTimeoutDebounc = {
|
||||||
|
Desktop: 350,
|
||||||
|
ImmediateChange: 100,
|
||||||
|
NativeMobileWeb: 700,
|
||||||
|
}
|
||||||
|
|
||||||
export class NoteViewController implements ItemViewControllerInterface {
|
export class NoteViewController implements ItemViewControllerInterface {
|
||||||
public item!: SNNote
|
public item!: SNNote
|
||||||
public dealloced = false
|
public dealloced = false
|
||||||
@@ -182,7 +184,7 @@ export class NoteViewController implements ItemViewControllerInterface {
|
|||||||
const isTemplate = this.isTemplateNote
|
const isTemplate = this.isTemplateNote
|
||||||
|
|
||||||
if (typeof document !== 'undefined' && document.hidden) {
|
if (typeof document !== 'undefined' && document.hidden) {
|
||||||
void this.application.alertService.alert(STRING_SAVING_WHILE_DOCUMENT_HIDDEN)
|
void this.application.alertService.alert(InfoStrings.SavingWhileDocumentHidden)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,7 +193,7 @@ export class NoteViewController implements ItemViewControllerInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!this.application.items.findItem(this.item.uuid)) {
|
if (!this.application.items.findItem(this.item.uuid)) {
|
||||||
void this.application.alertService.alert(STRING_INVALID_NOTE)
|
void this.application.alertService.alert(InfoStrings.InvalidNote)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,9 +209,9 @@ export class NoteViewController implements ItemViewControllerInterface {
|
|||||||
|
|
||||||
if (!dto.dontUpdatePreviews) {
|
if (!dto.dontUpdatePreviews) {
|
||||||
const noteText = text || ''
|
const noteText = text || ''
|
||||||
const truncate = noteText.length > NOTE_PREVIEW_CHAR_LIMIT
|
const truncate = noteText.length > NotePreviewCharLimit
|
||||||
const substring = noteText.substring(0, NOTE_PREVIEW_CHAR_LIMIT)
|
const substring = noteText.substring(0, NotePreviewCharLimit)
|
||||||
const previewPlain = substring + (truncate ? STRING_ELLIPSES : '')
|
const previewPlain = substring + (truncate ? StringEllipses : '')
|
||||||
|
|
||||||
// eslint-disable-next-line camelcase
|
// eslint-disable-next-line camelcase
|
||||||
noteMutator.preview_plain = previewPlain
|
noteMutator.preview_plain = previewPlain
|
||||||
@@ -225,7 +227,13 @@ export class NoteViewController implements ItemViewControllerInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const noDebounce = dto.bypassDebouncer || this.application.noAccount()
|
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(() => {
|
this.saveTimeout = setTimeout(() => {
|
||||||
void this.application.sync.sync()
|
void this.application.sync.sync()
|
||||||
}, syncDebouceMs)
|
}, syncDebouceMs)
|
||||||
|
|||||||
@@ -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
|
|
||||||
@@ -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.',
|
'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:
|
BackupFileMoreRecentThanAccount:
|
||||||
"This backup file was created using a newer encryption version than your account's. Please run the available encryption upgrade and try again.",
|
"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.",
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user