refactor: native feature management (#2350)
This commit is contained in:
29
packages/ui-services/src/Theme/GetAllThemesUseCase.ts
Normal file
29
packages/ui-services/src/Theme/GetAllThemesUseCase.ts
Normal 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)),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user