-
Notifications
You must be signed in to change notification settings - Fork 464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FilePickerControl features like new event and fixes upload behavior between page update #3875
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ class FilePickerState(Enum): | |
PICK_FILES = "pickFiles" | ||
SAVE_FILE = "saveFile" | ||
GET_DIRECTORY_PATH = "getDirectoryPath" | ||
UPLOADING_FILES = "uploadfiles" | ||
|
||
|
||
class FilePickerFileType(Enum): | ||
|
@@ -114,6 +115,7 @@ def __init__( | |
self, | ||
on_result: Optional[Callable[[FilePickerResultEvent], None]] = None, | ||
on_upload: Optional[Callable[[FilePickerUploadEvent], None]] = None, | ||
on_upload_finished: Optional[Callable[[ControlEvent], None]] = None, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (complexity): Consider whether the new state and event handler are essential. The recent changes have increased the complexity of the |
||
# | ||
# Control | ||
# | ||
|
@@ -138,13 +140,19 @@ def convert_result_event_data(e): | |
self.__on_upload = EventHandler(lambda e: FilePickerUploadEvent(e)) | ||
self._add_event_handler("upload", self.__on_upload.get_handler()) | ||
|
||
self.__on_upload_finished = EventHandler(lambda e: e) | ||
self._add_event_handler( | ||
"upload_finished", self.__on_upload_finished.get_handler() | ||
) | ||
|
||
self.__result: Optional[FilePickerResultEvent] = None | ||
self.__upload: List[FilePickerUploadFile] = [] | ||
self.__allowed_extensions: Optional[List[str]] = None | ||
self.__state = None | ||
self.__file_type = None | ||
self.on_result = on_result | ||
self.on_upload = on_upload | ||
self.on_upload_finished = on_upload_finished | ||
|
||
def _get_control_name(self): | ||
return "filepicker" | ||
|
@@ -248,6 +256,7 @@ async def get_directory_path_async( | |
|
||
def upload(self, files: List[FilePickerUploadFile]): | ||
self.__upload = files | ||
self.state = FilePickerState.UPLOADING_FILES | ||
self.update() | ||
|
||
@deprecated( | ||
|
@@ -345,3 +354,12 @@ def on_upload(self): | |
@on_upload.setter | ||
def on_upload(self, handler: OptionalEventCallable[FilePickerUploadEvent]): | ||
self.__on_upload.handler = handler | ||
|
||
# on_upload_finished | ||
@property | ||
def on_upload_finished(self): | ||
return self.__on_upload_finished.handler | ||
|
||
@on_upload_finished.setter | ||
def on_upload_finished(self, handler: OptionalEventCallable[ControlEvent]): | ||
self.__on_upload_finished.handler = handler |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Consider moving the 'files' list into the state class
Global variables can lead to unexpected behavior and make the code harder to maintain. It would be better to keep this list as part of the _FilePickerControlState class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the state class, the
files
variable becomes unstable during page refreshes.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It sounds like the instability of the
files
variable during page refreshes might be due to how the state is being managed or preserved across refreshes. One approach to address this could be to ensure that the state is properly initialized or restored when the component is rebuilt.You might want to consider using a state management solution or a mechanism to persist the state across refreshes, such as using a
StatefulWidget
with aState
that properly handles initialization and disposal. Additionally, you could explore using local storage or a similar method to save and restore thefiles
list if it needs to persist across page reloads.If you can provide more details about how the state is currently being managed, I might be able to offer more specific suggestions.