Skip to content

Commit

Permalink
fix: wait for cortex process overlay should be on top
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-menlo committed Aug 1, 2024
1 parent 1d58496 commit a4a90b2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
18 changes: 15 additions & 3 deletions web/containers/WaitingCortexModal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
import { Modal } from '@janhq/joi'
import { useAtomValue } from 'jotai'
import { useAtom, useAtomValue } from 'jotai'

import Spinner from '../Loader/Spinner'

import { waitingForCortexAtom } from '@/helpers/atoms/App.atom'
import { hostAtom } from '@/helpers/atoms/AppConfig.atom'
import { useCallback, useEffect } from 'react'
import useCortex from '@/hooks/useCortex'

const WaitingForCortexModal: React.FC = () => {
const host = useAtomValue(hostAtom)
const open = useAtomValue(waitingForCortexAtom)
const [waitingForCortex, setWaitingForCortex] = useAtom(waitingForCortexAtom)
const { isSystemAlive } = useCortex()

const checkSystemAlive = useCallback(async () => {
setWaitingForCortex(!(await isSystemAlive()))
}, [])

// Check health for the first time on mount
useEffect(() => {
checkSystemAlive()
}, [])

return (
<Modal
hideClose
open={open}
open={waitingForCortex}
title={'Waiting for cortex'}
content={
<div className="flex gap-x-2">
Expand Down
2 changes: 1 addition & 1 deletion web/helpers/atoms/App.atom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const mainViewStateAtom = atom<MainViewState>(MainViewState.Thread)

export const defaultJanDataFolderAtom = atom<string>('')

export const waitingForCortexAtom = atom<boolean>(false)
export const waitingForCortexAtom = atom<boolean>(true)

// Store panel atom
export const showLeftPanelAtom = atom<boolean>(true)
Expand Down
10 changes: 10 additions & 0 deletions web/hooks/useCortex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,15 @@ const useCortex = () => {
[host]
)

const isSystemAlive = useCallback(async () => {
try {
await cortex.system.status();
return true;
} catch {
return false;
}
}, [host])

return {
fetchAssistants,
fetchThreads,
Expand All @@ -345,6 +354,7 @@ const useCortex = () => {
createModel,
initializeEngine,
getEngineStatuses,
isSystemAlive
}
}

Expand Down

0 comments on commit a4a90b2

Please sign in to comment.