bugfix: lyric search excludeSources was not being sent/state issues

This commit is contained in:
2025-07-19 08:01:29 -04:00
parent 814bbbff85
commit cc833e6694

View File

@@ -44,13 +44,6 @@ export default function LyricSearch() {
id="lyric-search-input" id="lyric-search-input"
placeholder="Artist - Song" placeholder="Artist - Song"
setShowLyrics={setShowLyrics} /> setShowLyrics={setShowLyrics} />
<br />
Exclude:<br />
<div id="exclude-checkboxes">
<UICheckbox id="excl-Genius" label="Genius" />
<UICheckbox id="excl-LRCLib" label="LRCLib" />
<UICheckbox id="excl-Cache" label="Cache" />
</div>
<div id="spinner" className="hidden"> <div id="spinner" className="hidden">
<CircularProgress <CircularProgress
variant="plain" variant="plain"
@@ -86,13 +79,15 @@ export function LyricSearchInputField({ id, placeholder, setShowLyrics }) {
// Toggle exclusion state for checkboxes // Toggle exclusion state for checkboxes
const toggleExclusion = (source) => { const toggleExclusion = (source) => {
const lower = source.toLowerCase();
setExcludedSources((prev) => setExcludedSources((prev) =>
prev.includes(source) prev.includes(lower)
? prev.filter((s) => s !== source) ? prev.filter((s) => s !== lower)
: [...prev, source] : [...prev, lower]
); );
}; };
// Show scrollable dropdown panel with mouse wheel handling // Show scrollable dropdown panel with mouse wheel handling
const handlePanelShow = () => { const handlePanelShow = () => {
setTimeout(() => { setTimeout(() => {
@@ -233,6 +228,13 @@ export function LyricSearchInputField({ id, placeholder, setShowLyrics }) {
<Button onClick={handleSearch} className="btn"> <Button onClick={handleSearch} className="btn">
Search Search
</Button> </Button>
<br />
Exclude:<br />
<div id="exclude-checkboxes">
<UICheckbox id="excl-Genius" label="Genius" onToggle={toggleExclusion} />
<UICheckbox id="excl-LRCLib" label="LRCLib" onToggle={toggleExclusion} />
<UICheckbox id="excl-Cache" label="Cache" onToggle={toggleExclusion} />
</div>
{isLoading && ( {isLoading && (
<div className="mt-3"> <div className="mt-3">
@@ -255,42 +257,47 @@ export function LyricSearchInputField({ id, placeholder, setShowLyrics }) {
} }
export const UICheckbox = forwardRef(function UICheckbox(opts = {}, ref) { export const UICheckbox = forwardRef(function UICheckbox(props = {}, ref) {
const [checked, setChecked] = useState(false); const [checked, setChecked] = useState(false);
const [showAlert, setShowAlert] = useState(false);
let valid_exclusions = true;
useImperativeHandle(ref, () => ({ useImperativeHandle(ref, () => ({
setChecked: (val) => setChecked(val), setChecked: (val) => setChecked(val),
checked, checked,
})); }));
const verifyExclusions = (e) => { const verifyExclusions = () => {
let exclude_error = false; const checkedCount = $("#exclude-checkboxes input:checkbox:checked").length;
if (($("#exclude-checkboxes").find("input:checkbox").filter(":checked").length == 3)){ if (checkedCount === 3) {
$("#exclude-checkboxes").find("input:checkbox").each(function () { $("#exclude-checkboxes input:checkbox").each(function () {
exclude_error = true;
this.click(); this.click();
}); });
if (exclude_error) { toast.error(
toast.error("All sources were excluded; exclusions have been reset.", "All sources were excluded; exclusions have been reset.",
{ style: { backgroundColor: "rgba(255, 0, 0, 0.5)", color: 'inherit' } }, { style: { backgroundColor: "rgba(255, 0, 0, 0.5)", color: "inherit" } }
); );
}
} }
}; };
return (
<div> const handleChange = (e) => {
<Checkbox const newChecked = e.target.checked;
id={opts.id} setChecked(newChecked);
key={opts.label} if (props.onToggle) {
checked={checked} const source = props.label; // Use label as source identifier
label={opts.label} props.onToggle(source);
style={{ color: "inherit" }} }
onChange={(e) => { verifyExclusions();
setChecked(e.target.checked); };
verifyExclusions();
}} return (
/> <div>
<Checkbox
id={props.id}
key={props.label}
checked={checked}
label={props.label}
style={{ color: "inherit" }}
onChange={handleChange}
/>
</div> </div>
); );
}); });