fix(tui): use bridged event stream for data
This commit is contained in:
@@ -21,6 +21,7 @@ import type {
|
|||||||
import { createStore, produce } from "solid-js/store"
|
import { createStore, produce } from "solid-js/store"
|
||||||
import { createSimpleContext } from "./helper"
|
import { createSimpleContext } from "./helper"
|
||||||
import { useSDK } from "./sdk"
|
import { useSDK } from "./sdk"
|
||||||
|
import { useEvent } from "./event"
|
||||||
import { createSignal, onCleanup, onMount } from "solid-js"
|
import { createSignal, onCleanup, onMount } from "solid-js"
|
||||||
|
|
||||||
type LocationData = {
|
type LocationData = {
|
||||||
@@ -71,6 +72,7 @@ export const { use: useData, provider: DataProvider } = createSimpleContext({
|
|||||||
})
|
})
|
||||||
|
|
||||||
const sdk = useSDK()
|
const sdk = useSDK()
|
||||||
|
const events = useEvent()
|
||||||
const [defaultLocation, setDefaultLocation] = createSignal<LocationRef>({
|
const [defaultLocation, setDefaultLocation] = createSignal<LocationRef>({
|
||||||
directory: sdk.directory ?? process.cwd(),
|
directory: sdk.directory ?? process.cwd(),
|
||||||
})
|
})
|
||||||
@@ -119,12 +121,12 @@ export const { use: useData, provider: DataProvider } = createSimpleContext({
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleEvent(event: V2Event, metadata: { directory: string; workspace: string | undefined }) {
|
function handleEvent(event: V2Event) {
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case "catalog.updated":
|
case "catalog.updated":
|
||||||
void Promise.all([
|
void Promise.all([
|
||||||
result.location.model.refresh({ directory: metadata.directory, workspaceID: metadata.workspace }),
|
result.location.model.refresh(event.location),
|
||||||
result.location.provider.refresh({ directory: metadata.directory, workspaceID: metadata.workspace }),
|
result.location.provider.refresh(event.location),
|
||||||
])
|
])
|
||||||
break
|
break
|
||||||
case "session.next.agent.switched":
|
case "session.next.agent.switched":
|
||||||
@@ -404,26 +406,23 @@ export const { use: useData, provider: DataProvider } = createSimpleContext({
|
|||||||
break
|
break
|
||||||
case "integration.updated":
|
case "integration.updated":
|
||||||
void Promise.all([
|
void Promise.all([
|
||||||
result.location.integration.refresh({ directory: metadata.directory, workspaceID: metadata.workspace }),
|
result.location.integration.refresh(event.location),
|
||||||
result.location.model.refresh({ directory: metadata.directory, workspaceID: metadata.workspace }),
|
result.location.model.refresh(event.location),
|
||||||
result.location.provider.refresh({ directory: metadata.directory, workspaceID: metadata.workspace }),
|
result.location.provider.refresh(event.location),
|
||||||
])
|
])
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
const controller = new AbortController()
|
const unsub = events.subscribe((event, metadata) => {
|
||||||
onCleanup(() => controller.abort())
|
handleEvent({
|
||||||
void (async () => {
|
...event,
|
||||||
const events = await sdk.client.v2.event.subscribe({ signal: controller.signal })
|
data: event.properties,
|
||||||
for await (const event of events.stream) {
|
location: { directory: metadata.directory, workspaceID: metadata.workspace },
|
||||||
handleEvent(event, {
|
} as V2Event)
|
||||||
directory: event.location?.directory ?? defaultLocation().directory,
|
})
|
||||||
workspace: event.location?.workspaceID,
|
onCleanup(unsub)
|
||||||
})
|
|
||||||
}
|
|
||||||
})().catch(() => {})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const result = {
|
const result = {
|
||||||
|
|||||||
Reference in New Issue
Block a user