jan/web/screens/Settings/index.tsx
Faisal Amir 2394c13065
ui: standalone UIKit and refactor (#557)
* Eslint import order

* Initial Uikit

* Rename file with camelCase

* Remove unused code

* Remove unused code

* Set position traficlight mac

* Grouping Ribbon, Topbar and Bottombar as layout

* Added image brand

* Moving feature toggle into context folder

* Fix active state of setting menu

* Cleanup downloadModel atom helper

* Cleanup useGetConfigureModel

* Added wave animation

* Create useMainViewState intead of import helper atom

* Remove unused code

* Take a back switch ui

* Toggle using switch component

* Add dynamic primary color

* Cleanup import

* Added uikit scroll area

* Add best practice form

* Added toaster container

* Fix loader container

* Add hooks useDownloadState

* Added tooltip on ribbon menu

* Added case user multiple download model

* Adjust input style with bigger ring

* Restyle my model screen

* Replace useStartStop model with useActiveModel

* Import icon using Icon name

* Fix missing login loading start and stop model

* WIP integrate with cmdk

* Move layout search bar on middle of app

* Added function cancel download

* Cleanup model explore

* Cleanup unused code

* Move app version in bototmbar or footer

* WIP chat screen

* WIP chat screen

* Cleanup style and remove unsed code

* Added command for showing downloaded model

* Fix missing keyframe loader dot animation

* Conditional loader of plugin setting

* WIP history list message

* chore: rebase main

* Adding script ui into root package

* Fix different version react hooks form

* Add close toaster

* Added status model active or not on list of command

* Conditional showing info if user don't have a model

* Disabled toolbar chat when user not yet have convo

* chore: fix state

* fix: get resource atom

* Fix conditional bottom bar

* fix: model download state

* Fix font

* Improve icon my model

* Add toaster delete chat

* Remove test classname

* Fix scroll chat body

* Fix scrolling chat body

* chore: add message update

* Add uikit into depedencies on root package

* Update chat flow

* Fix hot reload ui changes

* Increate background color chat screen light mode

* Added visual conversation active state

* Added build:uikit on gh actions

* chore: attempt to fix CI

* fix: deps

* fix: tests

* chore: attempt to fix CI

---------

Co-authored-by: Louis <louis@jan.ai>
2023-11-07 21:27:11 +07:00

178 lines
6.1 KiB
TypeScript

/* eslint-disable @typescript-eslint/no-explicit-any */
import { useEffect, useState } from 'react'
import { ScrollArea } from '@janhq/uikit'
import { motion as m } from 'framer-motion'
import { twMerge } from 'tailwind-merge'
import Advanced from '@/screens/Settings/Advanced'
import AppearanceOptions from '@/screens/Settings/Appearance'
import PluginCatalog from '@/screens/Settings/CorePlugins/PluginsCatalog'
import PreferencePlugins from '@/screens/Settings/CorePlugins/PreferencePlugins'
import { formatPluginsName } from '@/utils/converter'
const SettingsScreen = () => {
const [activeStaticMenu, setActiveStaticMenu] = useState('Appearance')
const [menus, setMenus] = useState<any[]>([])
const [preferenceItems, setPreferenceItems] = useState<any[]>([])
const [preferenceValues, setPreferenceValues] = useState<any[]>([])
useEffect(() => {
const menu = ['Appearance']
if (typeof window !== 'undefined' && window.electronAPI) {
menu.push('Core Plugins')
}
menu.push('Advanced')
setMenus(menu)
}, [])
/**
* Fetches the active plugins and their preferences from the `plugins` and `preferences` modules.
* If the `experimentComponent` extension point is available, it executes the extension point and
* appends the returned components to the `experimentRef` element.
* If the `PluginPreferences` extension point is available, it executes the extension point and
* fetches the preferences for each plugin using the `preferences.get` function.
*/
useEffect(() => {
const getActivePluginPreferences = async () => {
// setPreferenceItems(Array.isArray(data) ? data : [])
// TODO: Add back with new preferences mechanism
// Promise.all(
// (Array.isArray(data) ? data : []).map((e) =>
// preferences
// .get(e.pluginName, e.preferenceKey)
// .then((k) => ({ key: e.preferenceKey, value: k }))
// )
// ).then((data) => {
// setPreferenceValues(data)
// })
}
getActivePluginPreferences()
}, [])
const preferencePlugins = preferenceItems
.map((x) => x.pluginName)
.filter((x, i) => {
// return prefere/nceItems.map((x) => x.pluginName).indexOf(x) === i
})
const [activePreferencePlugin, setActivePreferencePlugin] = useState('')
const handleShowOptions = (menu: string) => {
switch (menu) {
case 'Core Plugins':
return <PluginCatalog />
case 'Appearance':
return <AppearanceOptions />
case 'Advanced':
return <Advanced />
default:
return (
<PreferencePlugins
pluginName={menu}
preferenceItems={preferenceItems}
preferenceValues={preferenceValues}
/>
)
}
}
return (
<div className="flex h-full">
<div className="flex h-full w-64 flex-shrink-0 flex-col overflow-y-auto border-r border-border">
<ScrollArea className="h-full w-full">
<div className="p-4">
<div className="flex-shrink-0">
<label className="font-bold uppercase text-muted-foreground">
Options
</label>
<div className="mt-2 font-medium">
{menus.map((menu, i) => {
const isActive = activeStaticMenu === menu
return (
<div key={i} className="relative my-0.5 block py-1.5">
<div
onClick={() => {
setActiveStaticMenu(menu)
setActivePreferencePlugin('')
}}
className="block w-full cursor-pointer"
>
<span className={twMerge(isActive && 'relative z-10')}>
{menu}
</span>
</div>
{isActive && (
<m.div
className="absolute inset-0 -left-3 h-full w-[calc(100%+24px)] rounded-md bg-primary/50"
layoutId="active-static-menu"
/>
)}
</div>
)
})}
</div>
</div>
<div className="mt-5 flex-shrink-0">
{preferencePlugins.length > 0 && (
<label className="font-bold uppercase text-muted-foreground">
Core plugins
</label>
)}
<div className="mt-2 font-medium">
{preferencePlugins.map((menu, i) => {
const isActive = activePreferencePlugin === menu
return (
<div key={i} className="relative my-0.5 block py-1.5">
<div
onClick={() => {
setActivePreferencePlugin(menu)
setActiveStaticMenu('')
}}
className="block w-full cursor-pointer"
>
<span
className={twMerge(
'capitalize',
isActive && 'relative z-10'
)}
>
{formatPluginsName(String(menu))}
</span>
</div>
{isActive ? (
<m.div
className="absolute inset-0 -left-3 h-full w-[calc(100%+24px)] rounded-md bg-primary/50"
layoutId="active-static-menu"
/>
) : null}
</div>
)
})}
</div>
</div>
</div>
</ScrollArea>
</div>
<div className="h-full w-full bg-background/50">
<ScrollArea className="h-full w-full">
<div className="p-4">
{handleShowOptions(activeStaticMenu || activePreferencePlugin)}
</div>
</ScrollArea>
</div>
</div>
)
}
export default SettingsScreen