fix audio label translation in explore filter

This commit is contained in:
Josh Hawkins 2025-12-27 07:30:24 -06:00
parent 25b36a1a7a
commit e32d250f39

View File

@ -251,11 +251,30 @@ function GeneralFilterButton({
updateLabelFilter, updateLabelFilter,
}: GeneralFilterButtonProps) { }: GeneralFilterButtonProps) {
const { t } = useTranslation(["components/filter"]); const { t } = useTranslation(["components/filter"]);
const { data: config } = useSWR<FrigateConfig>("config", {
revalidateOnFocus: false,
});
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
const [currentLabels, setCurrentLabels] = useState<string[] | undefined>( const [currentLabels, setCurrentLabels] = useState<string[] | undefined>(
selectedLabels, selectedLabels,
); );
const allAudioListenLabels = useMemo<Set<string>>(() => {
if (!config) {
return new Set<string>();
}
const labels = new Set<string>();
Object.values(config.cameras).forEach((camera) => {
if (camera?.audio?.enabled) {
camera.audio.listen.forEach((label) => {
labels.add(label);
});
}
});
return labels;
}, [config]);
const buttonText = useMemo(() => { const buttonText = useMemo(() => {
if (isMobile) { if (isMobile) {
return t("labels.all.short"); return t("labels.all.short");
@ -266,13 +285,17 @@ function GeneralFilterButton({
} }
if (selectedLabels.length == 1) { if (selectedLabels.length == 1) {
return getTranslatedLabel(selectedLabels[0]); const label = selectedLabels[0];
return getTranslatedLabel(
label,
allAudioListenLabels.has(label) ? "audio" : "object",
);
} }
return t("labels.count", { return t("labels.count", {
count: selectedLabels.length, count: selectedLabels.length,
}); });
}, [selectedLabels, t]); }, [selectedLabels, allAudioListenLabels, t]);
// ui // ui