fix: circular import causing navigate undefined; unified importer input
- Remove top-level ui.js import from soundcloud.js (broke views.js→soundcloud.js→ui.js→views.js cycle) - Use window.executeSpotifyDownload() instead to avoid the circular dep - Merge Spotify + SoundCloud into one unified URL input that auto-detects the service and colors the badge/button accordingly - resolveImporterLink() routes to the correct handler based on URL Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
ee65183555
commit
0e8eb311af
4 files changed
+84
-57
No files matched your search
+56
-12
@@ -5,27 +5,71 @@ import { itunesSearch } from './api.js';
|
||||
import { makeGlobalTrackItem } from './components.js';
|
||||
import { openDlModal } from './ui.js';
|
||||
|
||||
// ─── UNIFIED IMPORTER INPUT ───
|
||||
export function onImporterInput(val) {
|
||||
const badge = document.getElementById('importer-badge');
|
||||
const btn = document.getElementById('importer-btn');
|
||||
if (!badge || !btn) return;
|
||||
if (val.includes('spotify.com')) {
|
||||
badge.textContent = 'Spotify';
|
||||
badge.style.background = 'rgba(29,185,84,.15)';
|
||||
badge.style.color = '#1DB954';
|
||||
btn.style.background = '#1DB954';
|
||||
btn.style.color = '#000';
|
||||
btn.style.borderColor = 'transparent';
|
||||
} else if (val.includes('soundcloud.com')) {
|
||||
badge.textContent = 'SoundCloud';
|
||||
badge.style.background = 'rgba(255,85,0,.15)';
|
||||
badge.style.color = '#ff5500';
|
||||
btn.style.background = '#ff5500';
|
||||
btn.style.color = '#fff';
|
||||
btn.style.borderColor = 'transparent';
|
||||
} else {
|
||||
badge.textContent = 'URL';
|
||||
badge.style.background = '';
|
||||
badge.style.color = '';
|
||||
btn.style.background = '';
|
||||
btn.style.color = '';
|
||||
btn.style.borderColor = '';
|
||||
}
|
||||
// Hide results when input is cleared
|
||||
if (!val) {
|
||||
document.getElementById('spotify-preview').style.display = 'none';
|
||||
document.getElementById('sc-preview').style.display = 'none';
|
||||
document.getElementById('importer-hint').style.display = '';
|
||||
}
|
||||
}
|
||||
|
||||
export async function resolveImporterLink() {
|
||||
const url = document.getElementById('importer-link-input')?.value.trim();
|
||||
if (!url) return;
|
||||
// Mirror to the hidden inputs so existing resolve functions pick it up
|
||||
document.getElementById('spotify-link-input').value = url;
|
||||
document.getElementById('sc-link-input').value = url;
|
||||
document.getElementById('importer-hint').style.display = 'none';
|
||||
if (url.includes('soundcloud.com')) {
|
||||
window.resolveSoundCloudLink();
|
||||
} else {
|
||||
resolveSpotifyLink();
|
||||
}
|
||||
}
|
||||
|
||||
// ─── SPOTIFY IMPORTER PAGE ───
|
||||
export function loadSpotifyImporter() {
|
||||
if (!document.getElementById('spotify-link-input')?.value) {
|
||||
const hint = document.getElementById('spotify-importer-hint');
|
||||
const preview = document.getElementById('spotify-preview');
|
||||
if (hint) hint.style.display = '';
|
||||
if (preview) preview.style.display = 'none';
|
||||
const input = document.getElementById('importer-link-input');
|
||||
if (!input?.value) {
|
||||
document.getElementById('importer-hint').style.display = '';
|
||||
document.getElementById('spotify-preview').style.display = 'none';
|
||||
}
|
||||
}
|
||||
|
||||
export function clearSpotifyPreview() {
|
||||
if (!document.getElementById('spotify-link-input')?.value) {
|
||||
const hint = document.getElementById('spotify-importer-hint');
|
||||
const preview = document.getElementById('spotify-preview');
|
||||
if (hint) hint.style.display = '';
|
||||
if (preview) preview.style.display = 'none';
|
||||
}
|
||||
// no-op — handled by onImporterInput
|
||||
}
|
||||
|
||||
export async function resolveSpotifyLink() {
|
||||
const url = document.getElementById('spotify-link-input')?.value.trim();
|
||||
const url = document.getElementById('spotify-link-input')?.value.trim()
|
||||
|| document.getElementById('importer-link-input')?.value.trim();
|
||||
if (!url) return;
|
||||
if (!S.cfg.backendUrl) { toast('⚠ Backend URL in Einstellungen konfigurieren'); return; }
|
||||
|
||||
|
||||
Reference in new issue
Block a user