feat: daily notes (dev only) (#1894)
This commit is contained in:
@@ -28,6 +28,7 @@ describe('note view controller', () => {
|
||||
expect(application.mutator.createTemplateItem).toHaveBeenCalledWith(
|
||||
ContentType.Note,
|
||||
expect.objectContaining({ noteType: NoteType.Plain }),
|
||||
expect.anything(),
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -34,7 +34,6 @@ export class NoteViewController implements ItemViewControllerInterface {
|
||||
private removeStreamObserver?: () => void
|
||||
public isTemplateNote = false
|
||||
private saveTimeout?: ReturnType<typeof setTimeout>
|
||||
private defaultTitle: string | undefined
|
||||
private defaultTagUuid: UuidString | undefined
|
||||
private defaultTag?: SNTag
|
||||
public runtimeId = `${Math.random()}`
|
||||
@@ -42,14 +41,13 @@ export class NoteViewController implements ItemViewControllerInterface {
|
||||
constructor(
|
||||
private application: SNApplication,
|
||||
item?: SNNote,
|
||||
templateNoteOptions?: TemplateNoteViewControllerOptions,
|
||||
public templateNoteOptions?: TemplateNoteViewControllerOptions,
|
||||
) {
|
||||
if (item) {
|
||||
this.item = item
|
||||
}
|
||||
|
||||
if (templateNoteOptions) {
|
||||
this.defaultTitle = templateNoteOptions.title
|
||||
this.defaultTagUuid = templateNoteOptions.tag
|
||||
}
|
||||
|
||||
@@ -80,13 +78,19 @@ export class NoteViewController implements ItemViewControllerInterface {
|
||||
? this.application.componentManager.componentWithIdentifier(editorIdentifier)
|
||||
: undefined
|
||||
|
||||
const note = this.application.mutator.createTemplateItem<NoteContent, SNNote>(ContentType.Note, {
|
||||
text: '',
|
||||
title: this.defaultTitle || '',
|
||||
noteType: defaultEditor?.noteType || NoteType.Plain,
|
||||
editorIdentifier: editorIdentifier,
|
||||
references: [],
|
||||
})
|
||||
const note = this.application.mutator.createTemplateItem<NoteContent, SNNote>(
|
||||
ContentType.Note,
|
||||
{
|
||||
text: '',
|
||||
title: this.templateNoteOptions?.title || '',
|
||||
noteType: defaultEditor?.noteType || NoteType.Plain,
|
||||
editorIdentifier: editorIdentifier,
|
||||
references: [],
|
||||
},
|
||||
{
|
||||
created_at: this.templateNoteOptions?.createdAt || new Date(),
|
||||
},
|
||||
)
|
||||
|
||||
this.isTemplateNote = true
|
||||
this.item = note
|
||||
@@ -109,6 +113,10 @@ export class NoteViewController implements ItemViewControllerInterface {
|
||||
}
|
||||
|
||||
private streamItems() {
|
||||
if (this.dealloced) {
|
||||
return
|
||||
}
|
||||
|
||||
this.removeStreamObserver = this.application.streamItems<SNNote>(
|
||||
ContentType.Note,
|
||||
({ changed, inserted, source }) => {
|
||||
|
||||
@@ -3,4 +3,8 @@ import { UuidString } from '@Lib/Types/UuidString'
|
||||
export type TemplateNoteViewControllerOptions = {
|
||||
title?: string
|
||||
tag?: UuidString
|
||||
createdAt?: Date
|
||||
autofocusBehavior?: TemplateNoteViewAutofocusBehavior
|
||||
}
|
||||
|
||||
export type TemplateNoteViewAutofocusBehavior = 'title' | 'editor'
|
||||
|
||||
@@ -3,6 +3,6 @@ export const STRING_SAVING_WHILE_DOCUMENT_HIDDEN =
|
||||
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 = 80
|
||||
export const NOTE_PREVIEW_CHAR_LIMIT = 160
|
||||
export const SAVE_TIMEOUT_DEBOUNCE = 350
|
||||
export const SAVE_TIMEOUT_NO_DEBOUNCE = 100
|
||||
|
||||
@@ -3,3 +3,4 @@ export * from './NoteViewController'
|
||||
export * from './FileViewController'
|
||||
export * from './ItemGroupController'
|
||||
export * from './ReactNativeToWebEvent'
|
||||
export * from './TemplateNoteViewControllerOptions'
|
||||
|
||||
@@ -805,12 +805,13 @@ export class ItemManager
|
||||
public createTemplateItem<
|
||||
C extends Models.ItemContent = Models.ItemContent,
|
||||
I extends Models.DecryptedItemInterface<C> = Models.DecryptedItemInterface<C>,
|
||||
>(contentType: ContentType, content?: C): I {
|
||||
>(contentType: ContentType, content?: C, override?: Partial<Models.DecryptedPayload<C>>): I {
|
||||
const payload = new Models.DecryptedPayload<C>({
|
||||
uuid: UuidGenerator.GenerateUuid(),
|
||||
content_type: contentType,
|
||||
content: Models.FillItemContent<C>(content || {}),
|
||||
...Models.PayloadTimestampDefaults(),
|
||||
...override,
|
||||
})
|
||||
const item = Models.CreateDecryptedItemFromPayload<C, I>(payload)
|
||||
return item
|
||||
|
||||
@@ -29,6 +29,7 @@ import {
|
||||
CreateEncryptedBackupFileContextPayload,
|
||||
DecryptedItemInterface,
|
||||
DecryptedItemMutator,
|
||||
DecryptedPayload,
|
||||
DecryptedPayloadInterface,
|
||||
EncryptedItemInterface,
|
||||
FileItem,
|
||||
@@ -221,8 +222,8 @@ export class MutatorService extends AbstractService implements MutatorClientInte
|
||||
public createTemplateItem<
|
||||
C extends ItemContent = ItemContent,
|
||||
I extends DecryptedItemInterface<C> = DecryptedItemInterface<C>,
|
||||
>(contentType: ContentType, content?: C): I {
|
||||
return this.itemManager.createTemplateItem(contentType, content)
|
||||
>(contentType: ContentType, content?: C, override?: Partial<DecryptedPayload<C>>): I {
|
||||
return this.itemManager.createTemplateItem(contentType, content, override)
|
||||
}
|
||||
|
||||
public async setItemNeedsSync(
|
||||
|
||||
Reference in New Issue
Block a user