From 7cf77631931c55b35de2667bc9efc5dbe767e82d Mon Sep 17 00:00:00 2001 From: Alex Kern Date: Wed, 16 Jul 2025 16:02:58 -0700 Subject: [PATCH] fmt --- src/components/ConnectionListItem.tsx | 4 ++-- src/components/ProgressBar.tsx | 10 ++++++++-- src/hooks/useDownloader.ts | 16 ++++++++++------ src/hooks/useUploaderConnections.ts | 17 ++++++++++++----- 4 files changed, 32 insertions(+), 15 deletions(-) diff --git a/src/components/ConnectionListItem.tsx b/src/components/ConnectionListItem.tsx index f562943..ee9f2d0 100644 --- a/src/components/ConnectionListItem.tsx +++ b/src/components/ConnectionListItem.tsx @@ -61,8 +61,8 @@ export function ConnectionListItem({ +
{Math.round(percentage)}%
@@ -25,7 +28,10 @@ export default function ProgressBar({ style={{ width: `${percentage}%` }} />
- + {Math.round(percentage)}%
diff --git a/src/hooks/useDownloader.ts b/src/hooks/useDownloader.ts index b1f04cc..b657a3a 100644 --- a/src/hooks/useDownloader.ts +++ b/src/hooks/useDownloader.ts @@ -208,7 +208,7 @@ export function useDownloader(uploaderPeerID: string): { console.error('[Downloader] no stream found for', message.fileName) return } - + // Track chunks for e2e testing if (!chunkCountByFile[message.fileName]) { chunkCountByFile[message.fileName] = 0 @@ -217,11 +217,11 @@ export function useDownloader(uploaderPeerID: string): { console.log( `[Downloader] received chunk ${chunkCountByFile[message.fileName]} for ${message.fileName} (${message.offset}-${message.offset + (message.bytes as ArrayBuffer).byteLength}) final=${message.final}`, ) - + const chunkSize = (message.bytes as ArrayBuffer).byteLength setBytesDownloaded((bd) => bd + chunkSize) fileStream.enqueue(new Uint8Array(message.bytes as ArrayBuffer)) - + // Send acknowledgment to uploader const ackMessage: Message = { type: MessageType.ChunkAck, @@ -230,10 +230,14 @@ export function useDownloader(uploaderPeerID: string): { bytesReceived: chunkSize, } dataConnection.send(ackMessage) - console.log(`[Downloader] sent ack for chunk ${chunkCountByFile[message.fileName]} (${message.offset}, ${chunkSize} bytes)`) - + console.log( + `[Downloader] sent ack for chunk ${chunkCountByFile[message.fileName]} (${message.offset}, ${chunkSize} bytes)`, + ) + if (message.final) { - console.log(`[Downloader] finished receiving ${message.fileName} after ${chunkCountByFile[message.fileName]} chunks`) + console.log( + `[Downloader] finished receiving ${message.fileName} after ${chunkCountByFile[message.fileName]} chunks`, + ) fileStream.close() startNextFileOrFinish() } diff --git a/src/hooks/useUploaderConnections.ts b/src/hooks/useUploaderConnections.ts index f9c8840..30a447d 100644 --- a/src/hooks/useUploaderConnections.ts +++ b/src/hooks/useUploaderConnections.ts @@ -5,7 +5,12 @@ import { UploaderConnection, UploaderConnectionStatus, } from '../types' -import { decodeMessage, Message, MessageType, ChunkAckMessage } from '../messages' +import { + decodeMessage, + Message, + MessageType, + ChunkAckMessage, +} from '../messages' import { z } from 'zod' import { getFileName } from '../fs' import { setRotating } from './useRotatingSpinner' @@ -331,13 +336,15 @@ export function useUploaderConnections( 'bytes', ackMessage.bytesReceived, ) - + updateConnection((draft) => { const currentAcked = draft.acknowledgedBytes || 0 const newAcked = currentAcked + ackMessage.bytesReceived - + // Find the file to calculate progress - const file = files.find(f => getFileName(f) === ackMessage.fileName) + const file = files.find( + (f) => getFileName(f) === ackMessage.fileName, + ) if (file) { const acknowledgedProgress = newAcked / file.size return { @@ -346,7 +353,7 @@ export function useUploaderConnections( currentFileProgress: acknowledgedProgress, } } - + return { ...draft, acknowledgedBytes: newAcked,