Skip to content

Commit d58757a

Browse files
committed
Reset EpubHandler after file upload
A change has been made to the file upload event handler function. After a successful file upload and processing, the EpubHandler, which is responsible for handling EPUB files, is now reset. This small addition creates a fresh instance of EpubHandler for each file upload, ensuring the state from the previous file processing does not persist. This is crucial for the correct handling of consecutive file uploads. In essence, this improves the reliability and accuracy of the file processing feature.
1 parent 90abcc9 commit d58757a

File tree

1 file changed

+28
-26
lines changed

1 file changed

+28
-26
lines changed

src/App.ts

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -48,33 +48,35 @@ export default class App {
4848
}
4949
}
5050

51-
/**
52-
* Handles the file upload event.
53-
* @param event - The file upload event.
54-
*/
55-
private async handleFileUpload(event: Event): Promise<void> {
56-
const input = event.target as HTMLInputElement;
57-
if (input.files && input.files.length > 0) {
58-
const file = input.files[0];
59-
this.hideFileInput();
60-
this.showLoadingSpinner();
61-
62-
const startTime = performance.now(); // Start time measurement
63-
await this.processFile(file);
64-
const endTime = performance.now(); // End time measurement
65-
66-
this.hideLoadingSpinner();
67-
this.showSuccessMessage(this.showFileInput.bind(this));
68-
input.value = ''; // Clear the input field
69-
70-
const processingTime = (endTime - startTime) / 1000;
71-
const seconds = Math.floor(processingTime);
72-
const milliseconds = Math.floor((processingTime - seconds) * 1000);
73-
74-
console.info(`File processing time: ${seconds} seconds and ${milliseconds} milliseconds`);
51+
/**
52+
* Handles the file upload event.
53+
* @param event - The file upload event.
54+
*/
55+
private async handleFileUpload(event: Event): Promise<void> {
56+
const input = event.target as HTMLInputElement;
57+
if (input.files && input.files.length > 0) {
58+
const file = input.files[0];
59+
this.hideFileInput();
60+
this.showLoadingSpinner();
61+
62+
const startTime = performance.now(); // Start time measurement
63+
await this.processFile(file);
64+
const endTime = performance.now(); // End time measurement
65+
66+
this.hideLoadingSpinner();
67+
this.showSuccessMessage(this.showFileInput.bind(this));
68+
input.value = ''; // Clear the input field
69+
this._epubHandler = new EpubHandler(); // Reset the EPUB handler
70+
71+
const processingTime = (endTime - startTime) / 1000;
72+
const seconds = Math.floor(processingTime);
73+
const milliseconds = Math.floor((processingTime - seconds) * 1000);
74+
75+
console.info(
76+
`File processing time: ${seconds} seconds and ${milliseconds} milliseconds`
77+
);
78+
}
7579
}
76-
}
77-
7880

7981
/**
8082
* Processes the uploaded file.

0 commit comments

Comments
 (0)