.dropdown region songlink
This commit is contained in:
@@ -11,6 +11,7 @@ import { SearchSpotify, SearchSpotifyByType } from "../../wailsjs/go/main/App";
|
|||||||
import { backend } from "../../wailsjs/go/models";
|
import { backend } from "../../wailsjs/go/models";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { useTypingEffect } from "@/hooks/useTypingEffect";
|
import { useTypingEffect } from "@/hooks/useTypingEffect";
|
||||||
|
import { getSettings, type Settings } from "@/lib/settings";
|
||||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select";
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select";
|
||||||
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog";
|
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog";
|
||||||
const FETCH_PLACEHOLDERS = [
|
const FETCH_PLACEHOLDERS = [
|
||||||
@@ -245,6 +246,7 @@ interface SearchBarProps {
|
|||||||
export function SearchBar({ url, loading, onUrlChange, onFetch, onFetchUrl, history, onHistorySelect, onHistoryRemove, hasResult, searchMode, onSearchModeChange, region, onRegionChange, }: SearchBarProps) {
|
export function SearchBar({ url, loading, onUrlChange, onFetch, onFetchUrl, history, onHistorySelect, onHistoryRemove, hasResult, searchMode, onSearchModeChange, region, onRegionChange, }: SearchBarProps) {
|
||||||
const [searchQuery, setSearchQuery] = useState("");
|
const [searchQuery, setSearchQuery] = useState("");
|
||||||
const [searchResults, setSearchResults] = useState<backend.SearchResponse | null>(null);
|
const [searchResults, setSearchResults] = useState<backend.SearchResponse | null>(null);
|
||||||
|
const [showRegionSelector, setShowRegionSelector] = useState(() => getSettings().linkResolver === "songlink");
|
||||||
const [resultFilter, setResultFilter] = useState("");
|
const [resultFilter, setResultFilter] = useState("");
|
||||||
const [sortOrders, setSortOrders] = useState<Record<ResultTab, string>>({
|
const [sortOrders, setSortOrders] = useState<Record<ResultTab, string>>({
|
||||||
tracks: "default",
|
tracks: "default",
|
||||||
@@ -279,6 +281,18 @@ export function SearchBar({ url, loading, onUrlChange, onFetch, onFetchUrl, hist
|
|||||||
console.error("Failed to load recent searches:", error);
|
console.error("Failed to load recent searches:", error);
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
useEffect(() => {
|
||||||
|
const syncRegionVisibility = (settings?: Partial<Settings>) => {
|
||||||
|
const resolver = settings?.linkResolver ?? getSettings().linkResolver;
|
||||||
|
setShowRegionSelector(resolver === "songlink");
|
||||||
|
};
|
||||||
|
syncRegionVisibility();
|
||||||
|
const handleSettingsUpdate = (event: Event) => {
|
||||||
|
syncRegionVisibility((event as CustomEvent<Partial<Settings>>).detail);
|
||||||
|
};
|
||||||
|
window.addEventListener("settingsUpdated", handleSettingsUpdate);
|
||||||
|
return () => window.removeEventListener("settingsUpdated", handleSettingsUpdate);
|
||||||
|
}, []);
|
||||||
const saveRecentSearch = (query: string) => {
|
const saveRecentSearch = (query: string) => {
|
||||||
const trimmed = query.trim();
|
const trimmed = query.trim();
|
||||||
if (!trimmed)
|
if (!trimmed)
|
||||||
@@ -589,7 +603,7 @@ export function SearchBar({ url, loading, onUrlChange, onFetch, onFetchUrl, hist
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{!searchMode && (<>
|
{!searchMode && (<>
|
||||||
<Select value={region} onValueChange={onRegionChange}>
|
{showRegionSelector && (<Select value={region} onValueChange={onRegionChange}>
|
||||||
<SelectTrigger className="w-[70px] shrink-0">
|
<SelectTrigger className="w-[70px] shrink-0">
|
||||||
<SelectValue placeholder="Region"/>
|
<SelectValue placeholder="Region"/>
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
@@ -601,7 +615,7 @@ export function SearchBar({ url, loading, onUrlChange, onFetch, onFetchUrl, hist
|
|||||||
</span>
|
</span>
|
||||||
</SelectItem>))}
|
</SelectItem>))}
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>)}
|
||||||
<Button onClick={handleFetchWithValidation} disabled={loading}>
|
<Button onClick={handleFetchWithValidation} disabled={loading}>
|
||||||
{loading ? (<>
|
{loading ? (<>
|
||||||
<Spinner />
|
<Spinner />
|
||||||
|
|||||||
Reference in New Issue
Block a user