fix double ding

This commit is contained in:
Jamie Pine
2026-01-11 01:54:25 -08:00
parent 4c520860f2
commit 85e9dba208
3 changed files with 34 additions and 18 deletions

View File

@@ -7,6 +7,10 @@ import { sounds } from "@sd/assets/sounds";
// This prevents multiple hook instances from playing the sound multiple times
const completedJobSounds = new Set<string>();
// Global throttle to prevent multiple sounds within 5 seconds
let lastSoundPlayedAt = 0;
const SOUND_THROTTLE_MS = 5000;
/**
* Unified hook for job management and counting.
* Prevents duplicate queries and subscriptions that were causing infinite loops.
@@ -56,11 +60,17 @@ export function useJobs() {
if (jobId && !completedJobSounds.has(jobId)) {
completedJobSounds.add(jobId);
// Play job-specific sound
if (jobType?.includes("copy") || jobType?.includes("Copy")) {
sounds.copy();
} else {
sounds.jobDone();
// Throttle: only play sound if enough time has passed since last sound
const now = Date.now();
if (now - lastSoundPlayedAt >= SOUND_THROTTLE_MS) {
lastSoundPlayedAt = now;
// Play job-specific sound
if (jobType?.includes("copy") || jobType?.includes("Copy")) {
sounds.copy();
} else {
sounds.jobDone();
}
}
// Clean up old entries after 5 seconds to prevent memory leak

View File

@@ -1,4 +1,4 @@
import { useState, useEffect } from "react";
import { useState, useEffect, memo } from "react";
import { GearSix, Palette, ArrowsClockwise, ListBullets, CircleNotch, ArrowsOut, FunnelSimple } from "@phosphor-icons/react";
import { useSidebarStore, useLibraryMutation } from "@sd/ts-client";
import type { SpaceGroup as SpaceGroupType, SpaceItem as SpaceItemType } from "@sd/ts-client";
@@ -95,7 +95,7 @@ function SpaceGroupWithDropZone({
}
// Sync Monitor Button with Popover
function SyncButton() {
const SyncButton = memo(function SyncButton() {
const popover = usePopover();
const navigate = useNavigate();
const [showActivityFeed, setShowActivityFeed] = useState(false);
@@ -198,18 +198,18 @@ function SyncButton() {
)}
</Popover>
);
}
});
// Jobs Button with Popover
function JobsButton({
activeJobCount,
hasRunningJobs,
jobs,
pause,
resume,
const JobsButton = memo(function JobsButton({
activeJobCount,
hasRunningJobs,
jobs,
pause,
resume,
cancel,
navigate
}: {
navigate
}: {
activeJobCount: number;
hasRunningJobs: boolean;
jobs: any[];
@@ -291,7 +291,13 @@ function JobsButton({
)}
</Popover>
);
}
}, (prevProps, nextProps) => {
// Only re-render if these specific values change
return (
prevProps.activeJobCount === nextProps.activeJobCount &&
prevProps.hasRunningJobs === nextProps.hasRunningJobs
);
});
interface SpacesSidebarProps {
isPreviewActive?: boolean;