Skip to content

Commit fbb5a94

Browse files
author
Ritika Mishra
committed
format code removed unwanted variables and extra spaces
1 parent 03b1b5c commit fbb5a94

File tree

2 files changed

+9
-34
lines changed

2 files changed

+9
-34
lines changed

src/components/Connection.tsx

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import React, { useState, useRef, useCallback, useEffect } from "react";
33
import { Button } from "./ui/button";
44
import { Input } from "./ui/input";
55
import { EXGFilter, Notch } from './filters';
6-
import JSZip from 'jszip';
76
import {
87
Cable,
98
Circle,
@@ -67,7 +66,6 @@ const Connection: React.FC<ConnectionProps> = ({
6766
onPauseChange,
6867
datastream,
6968
Connection,
70-
selectedBits,
7169
setSelectedBits,
7270
isDisplay,
7371
setIsDisplay,
@@ -85,20 +83,17 @@ const Connection: React.FC<ConnectionProps> = ({
8583
const [isEndTimePopoverOpen, setIsEndTimePopoverOpen] = useState(false);
8684
const [detectedBits, setDetectedBits] = useState<BitSelection | null>(null); // State to store the detected bits
8785
const detectedBitsRef = React.useRef<BitSelection>("ten");
88-
const [isRecordButtonDisabled, setIsRecordButtonDisabled] = useState(false); // New state variable
8986
const [datasets, setDatasets] = useState<any[]>([]);
9087
const currentFilenameRef = useRef<string>("");
91-
const [hasData, setHasData] = useState(false);
92-
const [recData, setrecData] = useState(false);
88+
const [isRecordButtonDisabled, setIsRecordButtonDisabled] = useState(false);
9389
const [recordingElapsedTime, setRecordingElapsedTime] = useState<number>(0); // State to store the recording duration
94-
const [elapsedTime, setElapsedTime] = useState<number>(0); // State to store the recording duration
9590
const recordingStartTime = useRef<number>(0);
9691
const [customTime, setCustomTime] = useState<string>(""); // State to store the custom stop time input
92+
const [clickCount, setClickCount] = useState(0); // Track how many times the left arrow is clicked
9793
const endTimeRef = useRef<number | null>(null); // Ref to store the end time of the recording
9894
const [popoverVisible, setPopoverVisible] = useState(false);
9995
const portRef = useRef<SerialPort | null>(null); // Ref to store the serial port
100-
const indexedDBRef = useRef<IDBDatabase | null>(null);
101-
const [ifBits, setifBits] = useState<BitSelection>("auto");
96+
const [ifBits, setifBits] = useState<BitSelection>("auto");
10297
const [showAllChannels, setShowAllChannels] = useState(false);
10398
const [FullZoom, setFullZoom] = useState(false);
10499
const canvasnumbersRef = useRef<number>(1);
@@ -132,8 +127,6 @@ const Connection: React.FC<ConnectionProps> = ({
132127
}
133128
};
134129

135-
const [clickCount, setClickCount] = useState(0); // Track how many times the left arrow is clicked
136-
137130
const enabledClicks = (snapShotRef.current?.filter(Boolean).length ?? 0) - 1;
138131

139132
// Enable/Disable left arrow button
@@ -193,7 +186,6 @@ const Connection: React.FC<ConnectionProps> = ({
193186
}
194187
};
195188

196-
197189
useEffect(() => {
198190
canvasnumbersRef.current = canvasCount; // Sync the ref with the state
199191
}, [canvasCount,isRecordingRef]);
@@ -269,7 +261,6 @@ const Connection: React.FC<ConnectionProps> = ({
269261
}
270262
};
271263

272-
273264
// Function to handle saving data by filename
274265
const saveDataByFilename = async (filename: string, canvasCount: number) => {
275266
if (workerRef.current) {
@@ -354,7 +345,6 @@ const Connection: React.FC<ConnectionProps> = ({
354345
baudRate: number;
355346
}
356347

357-
358348
const connectToDevice = async () => {
359349
try {
360350
if (portRef.current && portRef.current.readable) {
@@ -485,7 +475,6 @@ const Connection: React.FC<ConnectionProps> = ({
485475
});
486476
};
487477

488-
489478
const disconnectDevice = async (): Promise<void> => {
490479
try {
491480
if (portRef.current) {
@@ -679,8 +668,7 @@ const Connection: React.FC<ConnectionProps> = ({
679668
.filter((value): value is number => value !== null); // Filter out null values
680669
// Check if recording is enabled
681670
recordingBuffers[activeBufferIndex][fillingindex.current] = channeldatavalues;
682-
// activeBuffer.push(channeldatavalues); // Store the channel data in the recording buffer
683-
671+
684672
if (fillingindex.current >= MAX_BUFFER_SIZE - 1) {
685673
processBuffer(activeBufferIndex,canvasnumbersRef.current);
686674
activeBufferIndex = (activeBufferIndex + 1) % NUM_BUFFERS;
@@ -736,8 +724,7 @@ const Connection: React.FC<ConnectionProps> = ({
736724
const now = new Date();
737725
recordingStartTime.current = Date.now();
738726
setRecordingElapsedTime(Date.now());
739-
setrecData(true);
740-
727+
setIsRecordButtonDisabled(true);
741728

742729
const filename = `ChordsWeb-${now.getFullYear()}${String(now.getMonth() + 1).padStart(2, '0')}${String(now.getDate()).padStart(2, '0')}-` +
743730
`${String(now.getHours()).padStart(2, '0')}${String(now.getMinutes()).padStart(2, '0')}${String(now.getSeconds()).padStart(2, '0')}.csv`;
@@ -751,11 +738,9 @@ const Connection: React.FC<ConnectionProps> = ({
751738
toast.error("Recording start time was not captured.");
752739
return;
753740
}
754-
const endTime = new Date();
755-
const durationInSeconds = Math.floor((Date.now() - recordingStartTime.current) / 1000);
756741
isRecordingRef.current = false;
757742
setRecordingElapsedTime(0);
758-
setrecData(false);
743+
setIsRecordButtonDisabled(false);
759744
// setRecordingStartTime(0);
760745
recordingStartTime.current = 0;
761746
existingRecordRef.current = undefined;
@@ -1452,7 +1437,7 @@ const Connection: React.FC<ConnectionProps> = ({
14521437
<Button
14531438
className="rounded-xl rounded-r-none"
14541439
onClick={decreaseCanvas}
1455-
disabled={canvasCount === 1 || !isDisplay || recData}
1440+
disabled={canvasCount === 1 || !isDisplay || isRecordButtonDisabled}
14561441
>
14571442
<Minus size={16} />
14581443
</Button>
@@ -1474,7 +1459,7 @@ const Connection: React.FC<ConnectionProps> = ({
14741459
<Button
14751460
className="flex items-center justify-center px-3 py-2 rounded-none select-none"
14761461
onClick={toggleShowAllChannels}
1477-
disabled={!isDisplay || recData}
1462+
disabled={!isDisplay || isRecordButtonDisabled}
14781463
>
14791464
CH
14801465
</Button>
@@ -1496,7 +1481,7 @@ const Connection: React.FC<ConnectionProps> = ({
14961481
<Button
14971482
className="rounded-xl rounded-l-none"
14981483
onClick={increaseCanvas}
1499-
disabled={canvasCount >= (detectedBitsRef.current == "twelve" ? 3 : 6) || !isDisplay || recData}
1484+
disabled={canvasCount >= (detectedBitsRef.current == "twelve" ? 3 : 6) || !isDisplay || isRecordButtonDisabled}
15001485
>
15011486
<Plus size={16} />
15021487
</Button>

workers/indexedDBWorker.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import JSZip from 'jszip';
33
self.onmessage = async (event) => {
44
const { action, data, filename, canvasCount } = event.data;
55

6-
76
// Open IndexedDB
87
const db = await openIndexedDB();
98

@@ -44,8 +43,6 @@ self.onmessage = async (event) => {
4443
self.postMessage({ error });
4544
}
4645
break;
47-
48-
4946
default:
5047
self.postMessage({ error: 'Invalid action' });
5148
}
@@ -92,7 +89,6 @@ const writeToIndexedDB = async (db: IDBDatabase, data: number[][], filename: str
9289
putRequest.onerror = () => reject(false);
9390
}
9491
};
95-
9692
getRequest.onerror = () => reject(false);
9793
});
9894
};
@@ -119,10 +115,6 @@ const getAllDataFromIndexedDB = async (db: IDBDatabase): Promise<any[]> => {
119115
});
120116
};
121117

122-
123-
124-
125-
126118
// Function to convert data to CSV
127119
const convertToCSV = (data: any[], canvasCount: number): string => {
128120
if (!Array.isArray(data) || data.length === 0) return "";
@@ -149,8 +141,6 @@ const convertToCSV = (data: any[], canvasCount: number): string => {
149141
return [header.join(","), ...rows].join("\n");
150142
};
151143

152-
153-
154144
// Function to save all data as a ZIP file
155145
const saveAllDataAsZip = async (canvasCount: number): Promise<Blob> => {
156146
try {

0 commit comments

Comments
 (0)