Files
opencode-mobile/app/demo.tsx
Den 179f88a4d8 feat(demo): funnel server-less users to the OpenCode Connect waitlist (#127)
The demo's only exit CTA was 'Connect your own server' — useless for the
majority of installers who have no server (the exact churn/retention segment).
Adds a secondary CTA pointing them to the OpenCode Connect (hosted, no-setup)
waitlist, which is the monetization funnel per the founder strategy. Additive,
reuses the existing waitlist on /connection/add and the demo's exit-tracking;
i18n en+zh in parity.


Claude-Session: https://claude.ai/code/session_01T12AhSnQVrSxNnvwfCx2z6

Co-authored-by: engineer <engineer@macbookpro.lan>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-18 11:53:21 -07:00

155 lines
6.1 KiB
TypeScript

import { useCallback, useEffect, useMemo, useState } from "react"
import { View, Text, ScrollView, TouchableOpacity, StyleSheet, useColorScheme, Linking } from "react-native"
import { Stack, useRouter } from "expo-router"
import { Ionicons } from "@expo/vector-icons"
import { useTranslation } from "react-i18next"
import { MessageBubble, PermissionPrompt } from "../src/components/chat"
import { buildDemoScript, buildDemoCompletionMessage, buildDemoDenialMessage } from "../src/lib/demo-script"
import { SETUP_GUIDE_URL } from "../src/lib/links"
import { track, AnalyticsEvent } from "../src/lib/analytics"
import {
demoStepAdvancedProps,
demoCompletedOutcome,
demoExitedToConnectProps,
type DemoPermissionReply,
} from "../src/lib/demo-analytics"
// Fully offline, scripted walkthrough for installers with no self-hosted
// opencode server. ISOLATION: every message/part below is hardcoded local
// data built once with useMemo — this screen never calls useSessions,
// useConnections, useEvents, or any sdk.ts client method, so it cannot
// create a real session, touch the network, or corrupt real app state. The
// permission "reply" only flips local component state (below); it never
// calls sessionClient.permission.reply the way app/session/[id].tsx does.
export default function DemoScreen() {
const router = useRouter()
const colorScheme = useColorScheme()
const isDark = colorScheme === "dark"
const { t } = useTranslation()
// Built once per mount from pure, hardcoded data (src/lib/demo-script.ts).
const script = useMemo(() => buildDemoScript(), [])
const [reply, setReply] = useState<DemoPermissionReply | null>(null)
// Fires once per screen mount — this is a fully offline, consent-gated
// event (track() is a no-op without telemetry consent, same as every
// other analytics call site).
useEffect(() => {
track(AnalyticsEvent.DemoStarted)
}, [])
const handleReply = useCallback((r: DemoPermissionReply) => {
setReply(r)
track(AnalyticsEvent.DemoStepAdvanced, demoStepAdvancedProps(r))
track(AnalyticsEvent.DemoCompleted, { outcome: demoCompletedOutcome(r) })
}, [])
const handleConnectPress = useCallback(() => {
track(AnalyticsEvent.DemoExitedToConnect, demoExitedToConnectProps(reply !== null))
router.push("/connection/add")
}, [reply, router])
const completion = useMemo(() => {
if (!reply) return null
return reply === "reject" ? buildDemoDenialMessage() : buildDemoCompletionMessage()
}, [reply])
const [userMessage, assistantMessage] = script.messages
return (
<>
<Stack.Screen options={{ title: t("demo.title"), presentation: "card" }} />
<View style={[s.container, isDark && s.containerDark]} testID="demo-screen">
<View style={[s.banner, isDark && s.bannerDark]} testID="demo-banner">
<Ionicons name="play-circle-outline" size={16} color="#8b5cf6" />
<Text style={s.bannerText}>{t("demo.banner")}</Text>
</View>
<ScrollView contentContainerStyle={s.scrollContent} keyboardShouldPersistTaps="handled">
<MessageBubble message={userMessage} parts={script.parts[userMessage.id] || []} isDark={isDark} />
<MessageBubble message={assistantMessage} parts={script.parts[assistantMessage.id] || []} isDark={isDark} />
{!reply && <PermissionPrompt permission={script.permission} isDark={isDark} onReply={handleReply} />}
{completion && (
<MessageBubble message={completion.message} parts={completion.parts} isDark={isDark} />
)}
<View style={[s.ctaCard, isDark && s.ctaCardDark]} testID="demo-cta-card">
<Text style={[s.ctaTitle, isDark && s.textWhite]}>{t("demo.ctaTitle")}</Text>
<Text style={[s.ctaSubtitle, isDark && s.metaDark]}>{t("demo.ctaSubtitle")}</Text>
<TouchableOpacity
style={s.connectButton}
onPress={handleConnectPress}
testID="demo-connect-button"
>
<Text style={s.connectButtonText}>{t("demo.connectButton")}</Text>
</TouchableOpacity>
<TouchableOpacity
style={s.hostedCtaLink}
onPress={handleConnectPress}
testID="demo-hosted-cta"
>
<Text style={s.hostedCtaLinkText}>{t("demo.hostedCtaLink")}</Text>
</TouchableOpacity>
<TouchableOpacity
style={s.setupGuideLink}
onPress={() => Linking.openURL(SETUP_GUIDE_URL)}
testID="demo-setup-guide-link"
>
<Text style={s.setupGuideLinkText}>{t("demo.setupGuideLink")}</Text>
</TouchableOpacity>
</View>
</ScrollView>
</View>
</>
)
}
const s = StyleSheet.create({
container: { flex: 1, backgroundColor: "#ffffff" },
containerDark: { backgroundColor: "#0a0a0a" },
textWhite: { color: "#ffffff" },
metaDark: { color: "#888888" },
banner: {
flexDirection: "row",
alignItems: "center",
gap: 8,
paddingHorizontal: 16,
paddingVertical: 10,
backgroundColor: "#f5f3ff",
borderBottomWidth: 1,
borderBottomColor: "#e9d5ff",
},
bannerDark: { backgroundColor: "#1a1030", borderBottomColor: "#2a1a4a" },
bannerText: { fontSize: 13, fontWeight: "600", color: "#6d28d9", flex: 1 },
scrollContent: { padding: 16, paddingBottom: 40 },
ctaCard: {
marginTop: 8,
padding: 20,
borderRadius: 16,
backgroundColor: "#f5f5f5",
alignItems: "center",
},
ctaCardDark: { backgroundColor: "#1a1a1a" },
ctaTitle: { fontSize: 17, fontWeight: "700", color: "#0a0a0a", textAlign: "center" },
ctaSubtitle: { fontSize: 13, color: "#666666", marginTop: 6, textAlign: "center", lineHeight: 18 },
connectButton: {
marginTop: 16,
backgroundColor: "#0a0a0a",
paddingHorizontal: 24,
paddingVertical: 12,
borderRadius: 8,
width: "100%",
alignItems: "center",
},
connectButtonText: { color: "#ffffff", fontWeight: "600", fontSize: 15 },
hostedCtaLink: { marginTop: 14 },
hostedCtaLinkText: { fontSize: 14, fontWeight: "600", color: "#8b5cf6", textAlign: "center" },
setupGuideLink: { marginTop: 14 },
setupGuideLinkText: { fontSize: 14, fontWeight: "600", color: "#6366f1" },
})