Skip to content

Commit 922633e

Browse files
committed
refactor mobile derived ui state
Rewrite a focused cluster of nested ternaries in the mobile screen into straight-line derived logic so the render state is easier to read without changing behavior.
1 parent 49b40e3 commit 922633e

1 file changed

Lines changed: 28 additions & 19 deletions

File tree

packages/mobile-voice/src/app/index.tsx

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1976,7 +1976,12 @@ export default function DictationScreen() {
19761976

19771977
const modelDownloading = downloadingModelID !== null
19781978
const modelLoading = isPreparingWhisperModel || activeWhisperModel == null || modelDownloading || isTranscribingBulk
1979-
const modelLoadingState = modelDownloading ? "downloading" : modelLoading ? "loading" : "ready"
1979+
let modelLoadingState: "downloading" | "loading" | "ready" = "ready"
1980+
if (modelDownloading) {
1981+
modelLoadingState = "downloading"
1982+
} else if (modelLoading) {
1983+
modelLoadingState = "loading"
1984+
}
19801985
const pct = Math.round(Math.max(0, Math.min(1, downloadProgress)) * 100)
19811986
const loadingModelLabel = downloadingModelID
19821987
? WHISPER_MODEL_LABELS[downloadingModelID]
@@ -1986,8 +1991,10 @@ export default function DictationScreen() {
19861991
const hasAgentActivity = hasAssistantResponse || monitorStatus.trim().length > 0 || monitorJob !== null
19871992
const shouldShowAgentStateCard = hasAgentActivity && !agentStateDismissed
19881993
const showsCompleteState = monitorStatus.toLowerCase().includes("complete")
1989-
const agentStateIcon =
1990-
monitorJob !== null ? "loading" : hasAssistantResponse || showsCompleteState ? "done" : "loading"
1994+
let agentStateIcon: "loading" | "done" = "loading"
1995+
if (monitorJob === null && (hasAssistantResponse || showsCompleteState)) {
1996+
agentStateIcon = "done"
1997+
}
19911998
const agentStateText = hasAssistantResponse ? latestAssistantResponse : "Waiting for agent…"
19921999
const shouldShowSend = hasCompletedSession && hasTranscript
19932000
const activeServer = servers.find((s) => s.id === activeServerId) ?? null
@@ -1996,14 +2003,12 @@ export default function DictationScreen() {
19962003
const isDropdownOpen = dropdownMode !== "none"
19972004
const effectiveDropdownMode = isDropdownOpen ? dropdownMode : dropdownRenderMode
19982005
const headerTitle = activeServer?.name ?? "No server configured"
1999-
const headerDotStyle =
2000-
activeServer == null
2001-
? styles.serverStatusOffline
2002-
: activeServer.status === "online"
2003-
? styles.serverStatusActive
2004-
: activeServer.status === "checking"
2005-
? styles.serverStatusChecking
2006-
: styles.serverStatusOffline
2006+
let headerDotStyle = styles.serverStatusOffline
2007+
if (activeServer?.status === "online") {
2008+
headerDotStyle = styles.serverStatusActive
2009+
} else if (activeServer?.status === "checking") {
2010+
headerDotStyle = styles.serverStatusChecking
2011+
}
20072012

20082013
const recordingProgress = useSharedValue(0)
20092014
const sendVisibility = useSharedValue(hasTranscript ? 1 : 0)
@@ -2150,8 +2155,12 @@ export default function DictationScreen() {
21502155
const basePhase = (Math.max(0, t - meta.delay) / meta.duration) * Math.PI * 2 + meta.phase + row * 0.35
21512156
const pulse = 0.5 + 0.5 * Math.sin(basePhase)
21522157

2153-
const alpha =
2154-
intensity > 0 ? (0.4 + intensity * 0.6) * (0.85 + pulse * 0.15) : isRecording ? 0.1 + pulse * 0.07 : 0.08
2158+
let alpha = 0.08
2159+
if (intensity > 0) {
2160+
alpha = (0.4 + intensity * 0.6) * (0.85 + pulse * 0.15)
2161+
} else if (isRecording) {
2162+
alpha = 0.1 + pulse * 0.07
2163+
}
21552164

21562165
// Base palette around #78839A, with brighter/lower variants by intensity.
21572166
const baseR = 120
@@ -2666,12 +2675,12 @@ export default function DictationScreen() {
26662675
const direct = (mod as { requestCameraPermissionsAsync?: unknown }).requestCameraPermissionsAsync
26672676
const fromCamera = (mod as { Camera?: { requestCameraPermissionsAsync?: unknown } }).Camera
26682677
?.requestCameraPermissionsAsync
2669-
const requestCameraPermissionsAsync =
2670-
typeof direct === "function"
2671-
? (direct as () => Promise<{ granted: boolean }>)
2672-
: typeof fromCamera === "function"
2673-
? (fromCamera as () => Promise<{ granted: boolean }>)
2674-
: null
2678+
let requestCameraPermissionsAsync: (() => Promise<{ granted: boolean }>) | null = null
2679+
if (typeof direct === "function") {
2680+
requestCameraPermissionsAsync = direct as () => Promise<{ granted: boolean }>
2681+
} else if (typeof fromCamera === "function") {
2682+
requestCameraPermissionsAsync = fromCamera as () => Promise<{ granted: boolean }>
2683+
}
26752684

26762685
if (!requestCameraPermissionsAsync) {
26772686
return null

0 commit comments

Comments
 (0)