Skip to content

Commit

Permalink
fix: separate model start loader
Browse files Browse the repository at this point in the history
  • Loading branch information
urmauur committed Dec 14, 2023
1 parent c17a4fe commit 01939af
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 47 deletions.
47 changes: 47 additions & 0 deletions web/containers/Loader/ModelStart.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React, { useEffect, useState } from 'react'

import { useActiveModel } from '@/hooks/useActiveModel'

export default function ModelStart() {
const { stateModel } = useActiveModel()
const [loader, setLoader] = useState(0)

// This is fake loader please fix this when we have realtime percentage when load model
useEffect(() => {
if (stateModel.loading) {
if (loader === 24) {
setTimeout(() => {
setLoader(loader + 1)
}, 250)
} else if (loader === 50) {
setTimeout(() => {
setLoader(loader + 1)
}, 250)
} else if (loader === 78) {
setTimeout(() => {
setLoader(loader + 1)
}, 250)
} else if (loader === 99) {
setLoader(99)
} else {
setLoader(loader + 1)
}
} else {
setLoader(0)
}
}, [stateModel.loading, loader])

if (!stateModel.loading) return null

return (
<div className=" mb-1 mt-2 py-2 text-center">
<div className="relative inline-block overflow-hidden rounded-lg border border-neutral-50 bg-blue-50 px-4 py-2 font-semibold text-blue-600 shadow-lg">
<div
className="absolute left-0 top-0 h-full bg-blue-200"
style={{ width: `${loader}%` }}
/>
<span className="relative z-10">Starting model {stateModel.model}</span>
</div>
</div>
)
}
51 changes: 4 additions & 47 deletions web/screens/Chat/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import {
ChangeEvent,
Fragment,
KeyboardEvent,
useEffect,
useRef,
useState,
} from 'react'
import { ChangeEvent, Fragment, KeyboardEvent, useEffect, useRef } from 'react'

import { Button, Textarea } from '@janhq/uikit'

Expand All @@ -15,6 +8,7 @@ import { twMerge } from 'tailwind-merge'

import LogoMark from '@/containers/Brand/Logo/Mark'

import ModelStart from '@/containers/Loader/ModelStart'
import { currentPromptAtom } from '@/containers/Providers/Jotai'

import { MainViewState } from '@/constants/screens'
Expand Down Expand Up @@ -57,7 +51,6 @@ const ChatScreen = () => {
const [isWaitingToSend, setIsWaitingToSend] = useAtom(waitingToSendMessage)

const showing = useAtomValue(showRightSideBarAtom)
const [loader, setLoader] = useState(0)

const textareaRef = useRef<HTMLTextAreaElement>(null)
const modelRef = useRef(activeModel)
Expand All @@ -78,31 +71,6 @@ const ChatScreen = () => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [waitingToSendMessage, activeThreadId])

// This is fake loader please fix this when we have realtime percentage when load model
useEffect(() => {
if (stateModel.loading) {
if (loader === 24) {
setTimeout(() => {
setLoader(loader + 1)
}, 250)
} else if (loader === 50) {
setTimeout(() => {
setLoader(loader + 1)
}, 250)
} else if (loader === 78) {
setTimeout(() => {
setLoader(loader + 1)
}, 250)
} else if (loader === 99) {
setLoader(99)
} else {
setLoader(loader + 1)
}
} else {
setLoader(0)
}
}, [stateModel.loading, loader])

useEffect(() => {
if (textareaRef.current !== null) {
const scrollHeight = textareaRef.current.scrollHeight
Expand Down Expand Up @@ -168,19 +136,8 @@ const ChatScreen = () => {
</div>
)}

{stateModel.loading && (
<div className=" mb-1 mt-2 py-2 text-center">
<div className="relative inline-block overflow-hidden rounded-lg border border-neutral-50 bg-blue-50 px-4 py-2 font-semibold text-blue-600 shadow-lg">
<div
className="absolute left-0 top-0 h-full bg-blue-200"
style={{ width: `${loader}%` }}
/>
<span className="relative z-10">
Starting model {stateModel.model}
</span>
</div>
</div>
)}
<ModelStart />

{queuedMessage && (
<div className="my-2 py-2 text-center">
<span className="rounded-lg border border-border px-4 py-2 shadow-lg">
Expand Down

0 comments on commit 01939af

Please sign in to comment.