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