marknguyen1302 a36b3fee24
fix: move Jan folder (#3160)
* chore: upgrade marked-katex-extension (#3049)

* fix: handle long word without space to avoid right panel disappears (#3048)

* add time weighted retrieval (#2908)

* add time weighted retrieval

* add missing configuration for timeWeightedVectorStore

* resolving conflict

* add missing configuration for timeWeightedVectorStore

* resolving conflict

* fix linting issues

* fix build failed due to requirement for useTimeWeightedRetriever in AssistantTool

* update web packages complying the new structure

---------

Co-authored-by: thu <thu@treehouse.finance>

* fix: model dropdown search by configured model (#3047)

* bump version (#3082) (#3083)

Co-authored-by: Hoang Ha <64120343+hahuyhoang411@users.noreply.github.com>

* Update cortex cpp nightly to version 0.4.18 (#3072)

* Update cortex cpp nightly to version 0.4.17

* update linux downloadnitro

* c‌ortex 0.4.18

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Van Pham <64197333+Van-QA@users.noreply.github.com>

* chore: update download.ts (#3088)

infomation -> information

* chore: cortex version update (#3098)

* fix: handle words without space (#3101)

* fix: handle long thread title without space (#3107)

* fix: handle long thread title without space, and make searchbar autofocus inside model dropdown

* feat: enable right click to show setting on thread items (#3108)

* chore: Bump-cortex-0.4.17 (#3111)

* Update cortex cpp nightly to version 0.4.18 (#3114)

* Update cortex cpp nightly to version 0.4.18

* cortex 0.4.19

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Van Pham <64197333+Van-QA@users.noreply.github.com>

* Chore: Add stop token for Gemma 2b (#3125)

* add stop token

* Bump version

* fix: set specific version for terminate (#3126)

Signed-off-by: James <namnh0122@gmail.com>

* feat: add claude 3.5 sonnet (#3129)

Signed-off-by: James <namnh0122@gmail.com>

* feat: add options config spell check for chat input (#3131)

* fixed grammar nits (#3132)

* Update cortex cpp nightly to version 0.4.20

* fix: toggle button for expand log section on modal troubleshoot (#3130)

* fix: add tooltip messages toolbar (#3138)

* fix: handle error message when apikey is not setup (#3149)

* fix: title thread not updated on input edit title (#3148)

* merge dev

* fix move jan folder

* Update electron/preload.ts

* refactor

* Update electron/preload.ts

* fix wrong param

* use correct method

* chore: fix lint

---------

Signed-off-by: James <namnh0122@gmail.com>
Co-authored-by: Faisal Amir <urmauur@gmail.com>
Co-authored-by: Nathan <thu.nhuanh99@gmail.com>
Co-authored-by: thu <thu@treehouse.finance>
Co-authored-by: Van Pham <64197333+Van-QA@users.noreply.github.com>
Co-authored-by: Hoang Ha <64120343+hahuyhoang411@users.noreply.github.com>
Co-authored-by: jan-service-account <136811300+jan-service-account@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Ikko Eltociear Ashimine <eltociear@gmail.com>
Co-authored-by: NamH <NamNh0122@gmail.com>
Co-authored-by: Saurabh <saurabhrai1717@gmail.com>
Co-authored-by: Louis <louis@jan.ai>
2024-07-15 13:36:52 +07:00

138 lines
4.4 KiB
TypeScript

import { Fragment, useCallback, useState } from 'react'
import { AppConfiguration, isSubdirectory } from '@janhq/core'
import { Button, Input } from '@janhq/joi'
import { useAtomValue, useSetAtom } from 'jotai'
import { PencilIcon, FolderOpenIcon } from 'lucide-react'
import Loader from '@/containers/Loader'
export const SUCCESS_SET_NEW_DESTINATION = 'successSetNewDestination'
import ModalChangeDirectory, {
showDirectoryConfirmModalAtom,
} from './ModalChangeDirectory'
import ModalChangeDestNotEmpty, {
showDestNotEmptyConfirmAtom,
} from './ModalConfirmDestNotEmpty'
import ModalErrorSetDestGlobal, {
showChangeFolderErrorAtom,
} from './ModalErrorSetDestGlobal'
import ModalSameDirectory, { showSamePathModalAtom } from './ModalSameDirectory'
import { janDataFolderPathAtom } from '@/helpers/atoms/AppConfig.atom'
const DataFolder = () => {
const [showLoader, setShowLoader] = useState(false)
const setShowDirectoryConfirm = useSetAtom(showDirectoryConfirmModalAtom)
const setShowSameDirectory = useSetAtom(showSamePathModalAtom)
const setShowChangeFolderError = useSetAtom(showChangeFolderErrorAtom)
const showDestNotEmptyConfirm = useSetAtom(showDestNotEmptyConfirmAtom)
const [destinationPath, setDestinationPath] = useState(undefined)
const janDataFolderPath = useAtomValue(janDataFolderPathAtom)
const onChangeFolderClick = useCallback(async () => {
const destFolder = await window.core?.api?.selectDirectory()
if (!destFolder) return
if (destFolder === janDataFolderPath) {
setShowSameDirectory(true)
return
}
const appConfiguration: AppConfiguration =
await window.core?.api?.getAppConfigurations()
const currentJanDataFolder = appConfiguration.data_folder
if (await isSubdirectory(currentJanDataFolder, destFolder)) {
setShowSameDirectory(true)
return
}
const isEmpty: boolean =
await window.core?.api?.isDirectoryEmpty(destFolder)
if (!isEmpty) {
setDestinationPath(destFolder)
showDestNotEmptyConfirm(true)
return
}
setDestinationPath(destFolder)
setShowDirectoryConfirm(true)
}, [
janDataFolderPath,
setShowDirectoryConfirm,
setShowSameDirectory,
showDestNotEmptyConfirm,
])
const onUserConfirmed = useCallback(async () => {
if (!destinationPath) return
try {
setShowLoader(true)
await window.core?.api?.changeDataFolder(destinationPath)
localStorage.setItem(SUCCESS_SET_NEW_DESTINATION, 'true')
setTimeout(() => {
setShowLoader(false)
}, 1200)
await window.core?.api?.relaunch()
} catch (e) {
console.error(e)
setShowLoader(false)
setShowChangeFolderError(true)
}
}, [destinationPath, setShowChangeFolderError])
return (
<Fragment>
<div className="flex w-full flex-col items-start justify-between gap-4 border-b border-[hsla(var(--app-border))] py-4 first:pt-0 last:border-none sm:flex-row">
<div className="space-y-1">
<div className="flex gap-x-2">
<h6 className="font-semibold capitalize">Jan Data Folder</h6>
</div>
<p className="font-medium leading-relaxed text-[hsla(var(--text-secondary))]">
Where messages, model configurations, and other user data are
placed.
</p>
</div>
<div className="flex items-center gap-x-3">
<div className="relative">
<Input
value={janDataFolderPath}
className="w-full pr-8 sm:w-[240px]"
disabled
/>
<FolderOpenIcon
size={16}
className="absolute right-2 top-1/2 z-10 -translate-y-1/2 cursor-pointer"
onClick={() => window.core?.api?.openAppDirectory()}
/>
</div>
<Button
size="small"
theme="ghost"
variant="outline"
className="h-9 w-9 flex-shrink-0 p-0"
onClick={onChangeFolderClick}
>
<PencilIcon size={16} />
</Button>
</div>
</div>
<ModalSameDirectory onChangeFolderClick={onChangeFolderClick} />
<ModalChangeDirectory
destinationPath={destinationPath ?? ''}
onUserConfirmed={onUserConfirmed}
/>
<ModalErrorSetDestGlobal />
<ModalChangeDestNotEmpty onUserConfirmed={onUserConfirmed} />
{showLoader && <Loader description="Relocating Jan Data Folder..." />}
</Fragment>
)
}
export default DataFolder