mirror of
https://github.com/ZHANGTIANYAO1/teamspeak-music-bot.git
synced 2026-10-02 13:02:49 +08:00
feat(web): per-platform source tabs on Home and Library
Recommend playlists, daily songs, and user playlists on Home now show a [网易云][QQ] tab when both platforms are logged in. Library 我的歌单 gets the same tab. Selection persists per-section in localStorage and falls back gracefully when the persisted source becomes unavailable (e.g., user logged out). Removes dead 我的收藏 block from Library that referenced a non-existent /api/music/user/liked endpoint. Spec: docs/superpowers/specs/2026-05-06-music-source-tabs-design.md Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
a216709227
commit
ac55a346be
4 files changed
+199
-61
No files matched your search
@@ -0,0 +1,36 @@
|
||||
import type { Source } from './player.js';
|
||||
|
||||
const STORAGE_KEY = 'source-tabs';
|
||||
|
||||
export type TabKey =
|
||||
| 'home.recommend'
|
||||
| 'home.daily'
|
||||
| 'home.user'
|
||||
| 'library.user';
|
||||
|
||||
function readAll(): Partial<Record<TabKey, Source>> {
|
||||
try {
|
||||
const raw = localStorage.getItem(STORAGE_KEY);
|
||||
if (!raw) return {};
|
||||
const parsed = JSON.parse(raw);
|
||||
return typeof parsed === 'object' && parsed !== null ? parsed : {};
|
||||
} catch {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
export function loadTabSource(key: TabKey, fallback: Source = 'netease'): Source {
|
||||
const all = readAll();
|
||||
const v = all[key];
|
||||
return v === 'netease' || v === 'qq' ? v : fallback;
|
||||
}
|
||||
|
||||
export function saveTabSource(key: TabKey, value: Source): void {
|
||||
try {
|
||||
const all = readAll();
|
||||
all[key] = value;
|
||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(all));
|
||||
} catch {
|
||||
// localStorage may be unavailable (private browsing); silently no-op
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user