Improve feature API
This commit is contained in:
@@ -58,13 +58,11 @@ export type AnalyticsContextType = {
|
||||
payload: Metrics[E],
|
||||
metadata?: MergeableMetadata,
|
||||
) => void
|
||||
feature: (feature: Features) => boolean
|
||||
Features: typeof Features
|
||||
features: typeof Features & {
|
||||
enabled(feature: Features): boolean
|
||||
}
|
||||
}
|
||||
export type AnalyticsBaseContextType = Omit<
|
||||
AnalyticsContextType,
|
||||
'feature' | 'Features'
|
||||
>
|
||||
export type AnalyticsBaseContextType = Omit<AnalyticsContextType, 'features'>
|
||||
|
||||
function createLogger(
|
||||
context: Logger['context'],
|
||||
@@ -198,8 +196,10 @@ export function AnalyticsFeaturesContext({
|
||||
const childContext = useMemo<AnalyticsContextType>(() => {
|
||||
return {
|
||||
...parentContext,
|
||||
feature: feats.isOn.bind(feats),
|
||||
Features,
|
||||
features: {
|
||||
enabled: feats.isOn.bind(feats),
|
||||
...Features,
|
||||
},
|
||||
}
|
||||
}, [parentContext])
|
||||
|
||||
@@ -220,7 +220,7 @@ export function useAnalyticsBase() {
|
||||
*/
|
||||
export function useAnalytics() {
|
||||
const ctx = useContext(Context)
|
||||
if (!('feature' in ctx) || !('Features' in ctx)) {
|
||||
if (!('features' in ctx)) {
|
||||
throw new Error(
|
||||
'useAnalytics must be used within an AnalyticsFeaturesContext',
|
||||
)
|
||||
|
||||
@@ -20,7 +20,7 @@ export function DiscoverDebug({
|
||||
const isDiscoverDebugUser =
|
||||
IS_INTERNAL ||
|
||||
DISCOVER_DEBUG_DIDS[currentAccount?.did || ''] ||
|
||||
ax.feature(ax.Features.DebugFeedContext)
|
||||
ax.features.enabled(ax.features.DebugFeedContext)
|
||||
const theme = useTheme()
|
||||
|
||||
return (
|
||||
|
||||
@@ -465,7 +465,7 @@ let PostMenuItems = ({
|
||||
const isDiscoverDebugUser =
|
||||
IS_INTERNAL ||
|
||||
DISCOVER_DEBUG_DIDS[currentAccount?.did || ''] ||
|
||||
ax.feature(ax.Features.DebugFeedContext)
|
||||
ax.features.enabled(ax.features.DebugFeedContext)
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -15,7 +15,6 @@ import {
|
||||
} from '#/components/dialogs/nuxs/utils'
|
||||
import {Beaker_Stroke2_Corner2_Rounded as BeakerIcon} from '#/components/icons/Beaker'
|
||||
import {Text} from '#/components/Typography'
|
||||
import {Features} from '#/analytics'
|
||||
import {IS_E2E, IS_WEB} from '#/env'
|
||||
|
||||
export const enabled = createIsEnabledCheck(props => {
|
||||
@@ -25,7 +24,7 @@ export const enabled = createIsEnabledCheck(props => {
|
||||
'2026-01-16T00:00:00.000Z',
|
||||
props.currentProfile.createdAt,
|
||||
) &&
|
||||
!props.feature(Features.DisableLiveNowBeta)
|
||||
!props.features.enabled(props.features.DisableLiveNowBeta)
|
||||
)
|
||||
})
|
||||
|
||||
|
||||
@@ -133,7 +133,7 @@ function Inner({
|
||||
if (
|
||||
enabled &&
|
||||
!enabled({
|
||||
feature: ax.feature,
|
||||
features: ax.features,
|
||||
currentAccount,
|
||||
currentProfile,
|
||||
preferences,
|
||||
@@ -165,7 +165,7 @@ function Inner({
|
||||
break
|
||||
}
|
||||
}, [
|
||||
ax.feature,
|
||||
ax.features,
|
||||
nuxs,
|
||||
snoozed,
|
||||
snoozeNuxDialog,
|
||||
|
||||
@@ -6,7 +6,7 @@ import {type AnalyticsContextType} from '#/analytics'
|
||||
import {type Geolocation} from '#/geolocation'
|
||||
|
||||
export type EnabledCheckProps = {
|
||||
feature: AnalyticsContextType['feature']
|
||||
features: AnalyticsContextType['features']
|
||||
currentAccount: SessionAccount
|
||||
currentProfile: AppBskyActorDefs.ProfileViewDetailed
|
||||
preferences: UsePreferencesQueryResponse
|
||||
|
||||
@@ -4,5 +4,5 @@ import {useAnalytics} from '#/analytics'
|
||||
|
||||
export function useIsBskyTeam() {
|
||||
const ax = useAnalytics()
|
||||
return useMemo(() => ax.feature(ax.Features.IsBskyTeam), [ax])
|
||||
return useMemo(() => ax.features.enabled(ax.features.IsBskyTeam), [ax])
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ export function Onboarding() {
|
||||
ENV !== 'e2e' &&
|
||||
IS_NATIVE &&
|
||||
findContactsEnabled &&
|
||||
!ax.feature(ax.Features.DisableOnboardingFindContacts)
|
||||
!ax.features.enabled(ax.features.DisableOnboardingFindContacts)
|
||||
|
||||
const [state, dispatch] = useReducer(
|
||||
reducer,
|
||||
|
||||
@@ -213,7 +213,7 @@ export function SettingsScreen({}: Props) {
|
||||
</SettingsList.LinkItem>
|
||||
{IS_NATIVE &&
|
||||
findContactsEnabled &&
|
||||
!ax.feature(ax.Features.DisableSettingsFindContacts) && (
|
||||
!ax.features.enabled(ax.features.DisableSettingsFindContacts) && (
|
||||
<SettingsList.LinkItem
|
||||
to="/settings/find-contacts"
|
||||
label={_(msg`Find friends from contacts`)}>
|
||||
|
||||
@@ -106,7 +106,7 @@ export function useCanGoLive() {
|
||||
const ax = useAnalytics()
|
||||
const {hasSession} = useSession()
|
||||
if (!hasSession) return false
|
||||
return IS_DEV ? true : !ax.feature(ax.Features.DisableLiveNowBeta)
|
||||
return IS_DEV ? true : !ax.features.enabled(ax.features.DisableLiveNowBeta)
|
||||
}
|
||||
|
||||
export function useCheckEmailConfirmed() {
|
||||
|
||||
Reference in New Issue
Block a user