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

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