Skip to content

Commit 81107c0

Browse files
author
Ritika Mishra
committed
updated ui
1 parent 4cc87c6 commit 81107c0

File tree

1 file changed

+29
-32
lines changed

1 file changed

+29
-32
lines changed

src/components/Connection.tsx

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ const Connection: React.FC<ConnectionProps> = ({
9797
const endTimeRef = useRef<number | null>(null); // Ref to store the end time of the recording
9898
const [popoverVisible, setPopoverVisible] = useState(false);
9999
const portRef = useRef<SerialPort | null>(null); // Ref to store the serial port
100-
const [ifBits, setifBits] = useState<BitSelection>("auto");
100+
const [ifBits, setifBits] = useState<BitSelection>("auto");
101101
const [showAllChannels, setShowAllChannels] = useState(false);
102102
const [FullZoom, setFullZoom] = useState(false);
103103
const canvasnumbersRef = useRef<number>(1);
@@ -127,15 +127,14 @@ const Connection: React.FC<ConnectionProps> = ({
127127
};
128128
const increaseCanvas = () => {
129129
if (canvasCount < (detectedBitsRef.current == "twelve" ? 3 : 6)) {
130-
131130
setCanvasCount(canvasCount + 1); // Increase canvas count up to 6
132131
}
133132
};
134-
133+
135134
const increaseValue = () => {
136135
if(currentValue < 10){
137-
setCurrentValue(currentValue + 1);
138-
}
136+
setCurrentValue(currentValue + 1);
137+
}
139138
};
140139

141140
const enabledClicks = (snapShotRef.current?.filter(Boolean).length ?? 0) - 1;
@@ -151,8 +150,6 @@ const Connection: React.FC<ConnectionProps> = ({
151150
}
152151
};
153152

154-
155-
156153
// Handle right arrow click (reset count and disable button if needed)
157154
const handleNextSnapshot = () => {
158155
if (clickCount > 0) {
@@ -170,10 +167,10 @@ const Connection: React.FC<ConnectionProps> = ({
170167
};
171168
const decreaseValue = () => {
172169
if(currentValue > 1){
173-
setCurrentValue(currentValue - 1);
170+
setCurrentValue(currentValue - 1);
174171
}
175172
};
176-
173+
177174
const toggleShowAllChannels = () => {
178175
if (canvasCount === (detectedBitsRef.current == "twelve" ? 3 : 6)) {
179176
setCanvasCount(1); // If canvasCount is 6, reduce it to 1
@@ -245,28 +242,28 @@ const Connection: React.FC<ConnectionProps> = ({
245242
workerRef.current?.postMessage({ action: 'setCanvasCount', canvasCount: canvasnumbersRef.current });
246243
};
247244
setCanvasCountInWorker(canvasnumbersRef.current);
248-
245+
249246
const processBuffer = async (bufferIndex: number, canvasCount: number) => {
250247
if (!workerRef.current) {
251248
initializeWorker();
252249
}
253250

254251
// If the buffer is empty, return early
255252
if (recordingBuffers[bufferIndex].length === 0) return;
256-
253+
257254
const data = recordingBuffers[bufferIndex];
258255
const filename = currentFilenameRef.current;
259-
256+
260257
if (filename) {
261258
// Check if the record already exists
262259
workerRef.current?.postMessage({ action: 'checkExistence', filename, canvasCount });
263260
writeToIndexedDB(data, filename, canvasCount);
264261
}
265262
};
266-
263+
267264
const writeToIndexedDB = (data: number[][], filename: string, canvasCount: number) => {
268265
workerRef.current?.postMessage({ action: 'write', data, filename, canvasCount });
269-
};
266+
};
270267

271268
const saveAllDataAsZip = async () => {
272269
try {
@@ -694,7 +691,7 @@ const Connection: React.FC<ConnectionProps> = ({
694691
.filter((value): value is number => value !== null); // Filter out null values
695692
// Check if recording is enabled
696693
recordingBuffers[activeBufferIndex][fillingindex.current] = channeldatavalues;
697-
694+
698695
if (fillingindex.current >= MAX_BUFFER_SIZE - 1) {
699696
processBuffer(activeBufferIndex, canvasnumbersRef.current);
700697
activeBufferIndex = (activeBufferIndex + 1) % NUM_BUFFERS;
@@ -791,26 +788,26 @@ const Connection: React.FC<ConnectionProps> = ({
791788
const deleteFilesByFilename = async (filename: string) => {
792789
try {
793790
const dbRequest = indexedDB.open("ChordsRecordings");
794-
791+
795792
dbRequest.onsuccess = (event) => {
796793
const db = (event.target as IDBOpenDBRequest).result;
797794
const transaction = db.transaction("ChordsRecordings", "readwrite");
798795
const store = transaction.objectStore("ChordsRecordings");
799-
796+
800797
// Check if the "filename" index exists
801798
if (!store.indexNames.contains("filename")) {
802799
console.error("Index 'filename' does not exist.");
803800
toast.error("Unable to delete files: index not found.");
804801
return;
805802
}
806-
803+
807804
const index = store.index("filename");
808805
const deleteRequest = index.openCursor(IDBKeyRange.only(filename));
809-
806+
810807
// Make this callback async
811808
deleteRequest.onsuccess = async (event) => {
812809
const cursor = (event.target as IDBRequest<IDBCursorWithValue>).result;
813-
810+
814811
if (cursor) {
815812
cursor.delete(); // Delete the current record
816813
// Fetch the updated data and update state
@@ -821,22 +818,22 @@ const Connection: React.FC<ConnectionProps> = ({
821818
toast.success("File deleted successfully.");
822819
}
823820
};
824-
821+
825822
deleteRequest.onerror = () => {
826823
console.error("Error during delete operation.");
827824
toast.error("Failed to delete the file. Please try again.");
828825
};
829-
826+
830827
transaction.oncomplete = () => {
831828
console.log("File deletion transaction completed.");
832829
};
833-
830+
834831
transaction.onerror = () => {
835832
console.error("Transaction failed during deletion.");
836833
toast.error("Failed to delete the file. Please try again.");
837834
};
838835
};
839-
836+
840837
dbRequest.onerror = () => {
841838
console.error("Failed to open IndexedDB database.");
842839
toast.error("An error occurred while accessing the database.");
@@ -846,7 +843,7 @@ const Connection: React.FC<ConnectionProps> = ({
846843
toast.error("An unexpected error occurred. Please try again.");
847844
}
848845
};
849-
846+
850847
// Function to delete all data from IndexedDB (for ZIP files or clear all)
851848
const deleteAllDataFromIndexedDB = async () => {
852849
return new Promise<void>((resolve, reject) => {
@@ -917,20 +914,20 @@ const Connection: React.FC<ConnectionProps> = ({
917914
{/* Left-aligned section */}
918915
<div className="absolute left-4 flex items-center mx-0 px-0 space-x-1">
919916
{isRecordingRef.current && (
920-
<div className="flex items-center space-x-1 w-min ml-2">
921-
<button className="flex items-center justify-center px-3 py-2 select-none min-w-20 bg-primary text-destructive whitespace-nowrap rounded-xl"
917+
<div className="flex items-center space-x-1 w-min">
918+
<button className="flex items-center justify-center px-1 py-2 select-none min-w-20 bg-primary text-destructive whitespace-nowrap rounded-xl"
922919
>
923920
{formatTime(recordingElapsedTime)}
924921
</button>
925-
<Separator orientation="vertical" className="bg-primary h-9 ml-2" />
922+
<Separator orientation="vertical" className="bg-primary h-9 " />
926923
<div>
927924
<Popover
928925
open={isEndTimePopoverOpen}
929926
onOpenChange={setIsEndTimePopoverOpen}
930927
>
931928
<PopoverTrigger asChild>
932929
<Button
933-
className="flex items-center justify-center px-3 py-2 select-none min-w-12 text-destructive whitespace-nowrap rounded-xl"
930+
className="flex items-center justify-center px-1 py-2 select-none min-w-10 text-destructive whitespace-nowrap rounded-xl"
934931
variant="destructive"
935932
>
936933
{endTimeRef.current === null ? (
@@ -995,7 +992,7 @@ const Connection: React.FC<ConnectionProps> = ({
995992
<TooltipProvider>
996993
<Tooltip>
997994
<TooltipTrigger asChild>
998-
<Button className="flex items-center justify-center gap-1 py-2 px-6 sm:py-3 sm:px-8 rounded-xl font-semibold" onClick={handleClick}>
995+
<Button className="flex items-center justify-center gap-1 py-2 px-2 sm:py-3 sm:px-4 rounded-xl font-semibold" onClick={handleClick}>
999996
{isConnected ? (
1000997
<>
1001998
Disconnect
@@ -1166,7 +1163,7 @@ const Connection: React.FC<ConnectionProps> = ({
11661163
<div className="flex space-x-2">
11671164
{/* Save file by filename */}
11681165
<Button
1169-
onClick={() => saveDataByFilename(dataset,canvasCount)}
1166+
onClick={() => saveDataByFilename(dataset, canvasCount)}
11701167
className="rounded-xl px-4"
11711168
>
11721169
<Download size={16} />
@@ -1562,7 +1559,7 @@ const Connection: React.FC<ConnectionProps> = ({
15621559
<Button
15631560
className="rounded-xl rounded-l-none"
15641561
onClick={increaseValue}
1565-
disabled={currentValue >= 10 }
1562+
disabled={currentValue >= 10}
15661563
>
15671564
<Plus size={16} />
15681565
</Button>

0 commit comments

Comments
 (0)