Refactor WhisperButton to enhance icon representation and prevent default click behavior
This commit is contained in:
@@ -3,6 +3,12 @@ import { createRef } from "preact";
|
|||||||
import { ChatStore } from "@/types/chatstore";
|
import { ChatStore } from "@/types/chatstore";
|
||||||
import { StateUpdater, useEffect, useState, Dispatch } from "preact/hooks";
|
import { StateUpdater, useEffect, useState, Dispatch } from "preact/hooks";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
|
import {
|
||||||
|
AudioWaveform,
|
||||||
|
AudioWaveformIcon,
|
||||||
|
MicIcon,
|
||||||
|
VoicemailIcon,
|
||||||
|
} from "lucide-react";
|
||||||
|
|
||||||
const WhisperButton = (props: {
|
const WhisperButton = (props: {
|
||||||
chatStore: ChatStore;
|
chatStore: ChatStore;
|
||||||
@@ -14,11 +20,14 @@ const WhisperButton = (props: {
|
|||||||
const [isRecording, setIsRecording] = useState("Mic");
|
const [isRecording, setIsRecording] = useState("Mic");
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button
|
||||||
variant={isRecording === "Recording" ? "destructive" : "default"}
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
className={`m-1 p-1 ${isRecording !== "Mic" ? "animate-pulse" : ""}`}
|
className={`m-1 p-1 ${isRecording !== "Mic" ? "animate-pulse" : ""}`}
|
||||||
disabled={isRecording === "Transcribing"}
|
disabled={isRecording === "Transcribing"}
|
||||||
ref={mediaRef}
|
ref={mediaRef}
|
||||||
onClick={async () => {
|
onClick={async (event) => {
|
||||||
|
event.preventDefault(); // Prevent the default behavior
|
||||||
|
|
||||||
if (isRecording === "Recording") {
|
if (isRecording === "Recording") {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
window.mediaRecorder.stop();
|
window.mediaRecorder.stop();
|
||||||
@@ -124,7 +133,13 @@ const WhisperButton = (props: {
|
|||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{isRecording}
|
{isRecording === "Mic" ? (
|
||||||
|
<MicIcon />
|
||||||
|
) : isRecording === "Recording" ? (
|
||||||
|
<VoicemailIcon />
|
||||||
|
) : (
|
||||||
|
<AudioWaveformIcon />
|
||||||
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user