Merge pull request #1850 from janhq/fix/jan-data-folder
fix: add loader when user change folder
This commit is contained in:
commit
4237c46fce
@ -27,7 +27,6 @@ const BaseLayout = (props: PropsWithChildren) => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (localStorage.getItem(SUCCESS_SET_NEW_DESTINATION) === 'true') {
|
if (localStorage.getItem(SUCCESS_SET_NEW_DESTINATION) === 'true') {
|
||||||
setMainViewState(MainViewState.Settings)
|
setMainViewState(MainViewState.Settings)
|
||||||
localStorage.removeItem(SUCCESS_SET_NEW_DESTINATION)
|
|
||||||
}
|
}
|
||||||
}, [setMainViewState])
|
}, [setMainViewState])
|
||||||
|
|
||||||
|
|||||||
@ -5,6 +5,8 @@ import { Button, Input } from '@janhq/uikit'
|
|||||||
import { useSetAtom } from 'jotai'
|
import { useSetAtom } from 'jotai'
|
||||||
import { PencilIcon, FolderOpenIcon } from 'lucide-react'
|
import { PencilIcon, FolderOpenIcon } from 'lucide-react'
|
||||||
|
|
||||||
|
import Loader from '@/containers/Loader'
|
||||||
|
|
||||||
import { SUCCESS_SET_NEW_DESTINATION } from '@/hooks/useVaultDirectory'
|
import { SUCCESS_SET_NEW_DESTINATION } from '@/hooks/useVaultDirectory'
|
||||||
|
|
||||||
import ModalChangeDirectory, {
|
import ModalChangeDirectory, {
|
||||||
@ -13,10 +15,12 @@ import ModalChangeDirectory, {
|
|||||||
import ModalErrorSetDestGlobal, {
|
import ModalErrorSetDestGlobal, {
|
||||||
showChangeFolderErrorAtom,
|
showChangeFolderErrorAtom,
|
||||||
} from './ModalErrorSetDestGlobal'
|
} from './ModalErrorSetDestGlobal'
|
||||||
|
|
||||||
import ModalSameDirectory, { showSamePathModalAtom } from './ModalSameDirectory'
|
import ModalSameDirectory, { showSamePathModalAtom } from './ModalSameDirectory'
|
||||||
|
|
||||||
const DataFolder = () => {
|
const DataFolder = () => {
|
||||||
const [janDataFolderPath, setJanDataFolderPath] = useState('')
|
const [janDataFolderPath, setJanDataFolderPath] = useState('')
|
||||||
|
const [showLoader, setShowLoader] = useState(false)
|
||||||
const setShowDirectoryConfirm = useSetAtom(showDirectoryConfirmModalAtom)
|
const setShowDirectoryConfirm = useSetAtom(showDirectoryConfirmModalAtom)
|
||||||
const setShowSameDirectory = useSetAtom(showSamePathModalAtom)
|
const setShowSameDirectory = useSetAtom(showSamePathModalAtom)
|
||||||
const setShowChangeFolderError = useSetAtom(showChangeFolderErrorAtom)
|
const setShowChangeFolderError = useSetAtom(showChangeFolderErrorAtom)
|
||||||
@ -46,18 +50,20 @@ const DataFolder = () => {
|
|||||||
const onUserConfirmed = useCallback(async () => {
|
const onUserConfirmed = useCallback(async () => {
|
||||||
if (!destinationPath) return
|
if (!destinationPath) return
|
||||||
try {
|
try {
|
||||||
|
setShowLoader(true)
|
||||||
const appConfiguration: AppConfiguration =
|
const appConfiguration: AppConfiguration =
|
||||||
await window.core?.api?.getAppConfigurations()
|
await window.core?.api?.getAppConfigurations()
|
||||||
const currentJanDataFolder = appConfiguration.data_folder
|
const currentJanDataFolder = appConfiguration.data_folder
|
||||||
appConfiguration.data_folder = destinationPath
|
appConfiguration.data_folder = destinationPath
|
||||||
await fs.syncFile(currentJanDataFolder, destinationPath)
|
await fs.syncFile(currentJanDataFolder, destinationPath)
|
||||||
await window.core?.api?.updateAppConfiguration(appConfiguration)
|
await window.core?.api?.updateAppConfiguration(appConfiguration)
|
||||||
|
|
||||||
console.debug(
|
console.debug(
|
||||||
`File sync finished from ${currentJanDataFolder} to ${destinationPath}`
|
`File sync finished from ${currentJanDataFolder} to ${destinationPath}`
|
||||||
)
|
)
|
||||||
|
|
||||||
localStorage.setItem(SUCCESS_SET_NEW_DESTINATION, 'true')
|
localStorage.setItem(SUCCESS_SET_NEW_DESTINATION, 'true')
|
||||||
|
setTimeout(() => {
|
||||||
|
setShowLoader(false)
|
||||||
|
}, 1200)
|
||||||
await window.core?.api?.relaunch()
|
await window.core?.api?.relaunch()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`Error: ${e}`)
|
console.error(`Error: ${e}`)
|
||||||
@ -107,6 +113,7 @@ const DataFolder = () => {
|
|||||||
onUserConfirmed={onUserConfirmed}
|
onUserConfirmed={onUserConfirmed}
|
||||||
/>
|
/>
|
||||||
<ModalErrorSetDestGlobal />
|
<ModalErrorSetDestGlobal />
|
||||||
|
{showLoader && <Loader description="Relocating Jan Data Folder..." />}
|
||||||
</Fragment>
|
</Fragment>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -49,6 +49,7 @@ const SettingsScreen = () => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (localStorage.getItem(SUCCESS_SET_NEW_DESTINATION) === 'true') {
|
if (localStorage.getItem(SUCCESS_SET_NEW_DESTINATION) === 'true') {
|
||||||
setActiveStaticMenu('Advanced Settings')
|
setActiveStaticMenu('Advanced Settings')
|
||||||
|
localStorage.removeItem(SUCCESS_SET_NEW_DESTINATION)
|
||||||
}
|
}
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user