Rather than repeatedly fetching the license summary, this commit fetches it once at the top-level and keeps it until an EVENT_REFRESH reaches the top level. This prevents the FOUC (Flash Of Unavailable Content) while loading and awaiting the end of the load.
26 lines
799 B
TypeScript
26 lines
799 B
TypeScript
import { authentikEnterpriseContext } from "@goauthentik/elements/AuthentikContexts";
|
|
|
|
import { consume } from "@lit-labs/context";
|
|
import type { LitElement } from "lit";
|
|
|
|
import type { LicenseSummary } from "@goauthentik/api";
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
type Constructor<T = object> = abstract new (...args: any[]) => T;
|
|
|
|
export function WithLicenseSummary<T extends Constructor<LitElement>>(
|
|
superclass: T,
|
|
subscribe = true
|
|
) {
|
|
abstract class WithEnterpriseProvider extends superclass {
|
|
@consume({ context: authentikEnterpriseContext, subscribe })
|
|
public licenseSummary!: LicenseSummary;
|
|
|
|
get hasEnterpriseLicense() {
|
|
return this.licenseSummary?.hasLicense;
|
|
}
|
|
}
|
|
|
|
return WithEnterpriseProvider;
|
|
}
|