-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: file explore on windows show empty when importing model
Signed-off-by: James <[email protected]>
- Loading branch information
James
committed
Mar 24, 2024
1 parent
67e285f
commit 4193f39
Showing
9 changed files
with
236 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
export type SelectFileOption = { | ||
/** | ||
* The title of the dialog. | ||
*/ | ||
title?: string | ||
/** | ||
* Whether the dialog allows multiple selection. | ||
*/ | ||
allowMultiple?: boolean | ||
|
||
buttonLabel?: string | ||
|
||
selectDirectory?: boolean | ||
|
||
props?: SelectFileProp[] | ||
} | ||
|
||
export const SelectFilePropTuple = [ | ||
'openFile', | ||
'openDirectory', | ||
'multiSelections', | ||
'showHiddenFiles', | ||
'createDirectory', | ||
'promptToCreate', | ||
'noResolveAliases', | ||
'treatPackageAsDirectory', | ||
'dontAddToRecent', | ||
] as const | ||
|
||
export type SelectFileProp = (typeof SelectFilePropTuple)[number] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { useCallback } from 'react' | ||
|
||
import { SelectFileOption } from '@janhq/core' | ||
import { | ||
Button, | ||
Modal, | ||
ModalContent, | ||
ModalHeader, | ||
ModalTitle, | ||
} from '@janhq/uikit' | ||
import { useSetAtom, useAtomValue } from 'jotai' | ||
|
||
import useImportModel, { | ||
setImportModelStageAtom, | ||
getImportModelStageAtom, | ||
} from '@/hooks/useImportModel' | ||
|
||
const ChooseWhatToImportModal: React.FC = () => { | ||
const setImportModelStage = useSetAtom(setImportModelStageAtom) | ||
const importModelStage = useAtomValue(getImportModelStageAtom) | ||
const { sanitizeFilePaths } = useImportModel() | ||
|
||
const onImportFileClick = useCallback(async () => { | ||
const options: SelectFileOption = { | ||
title: 'Select model files', | ||
buttonLabel: 'Select', | ||
allowMultiple: true, | ||
} | ||
const filePaths = await window.core?.api?.selectFiles(options) | ||
if (!filePaths || filePaths.length === 0) return | ||
sanitizeFilePaths(filePaths) | ||
}, [sanitizeFilePaths]) | ||
|
||
const onImportFolderClick = useCallback(async () => { | ||
const options: SelectFileOption = { | ||
title: 'Select model folders', | ||
buttonLabel: 'Select', | ||
allowMultiple: true, | ||
selectDirectory: true, | ||
} | ||
const filePaths = await window.core?.api?.selectFiles(options) | ||
if (!filePaths || filePaths.length === 0) return | ||
sanitizeFilePaths(filePaths) | ||
}, [sanitizeFilePaths]) | ||
|
||
return ( | ||
<Modal | ||
open={importModelStage === 'CHOOSE_WHAT_TO_IMPORT'} | ||
onOpenChange={() => setImportModelStage('SELECTING_MODEL')} | ||
> | ||
<ModalContent> | ||
<ModalHeader> | ||
<ModalTitle>Choose what to import</ModalTitle> | ||
</ModalHeader> | ||
|
||
<div> | ||
<Button onClick={onImportFileClick}>Import file (GGUF)</Button> | ||
<Button onClick={onImportFolderClick}>Import Folder</Button> | ||
</div> | ||
</ModalContent> | ||
</Modal> | ||
) | ||
} | ||
|
||
export default ChooseWhatToImportModal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.