fix(chat): apply unlocked voice audio url
This commit is contained in:
@@ -8,7 +8,7 @@ import styles from "./voice-bubble.module.css";
|
||||
|
||||
export interface VoiceBubbleProps {
|
||||
messageId?: string;
|
||||
audioUrl: string;
|
||||
audioUrl?: string | null;
|
||||
isFromAI: boolean;
|
||||
locked?: boolean;
|
||||
hint?: string | null;
|
||||
@@ -28,6 +28,7 @@ export function VoiceBubble({
|
||||
const audioRef = useRef<HTMLAudioElement>(null);
|
||||
const [isPlaying, setIsPlaying] = useState(false);
|
||||
const [errorMediaUrl, setErrorMediaUrl] = useState<string | null>(null);
|
||||
const hasAudio = audioUrl != null && audioUrl.length > 0;
|
||||
const { mediaUrl, isUsingCachedMedia, reportMediaError } =
|
||||
useCachedChatMediaUrl({
|
||||
messageId,
|
||||
@@ -66,7 +67,7 @@ export function VoiceBubble({
|
||||
const hasError = errorMediaUrl === mediaUrl;
|
||||
|
||||
const handleToggle = () => {
|
||||
if (locked) return;
|
||||
if (locked || !hasAudio) return;
|
||||
|
||||
const audio = audioRef.current;
|
||||
if (!audio || hasError) return;
|
||||
@@ -92,7 +93,7 @@ export function VoiceBubble({
|
||||
type="button"
|
||||
className={styles.playButton}
|
||||
onClick={handleToggle}
|
||||
disabled={locked || hasError}
|
||||
disabled={locked || hasError || !hasAudio}
|
||||
aria-label={isPlaying ? "Pause voice message" : "Play voice message"}
|
||||
>
|
||||
{locked ? (
|
||||
@@ -132,7 +133,7 @@ export function VoiceBubble({
|
||||
</>
|
||||
) : null}
|
||||
</div>
|
||||
{!locked ? (
|
||||
{!locked && hasAudio ? (
|
||||
<audio ref={audioRef} src={mediaUrl} preload="metadata" />
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user