import { Text, Flex } from "rebass"; import Dialog from "./dialog"; import * as Icon from "../icons"; import { getHomeRoute, hardNavigate } from "../../navigation"; import { appVersion } from "../../utils/version"; import Config from "../../utils/config"; import { isTesting } from "../../utils/platform"; type CallToAction = { title: string; icon?: (props: any) => JSX.Element; action?: () => void; }; type SubFeature = { title: string; icon?: (props: any) => JSX.Element; subtitle?: string | JSX.Element; }; type Feature = { shouldShow?: () => boolean; title: string; subtitle?: string; cta: CallToAction; subFeatures?: SubFeature[]; }; type FeatureKeys = "confirmed" | "highlights"; const features: Record = { confirmed: { title: "Email confirmed!", subtitle: "You can now sync your notes to unlimited devices.", cta: { title: "Continue", icon: Icon.ArrowRight, action: () => hardNavigate(getHomeRoute()), }, }, highlights: { title: "✨ Highlights ✨", subtitle: `Welcome to v${appVersion.clean}`, subFeatures: [ { title: "All panes are now resizable", subtitle: ( <> You can now adjust the width of all the panes as you see fit. And they persist across sessions too! ), icon: Icon.Resize, }, { title: "Sort alphabetically when group by = none", subtitle: <>No idea why this wasn't included earlier., icon: Icon.SortBy, }, ], cta: { title: "Got it", icon: Icon.Checkmark, action: () => { Config.set(`${appVersion.numerical}:highlights`, true); }, }, shouldShow: () => { const hasShown = Config.get( `${appVersion.numerical}:highlights`, false ) as boolean; return !isTesting() && !hasShown; }, }, }; type FeatureDialogProps = { featureName: FeatureKeys; onClose: (result: boolean) => void; }; function FeatureDialog(props: FeatureDialogProps) { const { featureName } = props; const feature = features[featureName]; if (!feature || (feature.shouldShow && !feature.shouldShow())) { props.onClose(false); return null; } return ( {feature.cta.icon && ( )} {feature.cta.title} ), onClick: () => { if (feature.cta.action) feature.cta.action(); props.onClose(true); }, }} > {feature.subFeatures?.map((feature) => ( {feature.icon && } {feature.title} {feature.subtitle && ( {feature.subtitle} )} ))} ); } export default FeatureDialog; type CodeProps = { text: string; href?: string }; export function Code(props: CodeProps) { return ( { if (props.href) window.open(props.href, "_target"); }} > {props.text} ); }