Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
wwayne committed May 28, 2024
1 parent 6ff5ede commit 9041761
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
6 changes: 4 additions & 2 deletions clients/tabby-chat-panel/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,21 @@ export interface ChatMessage {
relevantContext?: Array<Context>
}

export function createClient(target: HTMLIFrameElement, api: ClientApi): ServerApi {
export function createClient(target: HTMLIFrameElement, api: ClientApi, signal?: AbortSignal): ServerApi {
return createThreadFromIframe(target, {
expose: {
navigate: api.navigate,
},
signal

Check failure on line 47 in clients/tabby-chat-panel/src/index.ts

View workflow job for this annotation

GitHub Actions / tests

Missing trailing comma
})
}

export function createServer(api: ServerApi): ClientApi {
export function createServer(api: ServerApi, signal?: AbortSignal): ClientApi {
return createThreadFromInsideIframe({
expose: {
init: api.init,
sendMessage: api.sendMessage,
},
signal

Check failure on line 57 in clients/tabby-chat-panel/src/index.ts

View workflow job for this annotation

GitHub Actions / tests

Missing trailing comma
})
}
20 changes: 12 additions & 8 deletions clients/tabby-chat-panel/src/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import { createClient, createServer } from './index'

function useClient(iframeRef: RefObject<HTMLIFrameElement>, api: ClientApi) {
const [client, setClient] = useState<ServerApi | null>(null)
let isCreated = false
let abortController: AbortController

useEffect(() => {
if (iframeRef.current && !isCreated) {
isCreated = true
setClient(createClient(iframeRef.current, api))
if (iframeRef.current) {
console.log('client abortController', abortController)

Check failure on line 13 in clients/tabby-chat-panel/src/react.ts

View workflow job for this annotation

GitHub Actions / tests

Unexpected console statement

Check failure on line 13 in clients/tabby-chat-panel/src/react.ts

View workflow job for this annotation

GitHub Actions / autofix

Unexpected console statement
abortController?.abort()
setClient(createClient(iframeRef.current, api, abortController?.signal))
abortController = new AbortController()
}
}, [iframeRef.current])

Expand All @@ -20,13 +22,15 @@ function useClient(iframeRef: RefObject<HTMLIFrameElement>, api: ClientApi) {

function useServer(api: ServerApi) {
const [server, setServer] = useState<ClientApi | null>(null)
let isCreated = false
let abortController: AbortController

useEffect(() => {
const isInIframe = window.self !== window.top
if (isInIframe && !isCreated) {
isCreated = true
setServer(createServer(api))
if (isInIframe) {
console.log('server abortController', abortController)

Check failure on line 30 in clients/tabby-chat-panel/src/react.ts

View workflow job for this annotation

GitHub Actions / tests

Unexpected console statement

Check failure on line 30 in clients/tabby-chat-panel/src/react.ts

View workflow job for this annotation

GitHub Actions / autofix

Unexpected console statement
abortController?.abort()
setServer(createServer(api, abortController?.signal))
abortController = new AbortController()
}
}, [])

Expand Down

0 comments on commit 9041761

Please sign in to comment.