chore: fix ContentType usage (#2353)
* chore: fix ContentType usage * chore: fix specs
This commit is contained in:
@@ -209,7 +209,7 @@ const ClipperView = ({
|
||||
|
||||
const editorStateJSON = await getSuperJSONFromClipPayload(clipPayload)
|
||||
|
||||
const note = application.items.createTemplateItem<NoteContent, SNNote>(ContentType.Note, {
|
||||
const note = application.items.createTemplateItem<NoteContent, SNNote>(ContentType.TYPES.Note, {
|
||||
title: clipPayload.title,
|
||||
text: editorStateJSON,
|
||||
editorIdentifier: FeatureIdentifier.SuperEditor,
|
||||
@@ -401,7 +401,7 @@ const ClipperView = ({
|
||||
<ItemSelectionDropdown
|
||||
onSelection={selectTag}
|
||||
placeholder="Select tag to save clipped notes to..."
|
||||
contentTypes={[ContentType.Tag]}
|
||||
contentTypes={[ContentType.TYPES.Tag]}
|
||||
className={{
|
||||
input: 'text-[0.85rem]',
|
||||
}}
|
||||
|
||||
@@ -95,7 +95,7 @@ const ContentList: FunctionComponent<Props> = ({
|
||||
[hideTags, selectedTag, application],
|
||||
)
|
||||
|
||||
const hasNotes = items.some((item) => item.content_type === ContentType.Note)
|
||||
const hasNotes = items.some((item) => item.content_type === ContentType.TYPES.Note)
|
||||
|
||||
return (
|
||||
<div
|
||||
|
||||
@@ -7,9 +7,9 @@ import { ListableContentItem } from './Types/ListableContentItem'
|
||||
|
||||
const ContentListItem: FunctionComponent<AbstractListItemProps<ListableContentItem>> = (props) => {
|
||||
switch (props.item.content_type) {
|
||||
case ContentType.Note:
|
||||
case ContentType.TYPES.Note:
|
||||
return <NoteListItem {...props} item={props.item as SNNote} />
|
||||
case ContentType.File: {
|
||||
case ContentType.TYPES.File: {
|
||||
return <FileListItem {...props} item={props.item as FileItem} />
|
||||
}
|
||||
default:
|
||||
|
||||
@@ -63,11 +63,11 @@ const ImportModalFileItem = ({
|
||||
|
||||
const notePayloads =
|
||||
file.status === 'ready' && file.payloads
|
||||
? file.payloads.filter((payload) => payload.content_type === ContentType.Note)
|
||||
? file.payloads.filter((payload) => payload.content_type === ContentType.TYPES.Note)
|
||||
: []
|
||||
const tagPayloads =
|
||||
file.status === 'ready' && file.payloads
|
||||
? file.payloads.filter((payload) => payload.content_type === ContentType.Tag)
|
||||
? file.payloads.filter((payload) => payload.content_type === ContentType.TYPES.Tag)
|
||||
: []
|
||||
|
||||
const payloadsImportMessage =
|
||||
|
||||
@@ -7,14 +7,14 @@ import {
|
||||
useComboboxStore,
|
||||
VisuallyHidden,
|
||||
} from '@ariakit/react'
|
||||
import { classNames, ContentType, DecryptedItem, naturalSort } from '@standardnotes/snjs'
|
||||
import { classNames, DecryptedItem, naturalSort } from '@standardnotes/snjs'
|
||||
import { observer } from 'mobx-react-lite'
|
||||
import { useDeferredValue, useEffect, useState } from 'react'
|
||||
import { useApplication } from '../ApplicationProvider'
|
||||
import LinkedItemMeta from '../LinkedItems/LinkedItemMeta'
|
||||
|
||||
type Props = {
|
||||
contentTypes: ContentType[]
|
||||
contentTypes: string[]
|
||||
placeholder: string
|
||||
onSelection: (item: DecryptedItem) => void
|
||||
className?: {
|
||||
|
||||
@@ -120,7 +120,7 @@ const LinkedItemBubble = ({
|
||||
<span className="flex items-center overflow-hidden overflow-ellipsis whitespace-nowrap">
|
||||
{tagTitle && <span className="text-passive-1">{tagTitle.titlePrefix}</span>}
|
||||
<span className="flex items-center gap-1">
|
||||
{link.type === 'linked-by' && link.item.content_type !== ContentType.Tag && (
|
||||
{link.type === 'linked-by' && link.item.content_type !== ContentType.TYPES.Tag && (
|
||||
<span className={!isBidirectional ? 'hidden group-focus:block' : ''}>Linked By:</span>
|
||||
)}
|
||||
{getItemTitleInContextOfLinkBubble(link.item)}
|
||||
|
||||
@@ -115,7 +115,7 @@ const LinkedItemBubblesContainer = ({
|
||||
|
||||
return (
|
||||
existsInAllItemLinks &&
|
||||
(link.item.content_type === ContentType.Note ? existsInNotesLinkingToItem : existsInFilesLinkingToItem)
|
||||
(link.item.content_type === ContentType.TYPES.Note ? existsInNotesLinkingToItem : existsInFilesLinkingToItem)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(),
|
||||
)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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[],
|
||||
})
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -55,7 +55,7 @@ const Appearance: FunctionComponent<Props> = ({ application }) => {
|
||||
})
|
||||
|
||||
GetFeatures()
|
||||
.filter((feature) => feature.content_type === ContentType.Theme && !feature.layerable)
|
||||
.filter((feature) => feature.content_type === ContentType.TYPES.Theme && !feature.layerable)
|
||||
.forEach((theme) => {
|
||||
themesAsItems.push({
|
||||
label: theme.name as string,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { DisplayStringForContentType } from '@standardnotes/snjs'
|
||||
import { ContentType } from '@standardnotes/snjs'
|
||||
|
||||
import Button from '@/Components/Button/Button'
|
||||
import { Fragment, FunctionComponent } from 'react'
|
||||
import { Title, Text, Subtitle } from '@/Components/Preferences/PreferencesComponents/Content'
|
||||
@@ -9,6 +10,12 @@ const ConfirmCustomPackage: FunctionComponent<{
|
||||
component: AnyPackageType
|
||||
callback: (confirmed: boolean) => void
|
||||
}> = ({ component, callback }) => {
|
||||
let contentTypeDisplayName = null
|
||||
const contentTypeOrError = ContentType.create(component.content_type)
|
||||
if (!contentTypeOrError.isFailed()) {
|
||||
contentTypeDisplayName = contentTypeOrError.getValue().getDisplayName()
|
||||
}
|
||||
|
||||
const fields = [
|
||||
{
|
||||
label: 'Name',
|
||||
@@ -32,7 +39,7 @@ const ConfirmCustomPackage: FunctionComponent<{
|
||||
},
|
||||
{
|
||||
label: 'Extension Type',
|
||||
value: DisplayStringForContentType(component.content_type),
|
||||
value: contentTypeDisplayName,
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
@@ -13,9 +13,9 @@ import PreferencesSegment from '../../../../PreferencesComponents/PreferencesSeg
|
||||
|
||||
const loadExtensions = (application: WebApplication) =>
|
||||
application.items.getItems([
|
||||
ContentType.ActionsExtension,
|
||||
ContentType.Component,
|
||||
ContentType.Theme,
|
||||
ContentType.TYPES.ActionsExtension,
|
||||
ContentType.TYPES.Component,
|
||||
ContentType.TYPES.Theme,
|
||||
]) as AnyPackageType[]
|
||||
|
||||
type Props = {
|
||||
|
||||
@@ -104,7 +104,7 @@ const Moments: FunctionComponent<Props> = ({ application }: Props) => {
|
||||
<ItemSelectionDropdown
|
||||
onSelection={selectTag}
|
||||
placeholder="Select tag to save Moments to..."
|
||||
contentTypes={[ContentType.Tag]}
|
||||
contentTypes={[ContentType.TYPES.Tag]}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -33,7 +33,7 @@ const SmartViews = ({ application, featuresController }: Props) => {
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
const disposeItemStream = application.streamItems([ContentType.SmartView], () => {
|
||||
const disposeItemStream = application.streamItems([ContentType.TYPES.SmartView], () => {
|
||||
setSmartViews(application.items.getSmartViews().filter((view) => !isSystemView(view)))
|
||||
})
|
||||
|
||||
|
||||
@@ -9,8 +9,10 @@ import { formatCount } from './formatCount'
|
||||
const EncryptionEnabled: FunctionComponent = () => {
|
||||
const application = useApplication()
|
||||
const itemCounter = new StaticItemCounter()
|
||||
const count = itemCounter.countNotesAndTags(application.items.getItems([ContentType.Note, ContentType.Tag]))
|
||||
const files = application.items.getItems([ContentType.File])
|
||||
const count = itemCounter.countNotesAndTags(
|
||||
application.items.getItems([ContentType.TYPES.Note, ContentType.TYPES.Tag]),
|
||||
)
|
||||
const files = application.items.getItems([ContentType.TYPES.File])
|
||||
const notes = formatCount(count.notes, 'notes')
|
||||
const tags = formatCount(count.tags, 'tags')
|
||||
const archived = formatCount(count.archived, 'archived notes')
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
import { observer } from 'mobx-react-lite'
|
||||
import { Fragment, FunctionComponent, useEffect, useState } from 'react'
|
||||
import { Text, Title, Subtitle } from '@/Components/Preferences/PreferencesComponents/Content'
|
||||
import {
|
||||
ButtonType,
|
||||
ClientDisplayableError,
|
||||
ContentType,
|
||||
DisplayStringForContentType,
|
||||
EncryptedItemInterface,
|
||||
} from '@standardnotes/snjs'
|
||||
import { ButtonType, ClientDisplayableError, ContentType, EncryptedItemInterface } from '@standardnotes/snjs'
|
||||
import Button from '@/Components/Button/Button'
|
||||
import HorizontalSeparator from '@/Components/Shared/HorizontalSeparator'
|
||||
import PreferencesSegment from '../../PreferencesComponents/PreferencesSegment'
|
||||
@@ -20,13 +14,17 @@ const ErroredItems: FunctionComponent = () => {
|
||||
const [erroredItems, setErroredItems] = useState(application.items.invalidNonVaultedItems)
|
||||
|
||||
useEffect(() => {
|
||||
return application.streamItems(ContentType.Any, () => {
|
||||
return application.streamItems(ContentType.TYPES.Any, () => {
|
||||
setErroredItems(application.items.invalidNonVaultedItems)
|
||||
})
|
||||
}, [application])
|
||||
|
||||
const getContentTypeDisplay = (item: EncryptedItemInterface): string => {
|
||||
const display = DisplayStringForContentType(item.content_type)
|
||||
const contentTypeOrError = ContentType.create(item.content_type)
|
||||
let display = null
|
||||
if (!contentTypeOrError.isFailed()) {
|
||||
display = contentTypeOrError.getValue().getDisplayName()
|
||||
}
|
||||
if (display) {
|
||||
return `${display[0].toUpperCase()}${display.slice(1)}`
|
||||
} else {
|
||||
|
||||
@@ -61,7 +61,7 @@ const Vaults = () => {
|
||||
}, [application.sharedVaults, updateAllData])
|
||||
|
||||
useEffect(() => {
|
||||
return application.streamItems([ContentType.VaultListing, ContentType.TrustedContact], () => {
|
||||
return application.streamItems([ContentType.TYPES.VaultListing, ContentType.TYPES.TrustedContact], () => {
|
||||
void updateAllData()
|
||||
})
|
||||
}, [application, updateAllData])
|
||||
|
||||
@@ -43,7 +43,7 @@ const QuickSettingsMenu: FunctionComponent<MenuProps> = ({ application, quickSet
|
||||
}) as ThemeItem[]
|
||||
|
||||
GetFeatures()
|
||||
.filter((feature) => feature.content_type === ContentType.Theme && !feature.layerable)
|
||||
.filter((feature) => feature.content_type === ContentType.TYPES.Theme && !feature.layerable)
|
||||
.forEach((theme) => {
|
||||
if (themes.findIndex((item) => item.identifier === theme.identifier) === -1) {
|
||||
themes.push({
|
||||
@@ -76,7 +76,7 @@ const QuickSettingsMenu: FunctionComponent<MenuProps> = ({ application, quickSet
|
||||
}, [reloadThemes, themes.length])
|
||||
|
||||
useEffect(() => {
|
||||
const cleanupItemStream = application.streamItems(ContentType.Theme, () => {
|
||||
const cleanupItemStream = application.streamItems(ContentType.TYPES.Theme, () => {
|
||||
reloadThemes()
|
||||
})
|
||||
|
||||
@@ -86,7 +86,7 @@ const QuickSettingsMenu: FunctionComponent<MenuProps> = ({ application, quickSet
|
||||
}, [application, reloadThemes])
|
||||
|
||||
useEffect(() => {
|
||||
const cleanupItemStream = application.streamItems(ContentType.Component, () => {
|
||||
const cleanupItemStream = application.streamItems(ContentType.TYPES.Component, () => {
|
||||
reloadToggleableComponents()
|
||||
})
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ export const ItemSelectionPlugin: FunctionComponent<Props> = ({ currentNote }) =
|
||||
return new ItemOption(item, item.title || '', {
|
||||
onSelect: (_queryString: string) => {
|
||||
void linkingController.linkItems(currentNote, item)
|
||||
if (item.content_type === ContentType.File) {
|
||||
if (item.content_type === ContentType.TYPES.File) {
|
||||
editor.dispatchCommand(INSERT_FILE_COMMAND, item.uuid)
|
||||
} else {
|
||||
editor.dispatchCommand(INSERT_BUBBLE_COMMAND, item.uuid)
|
||||
|
||||
@@ -9,7 +9,7 @@ const ReadonlyPlugin = ({ note }: { note: SNNote }) => {
|
||||
const [readOnly, setReadOnly] = useState(note.locked)
|
||||
|
||||
useEffect(() => {
|
||||
return application.streamItems<SNNote>(ContentType.Note, ({ changed }) => {
|
||||
return application.streamItems<SNNote>(ContentType.TYPES.Note, ({ changed }) => {
|
||||
const changedNoteItem = changed.find((changedItem) => changedItem.uuid === note.uuid)
|
||||
|
||||
if (changedNoteItem) {
|
||||
|
||||
@@ -55,7 +55,7 @@ const SuperNoteConverter = ({
|
||||
return undefined
|
||||
}
|
||||
|
||||
const templateNoteForRevision = application.items.createTemplateItem<NoteContent, SNNote>(ContentType.Note, {
|
||||
const templateNoteForRevision = application.items.createTemplateItem<NoteContent, SNNote>(ContentType.TYPES.Note, {
|
||||
title: note.title,
|
||||
text: convertedContent,
|
||||
references: note.references,
|
||||
|
||||
@@ -101,7 +101,7 @@ const SmartViewsListItem: FunctionComponent<Props> = ({ view, tagsState, setEdit
|
||||
return
|
||||
}
|
||||
|
||||
return application.streamItems(ContentType.Note, () => {
|
||||
return application.streamItems(ContentType.TYPES.Note, () => {
|
||||
setConflictsCount(application.items.numberOfNotesWithConflicts())
|
||||
})
|
||||
}, [application, view])
|
||||
|
||||
Reference in New Issue
Block a user