Skip to content

Commit

Permalink
Fix bugs avoid chat body scroll horizontal
Browse files Browse the repository at this point in the history
  • Loading branch information
urmauur committed Oct 26, 2023
1 parent e53379b commit 9ed8678
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 29 deletions.
48 changes: 26 additions & 22 deletions web/app/_components/InputToolbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import useGetInputState from '@hooks/useGetInputState'
import { Button } from '../../../uikit/button'
import useStartStopModel from '@hooks/useStartStopModel'
import { userConversationsAtom } from '@helpers/atoms/Conversation.atom'

const InputToolbar: React.FC = () => {
const activeModel = useAtomValue(activeAssistantModelAtom)
Expand All @@ -23,6 +24,8 @@ const InputToolbar: React.FC = () => {
const { requestCreateConvo } = useCreateConversation()
const { startModel } = useStartStopModel()

const conversations = useAtomValue(userConversationsAtom)

const activeConvoId = useAtomValue(getActiveConvoIdAtom)

const onNewConversationClick = () => {
Expand Down Expand Up @@ -68,31 +71,32 @@ const InputToolbar: React.FC = () => {
)
}

return (
<div className="sticky bottom-0 w-full bg-background/90 px-5 py-0">
{currentConvoState?.error && (
<div className="flex flex-row justify-center">
<span className="mx-5 my-2 text-sm text-red-500">
{currentConvoState?.error?.toString()}
</span>
if (conversations.length > 0)
return (
<div className="sticky bottom-0 w-full bg-background/90 px-5 py-0">
{currentConvoState?.error && (
<div className="flex flex-row justify-center">
<span className="mx-5 my-2 text-sm text-red-500">
{currentConvoState?.error?.toString()}
</span>
</div>
)}
<div className="my-3 flex justify-center gap-2">
<SecondaryButton
onClick={onNewConversationClick}
title="New Conversation"
icon={<PlusIcon width={16} height={16} />}
/>
</div>
)}
<div className="my-3 flex justify-center gap-2">
<SecondaryButton
onClick={onNewConversationClick}
title="New Conversation"
icon={<PlusIcon width={16} height={16} />}
/>
</div>
{/* My text input */}
<div className="mb-5 flex items-start space-x-4">
<div className="relative min-w-0 flex-1">
<BasicPromptInput />
<BasicPromptAccessories />
{/* My text input */}
<div className="mb-5 flex items-start space-x-4">
<div className="relative min-w-0 flex-1">
<BasicPromptInput />
<BasicPromptAccessories />
</div>
</div>
</div>
</div>
)
)
}

export default InputToolbar
4 changes: 2 additions & 2 deletions web/app/_components/LeftHeaderAction/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ const LeftHeaderAction: React.FC = () => {
className="flex-1"
icon={<MagnifyingGlassIcon width={16} height={16} />}
/>
<SecondaryButton
{/* <SecondaryButton
title={'Create bot'}
onClick={onCreateBotClicked}
className="flex-1"
icon={<PlusIcon width={16} height={16} />}
/>
/> */}
</div>
)
}
Expand Down
72 changes: 72 additions & 0 deletions web/app/_components/ModalNoActiveModel/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import React, { Fragment } from 'react'
import { Dialog, Transition } from '@headlessui/react'
import { useAtom, useSetAtom } from 'jotai'
import { showingModalNoActiveModel } from '@helpers/atoms/Modal.atom'
import {
MainViewState,
setMainViewStateAtom,
} from '@helpers/atoms/MainView.atom'

const ModalNoActiveModel: React.FC = () => {
const [show, setShow] = useAtom(showingModalNoActiveModel)
const setMainView = useSetAtom(setMainViewStateAtom)

return (
<Transition.Root show={show} as={Fragment}>
<Dialog as="div" className="relative z-10" onClose={setShow}>
<Transition.Child
as={Fragment}
enter="ease-out duration-300"
enterFrom="opacity-0"
enterTo="opacity-100"
leave="ease-in duration-200"
leaveFrom="opacity-100"
leaveTo="opacity-0"
>
<div className="fixed inset-0 z-40 h-full bg-gray-950/90 transition-opacity dark:backdrop-blur-sm" />
</Transition.Child>

<div className="fixed inset-0 z-50 w-screen overflow-y-auto">
<div className="flex min-h-full items-end justify-center p-4 text-center sm:items-center sm:p-0">
<Transition.Child
as={Fragment}
enter="ease-out duration-300"
enterFrom="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
enterTo="opacity-100 translate-y-0 sm:scale-100"
leave="ease-in duration-200"
leaveFrom="opacity-100 translate-y-0 sm:scale-100"
leaveTo="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
>
<Dialog.Panel className="relative transform overflow-hidden rounded-lg border border-border bg-background/90 px-4 pb-4 pt-5 text-left shadow-xl transition-all sm:my-8 sm:w-full sm:max-w-lg sm:p-6">
<h1 className="font-base mb-4 font-bold">
There is no active model at the moment ...
</h1>
<div className="mt-5 sm:mt-4 sm:flex sm:flex-row-reverse">
<button
type="button"
className="inline-flex w-full justify-center rounded-md bg-accent px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-accent/80 sm:ml-3 sm:w-auto"
onClick={() => {
setMainView(MainViewState.MyModel)
setShow(false)
}}
>
Ok
</button>
<button
type="button"
className="mt-3 inline-flex w-full justify-center rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50 sm:mt-0 sm:w-auto"
onClick={() => setShow(false)}
>
Cancel
</button>
</div>
</Dialog.Panel>
</Transition.Child>
</div>
</div>
</Dialog>
</Transition.Root>
)
}

export default React.memo(ModalNoActiveModel)
10 changes: 6 additions & 4 deletions web/app/_components/SidebarEmptyHistory/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { activeAssistantModelAtom } from '@helpers/atoms/Model.atom'
import { useGetDownloadedModels } from '@hooks/useGetDownloadedModels'
import { Button } from '@uikit'
import { MessageCircle } from 'lucide-react'
import { showingModalNoActiveModel } from '@helpers/atoms/Modal.atom'

enum ActionButton {
DownloadModel = 'Download a Model',
Expand All @@ -21,6 +22,7 @@ const SidebarEmptyHistory: React.FC = () => {
const setMainView = useSetAtom(setMainViewStateAtom)
const { requestCreateConvo } = useCreateConversation()
const [action, setAction] = useState(ActionButton.DownloadModel)
const modalNoActiveModel = useSetAtom(showingModalNoActiveModel)

useEffect(() => {
if (downloadedModels.length > 0) {
Expand All @@ -35,7 +37,7 @@ const SidebarEmptyHistory: React.FC = () => {
setMainView(MainViewState.ExploreModel)
} else {
if (!activeModel) {
setMainView(MainViewState.ConversationEmptyModel)
modalNoActiveModel(true)
} else {
await requestCreateConvo(activeModel)
}
Expand All @@ -44,10 +46,10 @@ const SidebarEmptyHistory: React.FC = () => {

return (
<div className="flex flex-col items-center gap-3 py-10">
<MessageCircle size={32} />
<div className="flex flex-col items-center gap-y-2">
<MessageCircle size={24} />
<div className="flex flex-col items-center">
<h6 className="text-center text-base">No Chat History</h6>
<p className="mb-6 text-center text-muted-foreground">
<p className="mb-6 mt-1 text-center text-muted-foreground">
Get started by creating a new chat.
</p>
<Button onClick={onClick} themes="accent">
Expand Down
2 changes: 2 additions & 0 deletions web/helpers/ModalWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import ConfirmDeleteModelModal from '@/_components/ConfirmDeleteModelModal'
import ConfirmSignOutModal from '@/_components/ConfirmSignOutModal'
import MobileMenuPane from '@/_components/MobileMenuPane'
import SwitchingModelConfirmationModal from '@/_components/SwitchingModelConfirmationModal'
import ModalNoActiveModel from '@/_components/ModalNoActiveModel'
import { ReactNode } from 'react'

type Props = {
Expand All @@ -20,6 +21,7 @@ export const ModalWrapper: React.FC<Props> = ({ children }) => (
<ConfirmDeleteModelModal />
<BotListModal />
<SwitchingModelConfirmationModal />
<ModalNoActiveModel />
{children}
</>
)
1 change: 1 addition & 0 deletions web/helpers/atoms/Modal.atom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ export const showingBotListModalAtom = atom<boolean>(false)
export const switchingModelConfirmationModalPropsAtom = atom<
SwitchingModelConfirmationModalProps | undefined
>(undefined)
export const showingModalNoActiveModel = atom<boolean>(false)
3 changes: 2 additions & 1 deletion web/styles/code-block.scss
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,14 @@

.hljs {
display: block;
overflow-x: auto;
// overflow-x: auto;
background: #2b2b2b;
color: #f8f8f2;
padding: 0.5em;
border-radius: 0.4rem;
margin-top: 1rem;
margin-bottom: 1rem;
// white-space: pre-wrap;
}

.hljs-emphasis {
Expand Down

0 comments on commit 9ed8678

Please sign in to comment.