Skip to content

Commit d7154c7

Browse files
🔴 refactor: Enhance Recorder component with stop functionality and UI updates
- Added `StopCircle` icon from `lucide-react` for a clear stop recording action. - Implemented hover state logic to switch between recording indicator and stop icon. - Improved formatting and logic for starting and stopping recordings.
1 parent 51c8016 commit d7154c7

2 files changed

Lines changed: 32 additions & 12 deletions

File tree

‎apps/desktop/src/components/Recorder.tsx‎

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useEffect, useState, useRef } from "react";
22
import { Source, UploadLink, baseUrl, isProd } from "../utils";
3-
import { Video } from "lucide-react";
3+
import { StopCircle, Video } from "lucide-react";
44
import { captureException } from "@sentry/react";
55
import { Progress } from "./ui/progress";
66

@@ -22,6 +22,7 @@ export function Recorder({
2222
const [audioStream, setAudioStream] = useState<MediaStream | null>(null);
2323
const [progress, setProgress] = useState(13);
2424
const [justStarted, setJustStarted] = useState(false);
25+
const [isHoveringStopRecording, setIsHoveringStopRecording] = useState(false);
2526

2627
const uploadFile = async (
2728
uploadFilePath: string,
@@ -48,7 +49,7 @@ export function Recorder({
4849
}
4950
await window.electron.uploadVideo(uploadFilePath, uploadLink);
5051
const uploadUrl = `${baseUrl}/view/${uploadId}`;
51-
if(openInBrowser) await window.electron.openInBrowser(uploadUrl);
52+
if (openInBrowser) await window.electron.openInBrowser(uploadUrl);
5253
} catch (error) {
5354
console.error("Failed to upload file:", error);
5455
captureException(error, {
@@ -365,7 +366,11 @@ export function Recorder({
365366
}
366367
};
367368

368-
const stopRecording = () => {
369+
const stopRecording = async () => {
370+
await window.electron.stopRecording();
371+
};
372+
373+
const stopRecordingStreams = () => {
369374
try {
370375
setIsRecording(false);
371376

@@ -415,25 +420,40 @@ export function Recorder({
415420
// @ts-ignore
416421
window.electron.on("finished-recording", (status: boolean) => {
417422
if (status) {
418-
stopRecording();
423+
stopRecordingStreams();
419424
}
420425
});
421426

422427
return (
423428
<div>
424429
<button
425-
onClick={startRecording}
426-
disabled={isRecording}
430+
onClick={isRecording ? stopRecording : startRecording}
427431
className={`w-full h-10 group relative justify-center gap-2 transition-all duration-300 ease-out hover:ring-2 hover:ring-primary hover:ring-offset-2 bg-sky-700 text-white hover:bg-sky-900 border border-transparent hover:border-sky-900 focus:border-sky-500 focus:ring focus:ring-sky-500 rounded-lg ${
428432
isRecording &&
429433
"bg-red-500 hover:bg-red-600 focus:border-red-400 focus:ring-red-400"
430434
}`}
431435
>
432436
{isRecording ? (
433-
<div className="flex items-center">
434-
<div className="animate-ping absolute inline-flex h-3 w-3 rounded-full bg-red-400 opacity-75 ml-3"></div>
435-
<div className="relative inline-flex rounded-full h-3 w-3 bg-red-400 ml-3"></div>
436-
<span className="text-md ml-3">Recording...</span>
437+
<div
438+
className="flex items-center justify-between"
439+
onMouseEnter={() => setIsHoveringStopRecording(true)}
440+
onMouseLeave={() => setIsHoveringStopRecording(false)}
441+
>
442+
<div className="flex items-center">
443+
{isHoveringStopRecording ? (
444+
<StopCircle className={"ml-2 h-4 w-4 "} />
445+
) : (
446+
<>
447+
<div className="animate-ping absolute inline-flex h-3 w-3 rounded-full bg-red-400 opacity-75 ml-3"></div>
448+
<div className="relative inline-flex rounded-full h-3 w-3 bg-red-400 ml-3"></div>
449+
</>
450+
)}
451+
{isHoveringStopRecording ? (
452+
<span className="text-md ml-3">Stop Recording</span>
453+
) : (
454+
<span className="text-md ml-3">Recording...</span>
455+
)}
456+
</div>
437457
</div>
438458
) : justStarted ? (
439459
<div className="flex items-center justify-center">
@@ -452,4 +472,4 @@ export function Recorder({
452472
)}
453473
</div>
454474
);
455-
}
475+
}

‎apps/desktop/src/utils.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,4 @@ export const logout = async () => {
7070
export const refreshDeviceCode = async () => {
7171
const newDeviceCode = await window.electron.getDeviceCode();
7272
return newDeviceCode;
73-
};
73+
};

0 commit comments

Comments
 (0)