chore: fix ContentType usage (#2353)

* chore: fix ContentType usage

* chore: fix specs
This commit is contained in:
Karol Sójko
2023-07-12 13:53:29 +02:00
committed by GitHub
parent d057cdff84
commit 325737bfbd
247 changed files with 1092 additions and 1060 deletions

View File

@@ -1,5 +1,5 @@
import { FileItem } from '@standardnotes/models'
import { ContentType } from '@standardnotes/common'
import { ContentType } from '@standardnotes/domain-core'
import { SNApplication } from '@standardnotes/snjs'
import { ItemViewControllerInterface } from './ItemViewControllerInterface'
@@ -23,20 +23,23 @@ export class FileViewController implements ItemViewControllerInterface {
}
private streamItems() {
this.removeStreamObserver = this.application.streamItems<FileItem>(ContentType.File, ({ changed, inserted }) => {
if (this.dealloced) {
return
}
this.removeStreamObserver = this.application.streamItems<FileItem>(
ContentType.TYPES.File,
({ changed, inserted }) => {
if (this.dealloced) {
return
}
const files = changed.concat(inserted)
const files = changed.concat(inserted)
const matchingFile = files.find((item) => {
return item.uuid === this.item.uuid
})
const matchingFile = files.find((item) => {
return item.uuid === this.item.uuid
})
if (matchingFile) {
this.item = matchingFile
}
})
if (matchingFile) {
this.item = matchingFile
}
},
)
}
}

View File

@@ -1,5 +1,5 @@
import { WebApplication } from '@/Application/WebApplication'
import { ContentType } from '@standardnotes/common'
import { ContentType } from '@standardnotes/domain-core'
import {
MutatorService,
SNComponentManager,
@@ -47,7 +47,7 @@ describe('note view controller', () => {
await controller.initialize()
expect(application.items.createTemplateItem).toHaveBeenCalledWith(
ContentType.Note,
ContentType.TYPES.Note,
expect.objectContaining({ noteType: NoteType.Plain }),
expect.anything(),
)
@@ -68,7 +68,7 @@ describe('note view controller', () => {
await controller.initialize()
expect(application.items.createTemplateItem).toHaveBeenCalledWith(
ContentType.Note,
ContentType.TYPES.Note,
expect.objectContaining({ noteType: NoteType.Markdown }),
expect.anything(),
)

View File

@@ -11,7 +11,7 @@ import {
} from '@standardnotes/models'
import { UuidString } from '@standardnotes/snjs'
import { removeFromArray } from '@standardnotes/utils'
import { ContentType } from '@standardnotes/common'
import { ContentType } from '@standardnotes/domain-core'
import { ItemViewControllerInterface } from './ItemViewControllerInterface'
import { TemplateNoteViewControllerOptions } from './TemplateNoteViewControllerOptions'
import { log, LoggingDomain } from '@/Logging'
@@ -99,7 +99,7 @@ export class NoteViewController implements ItemViewControllerInterface {
const noteType = noteTypeForEditorIdentifier(editorIdentifier)
const note = this.application.items.createTemplateItem<NoteContent, SNNote>(
ContentType.Note,
ContentType.TYPES.Note,
{
text: '',
title: this.templateNoteOptions?.title || '',
@@ -140,7 +140,7 @@ export class NoteViewController implements ItemViewControllerInterface {
}
this.disposers.push(
this.application.streamItems<SNNote>(ContentType.Note, ({ changed, inserted, source }) => {
this.application.streamItems<SNNote>(ContentType.TYPES.Note, ({ changed, inserted, source }) => {
if (this.dealloced) {
return
}

View File

@@ -425,21 +425,24 @@ class NoteView extends AbstractComponent<NoteViewProps, State> {
}
streamItems() {
this.removeComponentStreamObserver = this.application.streamItems(ContentType.Component, async ({ source }) => {
log(LoggingDomain.NoteView, 'On component stream observer', PayloadEmitSource[source])
if (isPayloadSourceInternalChange(source) || source === PayloadEmitSource.InitialObserverRegistrationPush) {
return
}
this.removeComponentStreamObserver = this.application.streamItems(
ContentType.TYPES.Component,
async ({ source }) => {
log(LoggingDomain.NoteView, 'On component stream observer', PayloadEmitSource[source])
if (isPayloadSourceInternalChange(source) || source === PayloadEmitSource.InitialObserverRegistrationPush) {
return
}
if (!this.note) {
return
}
if (!this.note) {
return
}
await this.reloadStackComponents()
this.debounceReloadEditorComponent()
})
await this.reloadStackComponents()
this.debounceReloadEditorComponent()
},
)
this.removeNoteStreamObserver = this.application.streamItems<SNNote>(ContentType.Note, async () => {
this.removeNoteStreamObserver = this.application.streamItems<SNNote>(ContentType.TYPES.Note, async () => {
this.setState({
conflictedNotes: this.application.items.conflictsOf(this.note.uuid) as SNNote[],
})

View File

@@ -36,7 +36,7 @@ export const ReadonlyNoteContent = ({
return undefined
}
const templateNoteForRevision = application.items.createTemplateItem(ContentType.Note, note.content) as SNNote
const templateNoteForRevision = application.items.createTemplateItem(ContentType.TYPES.Note, note.content) as SNNote
const componentViewer = application.componentManager.createComponentViewer(editorForCurrentNote)
componentViewer.setReadonly(true)