refactor: native feature management (#2350)

This commit is contained in:
Mo
2023-07-12 12:56:08 -05:00
committed by GitHub
parent 49f7581cd8
commit 078ef3772c
223 changed files with 3996 additions and 3438 deletions

View File

@@ -0,0 +1,29 @@
import { FindNativeTheme, GetNativeThemes, ThemeFeatureDescription } from '@standardnotes/features'
import { ComponentOrNativeFeature, 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>[]
} {
const nativeThemes = GetNativeThemes().filter((feature) => (options.excludeLayerable ? !feature.layerable : true))
const allThirdPartyThemes = this.items
.getDisplayableComponents()
.filter(
(component) => component.isTheme() && FindNativeTheme(component.identifier) === undefined,
) as ThemeInterface[]
const filteredThirdPartyThemes = allThirdPartyThemes.filter((theme) => {
return options.excludeLayerable ? !theme.layerable : true
})
return {
thirdParty: filteredThirdPartyThemes.map((theme) => new ComponentOrNativeFeature<ThemeFeatureDescription>(theme)),
native: nativeThemes.map((theme) => new ComponentOrNativeFeature(theme)),
}
}
}