refactor: component manager usecases (#2354)

This commit is contained in:
Mo
2023-07-13 05:46:52 -05:00
committed by GitHub
parent ecc5b5e503
commit 2c68ea1d76
52 changed files with 1454 additions and 1078 deletions

View File

@@ -1,13 +1,13 @@
import { FindNativeTheme, GetNativeThemes, ThemeFeatureDescription } from '@standardnotes/features'
import { ComponentOrNativeFeature, ThemeInterface } from '@standardnotes/models'
import { UIFeature, ThemeInterface } from '@standardnotes/models'
import { ItemManagerInterface } from '@standardnotes/services'
export class GetAllThemesUseCase {
constructor(private readonly items: ItemManagerInterface) {}
execute(options: { excludeLayerable: boolean }): {
thirdParty: ComponentOrNativeFeature<ThemeFeatureDescription>[]
native: ComponentOrNativeFeature<ThemeFeatureDescription>[]
thirdParty: UIFeature<ThemeFeatureDescription>[]
native: UIFeature<ThemeFeatureDescription>[]
} {
const nativeThemes = GetNativeThemes().filter((feature) => (options.excludeLayerable ? !feature.layerable : true))
@@ -22,8 +22,8 @@ export class GetAllThemesUseCase {
})
return {
thirdParty: filteredThirdPartyThemes.map((theme) => new ComponentOrNativeFeature<ThemeFeatureDescription>(theme)),
native: nativeThemes.map((theme) => new ComponentOrNativeFeature(theme)),
thirdParty: filteredThirdPartyThemes.map((theme) => new UIFeature<ThemeFeatureDescription>(theme)),
native: nativeThemes.map((theme) => new UIFeature(theme)),
}
}
}

View File

@@ -1,6 +1,6 @@
import { dismissToast, ToastType, addTimedToast } from '@standardnotes/toast'
import {
ComponentOrNativeFeature,
UIFeature,
CreateDecryptedLocalStorageContextPayload,
LocalStorageDecryptedContextualPayload,
PrefKey,
@@ -44,7 +44,7 @@ export class ThemeManager extends AbstractUIServicee {
if (desktopService) {
this.eventDisposers.push(
desktopService.registerUpdateObserver((component) => {
const uiFeature = new ComponentOrNativeFeature<ThemeFeatureDescription>(component)
const uiFeature = new UIFeature<ThemeFeatureDescription>(component)
if (uiFeature.isThemeComponent) {
if (this.components.isThemeActive(uiFeature)) {
this.deactivateThemeInTheUI(uiFeature.uniqueIdentifier)
@@ -81,7 +81,7 @@ export class ThemeManager extends AbstractUIServicee {
this.application.items.findItem<ThemeInterface>(activeTheme)
if (theme) {
const uiFeature = new ComponentOrNativeFeature<ThemeFeatureDescription>(theme)
const uiFeature = new UIFeature<ThemeFeatureDescription>(theme)
this.activateTheme(uiFeature)
hasChange = true
}
@@ -296,7 +296,7 @@ export class ThemeManager extends AbstractUIServicee {
}
}
private activateTheme(theme: ComponentOrNativeFeature<ThemeFeatureDescription>, skipEntitlementCheck = false) {
private activateTheme(theme: UIFeature<ThemeFeatureDescription>, skipEntitlementCheck = false) {
if (this.themesActiveInTheUI.find((uuid) => uuid === theme.uniqueIdentifier)) {
return
}
@@ -308,7 +308,7 @@ export class ThemeManager extends AbstractUIServicee {
return
}
const url = this.application.componentManager.urlForComponent(theme)
const url = this.application.componentManager.urlForFeature(theme)
if (!url) {
return
}
@@ -383,7 +383,7 @@ export class ThemeManager extends AbstractUIServicee {
return this.application.setValue(CachedThemesKey, mapped, StorageValueModes.Nonwrapped)
}
private getCachedThemes(): ComponentOrNativeFeature<ThemeFeatureDescription>[] {
private getCachedThemes(): UIFeature<ThemeFeatureDescription>[] {
const cachedThemes = this.application.getValue<LocalStorageDecryptedContextualPayload[]>(
CachedThemesKey,
StorageValueModes.Nonwrapped,
@@ -396,7 +396,7 @@ export class ThemeManager extends AbstractUIServicee {
const theme = this.application.items.createItemFromPayload<ThemeInterface>(payload)
themes.push(theme)
}
return themes.map((theme) => new ComponentOrNativeFeature<ThemeFeatureDescription>(theme))
return themes.map((theme) => new UIFeature<ThemeFeatureDescription>(theme))
} else {
return []
}