refactor mobile session payload parsing

Move server session response parsing into a typed helper so the mobile screen no longer relies on inline any-based mapping in the refresh path.
This commit is contained in:
Ryan Vogel 2026-03-30 08:27:16 -04:00
commit f8f986536b

View file

@ -292,6 +292,34 @@ function findLatestAssistantCompletionText(payload: unknown): string {
return ""
}
type SessionItem = {
id: string
title: string
updated: number
}
type ServerSessionPayload = {
id?: unknown
title?: unknown
time?: {
updated?: unknown
}
}
function parseSessionItems(payload: unknown): SessionItem[] {
if (!Array.isArray(payload)) return []
return payload
.filter((item): item is ServerSessionPayload => !!item && typeof item === "object")
.map((item) => ({
id: String(item.id ?? ""),
title: String(item.title ?? item.id ?? "Untitled session"),
updated: Number(item.time?.updated ?? 0),
}))
.filter((item) => item.id.length > 0)
.sort((a, b) => b.updated - a.updated)
}
type ServerItem = {
id: string
name: string
@ -304,12 +332,6 @@ type ServerItem = {
sessionsLoading: boolean
}
type SessionItem = {
id: string
title: string
updated: number
}
type MonitorJob = {
id: string
sessionID: string
@ -2275,16 +2297,7 @@ export default function DictationScreen() {
}
const json = sessionsRes.ok ? await sessionsRes.json() : []
const sessions: SessionItem[] = Array.isArray(json)
? json
.map((item: any) => ({
id: String(item.id ?? ""),
title: String(item.title ?? item.id ?? "Untitled session"),
updated: Number(item?.time?.updated ?? 0),
}))
.filter((s) => s.id.length > 0)
.sort((a, b) => b.updated - a.updated)
: []
const sessions = parseSessionItems(json)
setServers((prev) =>
prev.map((s) => (s.id === serverID ? { ...s, status: "online", sessionsLoading: false, sessions } : s)),