Skip to content

Commit

Permalink
fix: update feedback missing state when refrash app
Browse files Browse the repository at this point in the history
  • Loading branch information
urmauur committed May 27, 2024
1 parent d653ea2 commit 5fa8bb6
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 43 deletions.
2 changes: 2 additions & 0 deletions web/containers/ModelDropdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 157,8 @@ const ModelDropdown = ({ chatInputMode, strictedThread = true }: Props) => {

const inActiveEngineProvider = useAtomValue(inActiveEngineProviderAtom)

console.log(inActiveEngineProvider)

useEffect(() => {
const getAllSettings = async () => {
const extensionsMenu: {
Expand Down
22 changes: 11 additions & 11 deletions web/containers/Providers/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 74,18 @@ const Providers = ({ children }: PropsWithChildren) => {
<Umami />
{settingUp && <Loader description="Preparing Update..." />}
{setupCore && activated && (
<Responsive>
<KeyListener>
<EventListenerWrapper>
<DataLoader>
<ThemeWrapper>
<ThemeWrapper>
<Responsive>
<KeyListener>
<EventListenerWrapper>
<DataLoader>
<DeepLinkListener>{children}</DeepLinkListener>
</ThemeWrapper>
</DataLoader>
</EventListenerWrapper>
<Toaster />
</KeyListener>
</Responsive>
</DataLoader>
</EventListenerWrapper>
<Toaster />
</KeyListener>
</Responsive>
</ThemeWrapper>
)}
</JotaiWrapper>
)
Expand Down
7 changes: 6 additions & 1 deletion web/helpers/atoms/Extension.atom.ts
Original file line number Diff line number Diff line change
@@ -1,4 1,5 @@
import { atom } from 'jotai'
import { atomWithStorage } from 'jotai/utils'

type ExtensionId = string

Expand Down Expand Up @@ -39,4 40,8 @@ export const removeInstallingExtensionAtom = atom(
}
)

export const inActiveEngineProviderAtom = atom<string[]>([])
const INACTIVE_ENGINE_PROVIDER = 'inActiveEngineProvider'
export const inActiveEngineProviderAtom = atomWithStorage<string[]>(
INACTIVE_ENGINE_PROVIDER,
[]
)
15 changes: 11 additions & 4 deletions web/screens/LocalServer/LocalServerRightPanel/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 1,4 @@
import { useCallback, useMemo, useState } from 'react'
import { useCallback, useEffect, useMemo, useState } from 'react'

import { Accordion, AccordionItem } from '@janhq/joi'
import { useAtomValue, useSetAtom } from 'jotai'
Expand Down Expand Up @@ -30,16 30,23 @@ const LocalServerRightPanel = () => {
toSettingParams(selectedModel?.settings)
)

useEffect(() => {
if (Object.keys(currentModelSettingParams).length === 0) {
setCurrentModelSettingParams(toSettingParams(selectedModel?.settings))
}
}, [currentModelSettingParams, selectedModel?.settings])

const modelRuntimeParams = toRuntimeParams(selectedModel?.settings)

const componentDataEngineSetting = getConfigurationsData(
currentModelSettingParams
)
const componentDataRuntimeSetting = getConfigurationsData(
modelRuntimeParams,
selectedModel
)

const componentDataEngineSetting = getConfigurationsData(
currentModelSettingParams
)

const engineSettings = useMemo(
() =>
componentDataEngineSetting.filter(
Expand Down
22 changes: 0 additions & 22 deletions web/screens/Settings/CoreExtensions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,40 113,18 @@ const ExtensionCatalog = () => {
}
}

const INACTIVE_ENGINE_PROVIDER = 'inActiveEngineProvider'

const [inActiveEngineProvider, setInActiveEngineProvider] = useAtom(
inActiveEngineProviderAtom
)

useEffect(() => {
if (localStorage.getItem(INACTIVE_ENGINE_PROVIDER) === null) {
localStorage.setItem(INACTIVE_ENGINE_PROVIDER, '[]')
setInActiveEngineProvider([])
} else {
setInActiveEngineProvider(
JSON.parse(String(localStorage.getItem(INACTIVE_ENGINE_PROVIDER)))
)
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])

const onSwitchChange = useCallback(
(name: string) => {
if (inActiveEngineProvider.includes(name)) {
setInActiveEngineProvider(
[...inActiveEngineProvider].filter((x) => x !== name)
)
localStorage.setItem(
INACTIVE_ENGINE_PROVIDER,
JSON.stringify([...inActiveEngineProvider].filter((x) => x !== name))
)
} else {
setInActiveEngineProvider([...inActiveEngineProvider, name])
localStorage.setItem(
INACTIVE_ENGINE_PROVIDER,
JSON.stringify([...inActiveEngineProvider, name])
)
}
},
[inActiveEngineProvider, setInActiveEngineProvider]
Expand Down
28 changes: 23 additions & 5 deletions web/screens/Thread/ThreadRightPanel/Tools/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 1,14 @@
import { Fragment, useCallback } from 'react'
import { Fragment, useCallback, useEffect } from 'react'

import { Tooltip, Switch, Input } from '@janhq/joi'
import { useAtomValue } from 'jotai'
import { useAtom, useAtomValue } from 'jotai'

import { InfoIcon } from 'lucide-react'

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

import useRecommendedModel from '@/hooks/useRecommendedModel'

import AssistantSetting from '@/screens/Thread/ThreadCenterPanel/AssistantSetting'

import { getConfigurationsData } from '@/utils/componentSettings'
Expand All @@ -18,15 20,27 @@ import { activeThreadAtom } from '@/helpers/atoms/Thread.atom'
const Tools = () => {
const experimentalFeature = useAtomValue(experimentalFeatureEnabledAtom)
const activeThread = useAtomValue(activeThreadAtom)
const selectedModel = useAtomValue(selectedModelAtom)
const [selectedModel, setSelectedModel] = useAtom(selectedModelAtom)
const { updateThreadMetadata } = useCreateNewThread()
const { recommendedModel, downloadedModels } = useRecommendedModel()

const componentDataAssistantSetting = getConfigurationsData(
(activeThread?.assistants[0]?.tools &&
activeThread?.assistants[0]?.tools[0]?.settings) ??
{}
)

useEffect(() => {
if (!activeThread) return
let model = downloadedModels.find(
(model) => model.id === activeThread.assistants[0].model.id
)
if (!model) {
model = recommendedModel
}
setSelectedModel(model)
}, [recommendedModel, activeThread, downloadedModels, setSelectedModel])

const onRetrievalSwitchUpdate = useCallback(
(enabled: boolean) => {
if (!activeThread) return
Expand Down Expand Up @@ -115,7 129,11 @@ const Tools = () => {
/>
</div>
<div className="w-full">
<Input value={selectedModel?.name} disabled />
<Input
value={selectedModel?.name || ''}
disabled
readOnly
/>
</div>
</div>
<div className="mb-4">
Expand All @@ -142,7 160,7 @@ const Tools = () => {
</div>

<div className="w-full">
<Input value="HNSWLib" disabled />
<Input value="HNSWLib" disabled readOnly />
</div>
</div>
<AssistantSetting
Expand Down

0 comments on commit 5fa8bb6

Please sign in to comment.