fix: coderabbit

This commit is contained in:
DESKTOP-RTLN3BA\$punk 2025-05-05 23:31:52 -07:00
parent 8b8fd4fbad
commit 5c79831ca5
2 changed files with 27 additions and 14 deletions

View file

@ -472,11 +472,12 @@ export default function ChatsPageClient({ searchSpaceId }: ChatsPageClientProps)
size="sm"
onClick={selectAllVisibleChats}
className="gap-1"
title="Select or deselect all chats on the current page"
>
<CheckCircle className="h-4 w-4" />
{currentChats.every(chat => selectedChats.includes(chat.id))
? "Deselect All"
: "Select All"}
? "Deselect Page"
: "Select Page"}
</Button>
<Button
variant="default"
@ -567,7 +568,12 @@ export default function ChatsPageClient({ searchSpaceId }: ChatsPageClientProps)
className={`overflow-hidden hover:shadow-md transition-shadow
${selectionMode && selectedChats.includes(chat.id)
? 'ring-2 ring-primary ring-offset-2' : ''}`}
onClick={() => selectionMode ? toggleChatSelection(chat.id) : null}
onClick={(e) => {
if (!selectionMode) return;
// Ignore clicks coming from interactive elements
if ((e.target as HTMLElement).closest('button, a, [data-stop-selection]')) return;
toggleChatSelection(chat.id);
}}
>
<CardHeader className="pb-3">
<div className="flex justify-between items-start">
@ -592,7 +598,12 @@ export default function ChatsPageClient({ searchSpaceId }: ChatsPageClientProps)
{!selectionMode && (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="ghost" size="icon" className="h-8 w-8">
<Button
variant="ghost"
size="icon"
className="h-8 w-8"
data-stop-selection
>
<MoreHorizontal className="h-4 w-4" />
<span className="sr-only">Open menu</span>
</Button>

View file

@ -38,7 +38,7 @@ import {
} from "@/components/ui/select";
import { toast } from "sonner";
interface Podcast {
interface PodcastItem {
id: number;
title: string;
created_at: string;
@ -66,8 +66,8 @@ const podcastCardVariants = {
const MotionCard = motion(Card);
export default function PodcastsPageClient({ searchSpaceId }: PodcastsPageClientProps) {
const [podcasts, setPodcasts] = useState<Podcast[]>([]);
const [filteredPodcasts, setFilteredPodcasts] = useState<Podcast[]>([]);
const [podcasts, setPodcasts] = useState<PodcastItem[]>([]);
const [filteredPodcasts, setFilteredPodcasts] = useState<PodcastItem[]>([]);
const [isLoading, setIsLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
const [searchQuery, setSearchQuery] = useState('');
@ -77,7 +77,7 @@ export default function PodcastsPageClient({ searchSpaceId }: PodcastsPageClient
const [isDeleting, setIsDeleting] = useState(false);
// Audio player state
const [currentPodcast, setCurrentPodcast] = useState<Podcast | null>(null);
const [currentPodcast, setCurrentPodcast] = useState<PodcastItem | null>(null);
const [audioSrc, setAudioSrc] = useState<string | undefined>(undefined);
const [isAudioLoading, setIsAudioLoading] = useState(false);
const [isPlaying, setIsPlaying] = useState(false);
@ -123,7 +123,7 @@ export default function PodcastsPageClient({ searchSpaceId }: PodcastsPageClient
throw new Error(`Failed to fetch podcasts: ${response.status} ${errorData?.detail || ''}`);
}
const data: Podcast[] = await response.json();
const data: PodcastItem[] = await response.json();
setPodcasts(data);
setFilteredPodcasts(data);
setError(null);
@ -257,7 +257,7 @@ export default function PodcastsPageClient({ searchSpaceId }: PodcastsPageClient
};
// Play podcast - Fetch blob and set object URL
const playPodcast = async (podcast: Podcast) => {
const playPodcast = async (podcast: PodcastItem) => {
// If the same podcast is selected, just toggle play/pause
if (currentPodcast && currentPodcast.id === podcast.id) {
togglePlayPause();
@ -302,12 +302,14 @@ export default function PodcastsPageClient({ searchSpaceId }: PodcastsPageClient
const blob = await response.blob();
const objectUrl = URL.createObjectURL(blob);
currentObjectUrlRef.current = objectUrl;
// Wait for React to commit the new `src`
setAudioSrc(objectUrl);
// Let the audio element load the new src
setTimeout(() => {
// Use requestAnimationFrame instead of setTimeout for more reliable DOM updates
requestAnimationFrame(() => {
if (audioRef.current) {
audioRef.current.load();
// The <audio> element has the new src now
audioRef.current.play()
.then(() => {
setIsPlaying(true);
@ -318,7 +320,7 @@ export default function PodcastsPageClient({ searchSpaceId }: PodcastsPageClient
setIsPlaying(false);
});
}
}, 50);
});
} catch (error) {
console.error('Error fetching or playing podcast:', error);