forked from langflow-ai/langflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve file uploader size validation - custom hook (langflow-a…
…i#3952) * 📝 (inputFileComponent/index.tsx): add useFileSizeValidator hook to validate file size before upload to improve code readability and maintainability * 📝 (chatInput/index.tsx): remove unused imports and refactor file size validation to use a custom hook for better code organization and readability * 📝 (FileInput/index.tsx): refactor file input component to use a custom hook for file size validation instead of utility store 🔧 (FileInput/index.tsx): remove dependency on utility store for max file size upload and use a custom hook for file size validation instead * ✨ (use-file-size-validator.tsx): introduce a new custom hook useFileSizeValidator to validate file size before uploading it
- Loading branch information
1 parent
0ac622e
commit 86cbf1f
Showing
4 changed files
with
36 additions
and
23 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
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,22 @@ | ||
import { INVALID_FILE_SIZE_ALERT } from "@/constants/alerts_constants"; | ||
import { useUtilityStore } from "@/stores/utilityStore"; | ||
|
||
const useFileSizeValidator = ( | ||
setErrorData: (newState: { title: string; list?: Array<string> }) => void, | ||
) => { | ||
const maxFileSizeUpload = useUtilityStore((state) => state.maxFileSizeUpload); | ||
|
||
const validateFileSize = (file) => { | ||
if (file.size > maxFileSizeUpload) { | ||
setErrorData({ | ||
title: INVALID_FILE_SIZE_ALERT(maxFileSizeUpload / 1024 / 1024), | ||
}); | ||
return false; | ||
} | ||
return true; | ||
}; | ||
|
||
return { validateFileSize }; | ||
}; | ||
|
||
export default useFileSizeValidator; |