Skip to content

Commit

Permalink
WIP layout api server
Browse files Browse the repository at this point in the history
  • Loading branch information
urmauur committed Jan 17, 2024
1 parent cf83292 commit 05698cb
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 31 deletions.
81 changes: 53 additions & 28 deletions web/screens/LocalServer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,43 +1,53 @@
import { Button } from '@janhq/uikit'
import { useAtom } from 'jotai'
import { useAtom, useAtomValue } from 'jotai'

import { ExternalLinkIcon } from 'lucide-react'

import { twMerge } from 'tailwind-merge'

import DropdownListSidebar from '@/containers/DropdownListSidebar'

import { showRightSideBarAtom } from '../Chat/Sidebar'

import { serverEnabledAtom } from '@/helpers/atoms/LocalServer.atom'

const LocalServerScreen = () => {
const [serverEnabled, setServerEnabled] = useAtom(serverEnabledAtom)
const showing = useAtomValue(showRightSideBarAtom)

return (
<div className="flex h-full w-full">
{/* Left SideBar */}
<div className="flex h-full w-60 flex-shrink-0 flex-col overflow-y-auto border-r border-border p-4">
<h2 className="font-bold">Server Options</h2>
<p className="mt-2 leading-relaxed">
Start an OpenAI-compatible local HTTP server.
</p>

<div className="mt-4 space-y-3">
<Button
block
themes={serverEnabled ? 'danger' : 'success'}
onClick={() => {
if (serverEnabled) {
window.core?.api?.stopServer()
setServerEnabled(false)
} else {
window.core?.api?.startServer()
setServerEnabled(true)
}
}}
>
{serverEnabled ? 'Stop' : 'Start'} Server
</Button>
<Button block themes="secondaryBlue" asChild>
<a href="https://jan.ai/api-reference/" target="_blank">
API Reference <ExternalLinkIcon size={20} className="ml-2" />
</a>
</Button>
<div className="flex h-full w-60 flex-shrink-0 flex-col overflow-y-auto border-r border-border">
<div className="p-4">
<h2 className="font-bold">Server Options</h2>
<p className="mt-2 leading-relaxed">
Start an OpenAI-compatible local HTTP server.
</p>
</div>
<div className="border-b border-border pb-8">
<div className="space-y-3 px-4">
<Button
block
themes={serverEnabled ? 'danger' : 'success'}
onClick={() => {
if (serverEnabled) {
window.core?.api?.stopServer()
setServerEnabled(false)
} else {
window.core?.api?.startServer()
setServerEnabled(true)
}
}}
>
{serverEnabled ? 'Stop' : 'Start'} Server
</Button>
<Button block themes="secondaryBlue" asChild>
<a href="https://jan.ai/api-reference/" target="_blank">
API Reference <ExternalLinkIcon size={20} className="ml-2" />
</a>
</Button>
</div>
</div>
</div>

Expand All @@ -54,6 +64,21 @@ const LocalServerScreen = () => {
</div>

{/* Right bar */}
<div
className={twMerge(
'h-full flex-shrink-0 overflow-x-hidden border-l border-border bg-background transition-all duration-100 dark:bg-background/20',
showing
? 'w-80 translate-x-0 opacity-100'
: 'w-0 translate-x-full opacity-0'
)}
>
<p>
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Cumque earum
numquam fugit quia quisquam id quos aspernatur unde voluptatem neque,
officiis doloribus, laborum totam ad deserunt corporis impedit beatae
vitae?
</p>
</div>
</div>
)
}
Expand Down
6 changes: 3 additions & 3 deletions web/screens/Settings/Advanced/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useContext, useEffect, useState } from 'react'
import { fs } from '@janhq/core'
import { Switch, Button } from '@janhq/uikit'

import { useAtom } from 'jotai'
// import { useAtom } from 'jotai'

import ShortcutModal from '@/containers/ShortcutModal'
import { toaster } from '@/containers/Toast'
Expand All @@ -17,13 +17,13 @@ import { FeatureToggleContext } from '@/context/FeatureToggle'

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

import { serverEnabledAtom } from '@/helpers/atoms/LocalServer.atom'
// import { serverEnabledAtom } from '@/helpers/atoms/LocalServer.atom'

const Advanced = () => {
const { experimentalFeatureEnabed, setExperimentalFeatureEnabled } =
useContext(FeatureToggleContext)
const [gpuEnabled, setGpuEnabled] = useState<boolean>(false)
const [serverEnabled, setServerEnabled] = useAtom(serverEnabledAtom)
// const [serverEnabled, setServerEnabled] = useAtom(serverEnabledAtom)
const { readSettings, saveSettings, validateSettings, setShowNotification } =
useSettings()

Expand Down

0 comments on commit 05698cb

Please sign in to comment.