Skip to content

Commit 00a9611

Browse files
author
Ritika Mishra
committed
format code removed unwanted console checks
1 parent fbb5a94 commit 00a9611

File tree

2 files changed

+20
-24
lines changed

2 files changed

+20
-24
lines changed

src/components/Connection.tsx

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ const Connection: React.FC<ConnectionProps> = ({
9393
const endTimeRef = useRef<number | null>(null); // Ref to store the end time of the recording
9494
const [popoverVisible, setPopoverVisible] = useState(false);
9595
const portRef = useRef<SerialPort | null>(null); // Ref to store the serial port
96-
const [ifBits, setifBits] = useState<BitSelection>("auto");
96+
const [ifBits, setifBits] = useState<BitSelection>("auto");
9797
const [showAllChannels, setShowAllChannels] = useState(false);
9898
const [FullZoom, setFullZoom] = useState(false);
9999
const canvasnumbersRef = useRef<number>(1);
@@ -188,7 +188,7 @@ const Connection: React.FC<ConnectionProps> = ({
188188

189189
useEffect(() => {
190190
canvasnumbersRef.current = canvasCount; // Sync the ref with the state
191-
}, [canvasCount,isRecordingRef]);
191+
}, [canvasCount, isRecordingRef]);
192192

193193
const handleTimeSelection = (minutes: number | null) => {
194194
// Function to handle the time selection
@@ -219,7 +219,7 @@ const Connection: React.FC<ConnectionProps> = ({
219219
}
220220
};
221221

222-
const processBuffer = async (bufferIndex: number,canvasCount:number) => {
222+
const processBuffer = async (bufferIndex: number, canvasCount: number) => {
223223
if (!workerRef.current) {
224224
initializeWorker();
225225
}
@@ -233,11 +233,11 @@ const Connection: React.FC<ConnectionProps> = ({
233233
if (filename) {
234234
// Check if the record already exists
235235
workerRef.current?.postMessage({ action: 'checkExistence', filename, canvasCount });
236-
writeToIndexedDB(data, filename,canvasCount);
236+
writeToIndexedDB(data, filename, canvasCount);
237237
}
238238
};
239239

240-
const writeToIndexedDB = (data: number[][], filename: string,canvasCount:number) => {
240+
const writeToIndexedDB = (data: number[][], filename: string, canvasCount: number) => {
241241
workerRef.current?.postMessage({ action: 'write', data, filename, canvasCount });
242242
};
243243

@@ -271,7 +271,7 @@ const Connection: React.FC<ConnectionProps> = ({
271271
if (blob) {
272272
saveAs(blob, filename); // FileSaver.js
273273
toast.success("File downloaded successfully.");
274-
} else(error:any) =>{
274+
} else (error: any) => {
275275
console.error("Worker error:", error);
276276
toast.error(`Error during file download: ${error.message}`);
277277
}
@@ -661,16 +661,15 @@ const Connection: React.FC<ConnectionProps> = ({
661661
}
662662
datastream(channelData); // Pass the channel data to the LineData function for further processing
663663
if (isRecordingRef.current) {
664-
console.log(canvasnumbersRef.current);
665664
const channeldatavalues = channelData
666665
.slice(0, canvasnumbersRef.current + 1)
667666
.map((value) => (value !== undefined ? value : null))
668667
.filter((value): value is number => value !== null); // Filter out null values
669668
// Check if recording is enabled
670669
recordingBuffers[activeBufferIndex][fillingindex.current] = channeldatavalues;
671-
670+
672671
if (fillingindex.current >= MAX_BUFFER_SIZE - 1) {
673-
processBuffer(activeBufferIndex,canvasnumbersRef.current);
672+
processBuffer(activeBufferIndex, canvasnumbersRef.current);
674673
activeBufferIndex = (activeBufferIndex + 1) % NUM_BUFFERS;
675674
}
676675
fillingindex.current = (fillingindex.current + 1) % MAX_BUFFER_SIZE;
@@ -765,26 +764,26 @@ const Connection: React.FC<ConnectionProps> = ({
765764
const deleteFilesByFilename = async (filename: string) => {
766765
try {
767766
const dbRequest = indexedDB.open("ChordsRecordings");
768-
767+
769768
dbRequest.onsuccess = (event) => {
770769
const db = (event.target as IDBOpenDBRequest).result;
771770
const transaction = db.transaction("ChordsRecordings", "readwrite");
772771
const store = transaction.objectStore("ChordsRecordings");
773-
772+
774773
// Check if the "filename" index exists
775774
if (!store.indexNames.contains("filename")) {
776775
console.error("Index 'filename' does not exist.");
777776
toast.error("Unable to delete files: index not found.");
778777
return;
779778
}
780-
779+
781780
const index = store.index("filename");
782781
const deleteRequest = index.openCursor(IDBKeyRange.only(filename));
783-
782+
784783
// Make this callback async
785784
deleteRequest.onsuccess = async (event) => {
786785
const cursor = (event.target as IDBRequest<IDBCursorWithValue>).result;
787-
786+
788787
if (cursor) {
789788
cursor.delete(); // Delete the current record
790789
// Fetch the updated data and update state
@@ -795,22 +794,22 @@ const Connection: React.FC<ConnectionProps> = ({
795794
toast.success("File deleted successfully.");
796795
}
797796
};
798-
797+
799798
deleteRequest.onerror = () => {
800799
console.error("Error during delete operation.");
801800
toast.error("Failed to delete the file. Please try again.");
802801
};
803-
802+
804803
transaction.oncomplete = () => {
805804
console.log("File deletion transaction completed.");
806805
};
807-
806+
808807
transaction.onerror = () => {
809808
console.error("Transaction failed during deletion.");
810809
toast.error("Failed to delete the file. Please try again.");
811810
};
812811
};
813-
812+
814813
dbRequest.onerror = () => {
815814
console.error("Failed to open IndexedDB database.");
816815
toast.error("An error occurred while accessing the database.");
@@ -820,7 +819,7 @@ const Connection: React.FC<ConnectionProps> = ({
820819
toast.error("An unexpected error occurred. Please try again.");
821820
}
822821
};
823-
822+
824823
// Function to delete all data from IndexedDB (for ZIP files or clear all)
825824
const deleteAllDataFromIndexedDB = async () => {
826825
return new Promise<void>((resolve, reject) => {

workers/indexedDBWorker.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ self.onmessage = async (event) => {
88

99
switch (action) {
1010
case 'write':
11-
const success = await writeToIndexedDB(db, data, filename,canvasCount);
11+
const success = await writeToIndexedDB(db, data, filename, canvasCount);
1212
self.postMessage({ success });
1313
break;
1414
case 'getAllData':
@@ -67,7 +67,7 @@ const openIndexedDB = async (): Promise<IDBDatabase> => {
6767
};
6868

6969
// Function to write data to IndexedDB
70-
const writeToIndexedDB = async (db: IDBDatabase, data: number[][], filename: string,canvasCount:number): Promise<boolean> => {
70+
const writeToIndexedDB = async (db: IDBDatabase, data: number[][], filename: string, canvasCount: number): Promise<boolean> => {
7171
return new Promise((resolve, reject) => {
7272
const tx = db.transaction("ChordsRecordings", "readwrite");
7373
const store = tx.objectStore("ChordsRecordings");
@@ -148,7 +148,6 @@ const saveAllDataAsZip = async (canvasCount: number): Promise<Blob> => {
148148
const tx = db.transaction("ChordsRecordings", "readonly");
149149
const store = tx.objectStore("ChordsRecordings");
150150

151-
console.log(canvasCount);
152151
const allData: any[] = await new Promise((resolve, reject) => {
153152
const request = store.getAll();
154153
request.onsuccess = () => resolve(request.result);
@@ -180,7 +179,6 @@ const saveAllDataAsZip = async (canvasCount: number): Promise<Blob> => {
180179

181180
const saveDataByFilename = async (filename: string, canvasCount: number): Promise<Blob> => {
182181
try {
183-
console.log("filename",filename);
184182
const dbRequest = indexedDB.open("ChordsRecordings");
185183

186184
return new Promise((resolve, reject) => {
@@ -199,7 +197,6 @@ const saveDataByFilename = async (filename: string, canvasCount: number): Promis
199197

200198
getRequest.onsuccess = () => {
201199
const result = getRequest.result;
202-
console.log("Retrieved IndexedDB result:", result);
203200

204201
if (!result || !Array.isArray(result.content)) {
205202
reject(new Error("No data found for the given filename or invalid data format."));

0 commit comments

Comments
 (0)