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:
parent
785635caef
commit
f8f986536b
1 changed files with 29 additions and 16 deletions
|
|
@ -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)),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue