94 lines
2.6 KiB
TypeScript
94 lines
2.6 KiB
TypeScript
import {
|
|
hasFeatureInteraction,
|
|
type FeatureInteractionId,
|
|
type FeatureInteractionState
|
|
} from './feature-interactions'
|
|
|
|
export type FeatureTipId = 'voice-dictation'
|
|
|
|
export type FeatureTipPriority = 'new' | 'unseen'
|
|
|
|
export type FeatureTipAction = 'enable-voice'
|
|
|
|
export type FeatureTip = {
|
|
id: FeatureTipId
|
|
priority: FeatureTipPriority
|
|
eyebrow: string
|
|
title: string
|
|
description: string
|
|
action: FeatureTipAction
|
|
ctaLabel: string
|
|
/** Feature interactions that mean this tip is no longer useful to show. */
|
|
completedByFeatureInteractions?: readonly FeatureInteractionId[]
|
|
}
|
|
|
|
export type CompletedFeatureTipState = {
|
|
voiceDictationEnabled: boolean
|
|
featureInteractions?: FeatureInteractionState
|
|
}
|
|
|
|
export const FEATURE_TIPS = [
|
|
{
|
|
id: 'voice-dictation',
|
|
priority: 'new',
|
|
eyebrow: 'New',
|
|
title: 'Voice Dictation is here',
|
|
description:
|
|
'Speak into any focused pane and Orca will transcribe it. Press the dictation shortcut to start and stop.',
|
|
action: 'enable-voice',
|
|
ctaLabel: 'Set Up Voice',
|
|
completedByFeatureInteractions: ['voice-dictation']
|
|
}
|
|
] as const satisfies readonly FeatureTip[]
|
|
|
|
export const FEATURE_TIP_IDS = FEATURE_TIPS.map((tip) => tip.id)
|
|
|
|
export function isFeatureTipId(value: unknown): value is FeatureTipId {
|
|
return typeof value === 'string' && FEATURE_TIP_IDS.includes(value as FeatureTipId)
|
|
}
|
|
|
|
export function normalizeFeatureTipIds(value: unknown): FeatureTipId[] {
|
|
if (!Array.isArray(value)) {
|
|
return []
|
|
}
|
|
|
|
const seen = new Set<FeatureTipId>()
|
|
for (const item of value) {
|
|
if (isFeatureTipId(item)) {
|
|
seen.add(item)
|
|
}
|
|
}
|
|
return [...seen]
|
|
}
|
|
|
|
export function getCompletedFeatureTipIds(state: CompletedFeatureTipState): Set<FeatureTipId> {
|
|
const completedIds = new Set<FeatureTipId>()
|
|
if (state.voiceDictationEnabled) {
|
|
completedIds.add('voice-dictation')
|
|
}
|
|
for (const tip of FEATURE_TIPS) {
|
|
if (
|
|
tip.completedByFeatureInteractions?.some((id) =>
|
|
hasFeatureInteraction(state.featureInteractions, id)
|
|
)
|
|
) {
|
|
completedIds.add(tip.id)
|
|
}
|
|
}
|
|
return completedIds
|
|
}
|
|
|
|
export function getOrderedUnseenFeatureTips(args: {
|
|
seenTipIds: ReadonlySet<FeatureTipId>
|
|
completedTipIds?: ReadonlySet<FeatureTipId>
|
|
}): FeatureTip[] {
|
|
const completedTipIds = args.completedTipIds ?? new Set<FeatureTipId>()
|
|
const unseenTips = FEATURE_TIPS.filter(
|
|
(tip) => !args.seenTipIds.has(tip.id) && !completedTipIds.has(tip.id)
|
|
)
|
|
return [
|
|
...unseenTips.filter((tip) => tip.priority === 'new'),
|
|
...unseenTips.filter((tip) => tip.priority !== 'new')
|
|
]
|
|
}
|