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

@@ -325,7 +325,7 @@ export class WebApplication extends SNApplication implements WebApplicationInter
public getItemTags(item: DecryptedItemInterface) {
return this.items.itemsReferencingItem(item).filter((ref) => {
return ref.content_type === ContentType.Tag
return ref.content_type === ContentType.TYPES.Tag
}) as SNTag[]
}
@@ -397,7 +397,7 @@ export class WebApplication extends SNApplication implements WebApplicationInter
async handleReceivedTextEvent({ text, title }: { text: string; title?: string | undefined }) {
const titleForNote = title || this.getViewControllerManager().itemListController.titleForNewNote()
const note = this.items.createTemplateItem<NoteContent, SNNote>(ContentType.Note, {
const note = this.items.createTemplateItem<NoteContent, SNNote>(ContentType.TYPES.Note, {
title: titleForNote,
text: text,
references: [],

View File

@@ -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]',
}}

View File

@@ -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

View File

@@ -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:

View File

@@ -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 =

View File

@@ -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?: {

View File

@@ -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)}

View File

@@ -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)
)
}

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)

View File

@@ -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,

View File

@@ -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,
},
]

View File

@@ -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 = {

View File

@@ -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>
)}

View File

@@ -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)))
})

View File

@@ -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')

View File

@@ -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 {

View File

@@ -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])

View File

@@ -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()
})

View File

@@ -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)

View File

@@ -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) {

View File

@@ -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,

View File

@@ -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])

View File

@@ -23,7 +23,7 @@ export class PersistenceService {
this.hydratePersistedValues()
this.didHydrateOnce = true
} else if (eventName === ApplicationEvent.LocalDataIncrementalLoad) {
const canHydrate = this.application.items.getItems([ContentType.Note, ContentType.Tag]).length > 0
const canHydrate = this.application.items.getItems([ContentType.TYPES.Note, ContentType.TYPES.Tag]).length > 0
if (!canHydrate) {
return

View File

@@ -77,9 +77,9 @@ export class AccountMenuController extends AbstractViewController {
)
this.disposers.push(
this.application.streamItems([ContentType.Note, ContentType.Tag], () => {
this.application.streamItems([ContentType.TYPES.Note, ContentType.TYPES.Tag], () => {
runInAction(() => {
this.notesAndTags = this.application.items.getItems([ContentType.Note, ContentType.Tag])
this.notesAndTags = this.application.items.getItems([ContentType.TYPES.Note, ContentType.TYPES.Tag])
})
}),
)

View File

@@ -21,7 +21,7 @@ export class FilePreviewModalController {
})
this.eventObservers.push(
application.streamItems(ContentType.File, ({ changed, removed }) => {
application.streamItems(ContentType.TYPES.File, ({ changed, removed }) => {
if (!this.currentFile) {
return
}

View File

@@ -88,7 +88,7 @@ export class FilesController extends AbstractViewController<FilesControllerEvent
})
this.disposers.push(
application.streamItems(ContentType.File, () => {
application.streamItems(ContentType.TYPES.File, () => {
this.reloadAllFiles()
this.reloadAttachedFiles()
}),

View File

@@ -91,8 +91,8 @@ export class ImportModalController {
try {
await this.importer.importFromTransferPayloads(payloads)
const notesImported = payloads.filter((payload) => payload.content_type === ContentType.Note)
const tagsImported = payloads.filter((payload) => payload.content_type === ContentType.Tag)
const notesImported = payloads.filter((payload) => payload.content_type === ContentType.TYPES.Note)
const tagsImported = payloads.filter((payload) => payload.content_type === ContentType.TYPES.Tag)
const successMessage =
`Successfully imported ${notesImported.length} ` +
@@ -149,14 +149,14 @@ export class ImportModalController {
}
}
const currentDate = new Date()
const importTagItem = this.application.items.createTemplateItem<TagContent, SNTag>(ContentType.Tag, {
const importTagItem = this.application.items.createTemplateItem<TagContent, SNTag>(ContentType.TYPES.Tag, {
title: `Imported on ${currentDate.toLocaleString()}`,
expanded: false,
iconString: '',
references: importedPayloads
.filter((payload) => payload.content_type === ContentType.Note)
.filter((payload) => payload.content_type === ContentType.TYPES.Note)
.map((payload) => ({
content_type: ContentType.Note,
content_type: ContentType.TYPES.Note,
uuid: payload.uuid,
})),
})

View File

@@ -1,5 +1,4 @@
import { SNTag } from '@standardnotes/snjs'
import { ContentType } from '@standardnotes/common'
import { ContentType, SNTag } from '@standardnotes/snjs'
import { InternalEventBus } from '@standardnotes/services'
import { WebApplication } from '@/Application/WebApplication'
import { NavigationController } from '../Navigation/NavigationController'
@@ -57,7 +56,7 @@ describe('item list controller', () => {
it('should return false first item is file', () => {
controller.getFirstNonProtectedItem = jest.fn().mockReturnValue({
content_type: ContentType.File,
content_type: ContentType.TYPES.File,
})
expect(controller.shouldSelectFirstItem(ItemsReloadSource.UserTriggeredTagChange)).toBe(false)
@@ -66,7 +65,7 @@ describe('item list controller', () => {
it('should return false if selected tag is daily entry', () => {
const tag = {
isDailyEntry: true,
content_type: ContentType.Tag,
content_type: ContentType.TYPES.Tag,
} as jest.Mocked<SNTag>
Object.defineProperty(navigationController, 'selected', {
@@ -78,7 +77,7 @@ describe('item list controller', () => {
it('should return true if user triggered tag change', () => {
const tag = {
content_type: ContentType.Tag,
content_type: ContentType.TYPES.Tag,
} as jest.Mocked<SNTag>
Object.defineProperty(navigationController, 'selected', {
@@ -90,7 +89,7 @@ describe('item list controller', () => {
it('should return false if not user triggered tag change and there is an existing selected item', () => {
const tag = {
content_type: ContentType.Tag,
content_type: ContentType.TYPES.Tag,
} as jest.Mocked<SNTag>
Object.defineProperty(selectionController, 'selectedUuids', {

View File

@@ -109,27 +109,33 @@ export class ItemListController extends AbstractViewController implements Intern
this.resetPagination()
this.disposers.push(
application.streamItems<SNNote>([ContentType.Note, ContentType.File], () => {
application.streamItems<SNNote>([ContentType.TYPES.Note, ContentType.TYPES.File], () => {
void this.reloadItems(ItemsReloadSource.ItemStream)
}),
)
this.disposers.push(
application.streamItems<SNTag>([ContentType.Tag, ContentType.SmartView], async ({ changed, inserted }) => {
const tags = [...changed, ...inserted]
application.streamItems<SNTag>(
[ContentType.TYPES.Tag, ContentType.TYPES.SmartView],
async ({ changed, inserted }) => {
const tags = [...changed, ...inserted]
const { didReloadItems } = await this.reloadDisplayPreferences({ userTriggered: false })
if (!didReloadItems) {
/** A tag could have changed its relationships, so we need to reload the filter */
this.reloadNotesDisplayOptions()
void this.reloadItems(ItemsReloadSource.ItemStream)
}
const { didReloadItems } = await this.reloadDisplayPreferences({ userTriggered: false })
if (!didReloadItems) {
/** A tag could have changed its relationships, so we need to reload the filter */
this.reloadNotesDisplayOptions()
void this.reloadItems(ItemsReloadSource.ItemStream)
}
if (this.navigationController.selected && findInArray(tags, 'uuid', this.navigationController.selected.uuid)) {
/** Tag title could have changed */
this.reloadPanelTitle()
}
}),
if (
this.navigationController.selected &&
findInArray(tags, 'uuid', this.navigationController.selected.uuid)
) {
/** Tag title could have changed */
this.reloadPanelTitle()
}
},
),
)
this.disposers.push(

View File

@@ -29,7 +29,7 @@ const createNote = (name: string, options?: Partial<SNNote>) => {
archived: false,
trashed: false,
uuid: String(Math.random()),
content_type: ContentType.Note,
content_type: ContentType.TYPES.Note,
...options,
} as jest.Mocked<SNNote>
}
@@ -40,7 +40,7 @@ const createFile = (name: string, options?: Partial<FileItem>) => {
archived: false,
trashed: false,
uuid: String(Math.random()),
content_type: ContentType.File,
content_type: ContentType.TYPES.File,
...options,
} as jest.Mocked<FileItem>
}

View File

@@ -100,7 +100,7 @@ export class LinkingController extends AbstractViewController {
const referencingItem = naturalSort(this.application.items.itemsReferencingItem(item).filter(isFile), 'title')
if (item.content_type === ContentType.File) {
if (item.content_type === ContentType.TYPES.File) {
return {
filesLinkedToItem: referencesOfItem.map((item) => createLinkFromItem(item, 'linked')),
filesLinkingToItem: referencingItem.map((item) => createLinkFromItem(item, 'linked-by')),

View File

@@ -122,7 +122,7 @@ export class NavigationController
})
this.disposers.push(
this.application.streamItems([ContentType.Tag, ContentType.SmartView], ({ changed, removed }) => {
this.application.streamItems([ContentType.TYPES.Tag, ContentType.TYPES.SmartView], ({ changed, removed }) => {
this.reloadTags()
runInAction(() => {
@@ -599,7 +599,7 @@ export class NavigationController
return
}
const newTag = this.application.items.createTemplateItem(ContentType.Tag) as SNTag
const newTag = this.application.items.createTemplateItem(ContentType.TYPES.Tag) as SNTag
runInAction(() => {
this.selectedLocation = 'all'

View File

@@ -119,7 +119,7 @@ export class NotesController extends AbstractViewController implements NotesCont
}
public get selectedNotes(): SNNote[] {
return this.selectionController.getFilteredSelectedItems<SNNote>(ContentType.Note)
return this.selectionController.getFilteredSelectedItems<SNNote>(ContentType.TYPES.Note)
}
get firstSelectedNote(): SNNote | undefined {

View File

@@ -94,7 +94,7 @@ export class SelectedItemsController
this.disposers.push(
this.application.streamItems<SNNote | FileItem>(
[ContentType.Note, ContentType.File],
[ContentType.TYPES.Note, ContentType.TYPES.File],
({ changed, inserted, removed }) => {
runInAction(() => {
for (const removedItem of removed) {
@@ -121,7 +121,7 @@ export class SelectedItemsController
}
get selectedFiles(): FileItem[] {
return this.getFilteredSelectedItems<FileItem>(ContentType.File)
return this.getFilteredSelectedItems<FileItem>(ContentType.TYPES.File)
}
get selectedFilesCount(): number {
@@ -137,7 +137,7 @@ export class SelectedItemsController
return uuids.map((uuid) => this.application.items.findSureItem<SNNote | FileItem>(uuid)).filter((item) => !!item)
}
getFilteredSelectedItems = <T extends ListableContentItem = ListableContentItem>(contentType?: ContentType): T[] => {
getFilteredSelectedItems = <T extends ListableContentItem = ListableContentItem>(contentType?: string): T[] => {
return Object.values(this.selectedItems).filter((item) => {
return !contentType ? true : item.content_type === contentType
}) as T[]
@@ -243,9 +243,9 @@ export class SelectedItemsController
if (this.selectedItemsCount === 1) {
const item = this.firstSelectedItem
if (item.content_type === ContentType.Note) {
if (item.content_type === ContentType.TYPES.Note) {
await this.itemListController.openNote(item.uuid)
} else if (item.content_type === ContentType.File) {
} else if (item.content_type === ContentType.TYPES.File) {
await this.itemListController.openFile(item.uuid)
}

View File

@@ -17,7 +17,7 @@ export const useItemLinks = (item: DecryptedItem | undefined) => {
useEffect(
() =>
application.streamItems([ContentType.Note, ContentType.File, ContentType.Tag], () => {
application.streamItems([ContentType.TYPES.Note, ContentType.TYPES.File, ContentType.TYPES.Tag], () => {
refresh(Date.now())
}),
[application],

View File

@@ -19,7 +19,7 @@ export function getLinkingSearchResults(
application: WebApplicationInterface,
activeItem?: LinkableItem,
options: {
contentType?: ContentType
contentType?: string
returnEmptyIfQueryEmpty?: boolean
} = { returnEmptyIfQueryEmpty: true },
): {
@@ -49,7 +49,7 @@ export function getLinkingSearchResults(
}
const searchableItems = naturalSort(
application.items.getItems([ContentType.Note, ContentType.File, ContentType.Tag]),
application.items.getItems([ContentType.TYPES.Note, ContentType.TYPES.File, ContentType.TYPES.Tag]),
'title',
)
@@ -85,19 +85,26 @@ export function getLinkingSearchResults(
const limitPerContentType = resultLimitForSearchQuery(searchQuery)
if (
item.content_type === ContentType.Tag &&
(!enforceResultLimit || (unlinkedTags.length < limitPerContentType && item.content_type === ContentType.Tag))
item.content_type === ContentType.TYPES.Tag &&
(!enforceResultLimit ||
(unlinkedTags.length < limitPerContentType && item.content_type === ContentType.TYPES.Tag))
) {
unlinkedTags.push(item)
continue
}
if (item.content_type === ContentType.Note && (!enforceResultLimit || unlinkedNotes.length < limitPerContentType)) {
if (
item.content_type === ContentType.TYPES.Note &&
(!enforceResultLimit || unlinkedNotes.length < limitPerContentType)
) {
unlinkedNotes.push(item)
continue
}
if (item.content_type === ContentType.File && (!enforceResultLimit || unlinkedFiles.length < limitPerContentType)) {
if (
item.content_type === ContentType.TYPES.File &&
(!enforceResultLimit || unlinkedFiles.length < limitPerContentType)
) {
unlinkedFiles.push(item)
continue
}

View File

@@ -1,5 +1,5 @@
import { DecryptedItemInterface, ItemContent, ContentType } from '@standardnotes/snjs'
export function isSearchResultExistingTag(result: DecryptedItemInterface<ItemContent>, searchQuery: string) {
return result.content_type === ContentType.Tag && result.title === searchQuery
return result.content_type === ContentType.TYPES.Tag && result.title === searchQuery
}

View File

@@ -36,7 +36,7 @@ const insertNonInstalledNativeComponentsInMap = (
application: WebApplication,
): void => {
GetFeatures()
.filter((feature) => feature.content_type === ContentType.Component && feature.area === ComponentArea.Editor)
.filter((feature) => feature.content_type === ContentType.TYPES.Component && feature.area === ComponentArea.Editor)
.forEach((editorFeature) => {
const notInstalled = !components.find((editor) => editor.identifier === editorFeature.identifier)
const isExperimental = application.features.isExperimentalFeature(editorFeature.identifier)