feat: add standalone Last.fm integration and settings management
- Implemented standalone Last.fm integration in the settings page. - Added functionality to manage Last.fm credentials, including API key and secret. - Introduced sidebar settings for toggling between expanded and collapsed views. - Enhanced the Navidrome API with new methods for fetching starred items and album songs. - Created a new Favorites page to display starred albums, songs, and artists with play and toggle favorite options. - Added a Badge component for UI consistency across the application.
This commit is contained in:
@@ -8,6 +8,7 @@ import { FaPlay, FaPause, FaVolumeHigh, FaForward, FaBackward, FaCompress, FaVol
|
||||
import { Progress } from '@/components/ui/progress';
|
||||
import { useToast } from '@/hooks/use-toast';
|
||||
import { useLastFmScrobbler } from '@/hooks/use-lastfm-scrobbler';
|
||||
import { useStandaloneLastFm } from '@/hooks/use-standalone-lastfm';
|
||||
|
||||
export const AudioPlayer: React.FC = () => {
|
||||
const { currentTrack, playPreviousTrack, addToQueue, playNextTrack, clearQueue, queue, toggleShuffle, shuffle } = useAudioPlayer();
|
||||
@@ -24,14 +25,49 @@ export const AudioPlayer: React.FC = () => {
|
||||
const audioCurrent = audioRef.current;
|
||||
const { toast } = useToast();
|
||||
|
||||
// Last.fm scrobbler integration
|
||||
// Last.fm scrobbler integration (Navidrome)
|
||||
const {
|
||||
onTrackStart,
|
||||
onTrackPlay,
|
||||
onTrackPause,
|
||||
onTrackProgress,
|
||||
onTrackEnd,
|
||||
onTrackStart: navidromeOnTrackStart,
|
||||
onTrackPlay: navidromeOnTrackPlay,
|
||||
onTrackPause: navidromeOnTrackPause,
|
||||
onTrackProgress: navidromeOnTrackProgress,
|
||||
onTrackEnd: navidromeOnTrackEnd,
|
||||
} = useLastFmScrobbler();
|
||||
|
||||
// Standalone Last.fm integration
|
||||
const {
|
||||
onTrackStart: standaloneOnTrackStart,
|
||||
onTrackPlay: standaloneOnTrackPlay,
|
||||
onTrackPause: standaloneOnTrackPause,
|
||||
onTrackProgress: standaloneOnTrackProgress,
|
||||
onTrackEnd: standaloneOnTrackEnd,
|
||||
} = useStandaloneLastFm();
|
||||
|
||||
// Combined Last.fm handlers
|
||||
const onTrackStart = (track: any) => {
|
||||
navidromeOnTrackStart(track);
|
||||
standaloneOnTrackStart(track);
|
||||
};
|
||||
|
||||
const onTrackPlay = (track: any) => {
|
||||
navidromeOnTrackPlay(track);
|
||||
standaloneOnTrackPlay(track);
|
||||
};
|
||||
|
||||
const onTrackPause = (currentTime: number) => {
|
||||
navidromeOnTrackPause(currentTime);
|
||||
standaloneOnTrackPause(currentTime);
|
||||
};
|
||||
|
||||
const onTrackProgress = (track: any, currentTime: number, duration: number) => {
|
||||
navidromeOnTrackProgress(track, currentTime, duration);
|
||||
standaloneOnTrackProgress(track, currentTime, duration);
|
||||
};
|
||||
|
||||
const onTrackEnd = (track: any, currentTime: number, duration: number) => {
|
||||
navidromeOnTrackEnd(track, currentTime, duration);
|
||||
standaloneOnTrackEnd(track, currentTime, duration);
|
||||
};
|
||||
|
||||
const handleOpenQueue = () => {
|
||||
setIsFullScreen(false);
|
||||
|
||||
@@ -4,6 +4,9 @@ import { getNavidromeAPI, Album, Artist, Song, Playlist, AlbumInfo, ArtistInfo }
|
||||
import { useCallback } from 'react';
|
||||
|
||||
interface NavidromeContextType {
|
||||
// API instance
|
||||
api: ReturnType<typeof getNavidromeAPI>;
|
||||
|
||||
// Data
|
||||
albums: Album[];
|
||||
artists: Artist[];
|
||||
@@ -387,6 +390,9 @@ export const NavidromeProvider: React.FC<NavidromeProviderProps> = ({ children }
|
||||
}, [api, refreshData]);
|
||||
|
||||
const value: NavidromeContextType = {
|
||||
// API instance
|
||||
api,
|
||||
|
||||
// Data
|
||||
albums,
|
||||
artists,
|
||||
|
||||
@@ -15,8 +15,22 @@ const Ihateserverside: React.FC<IhateserversideProps> = ({ children }) => {
|
||||
const [isSidebarVisible, setIsSidebarVisible] = useState(true);
|
||||
const [isStatusBarVisible, setIsStatusBarVisible] = useState(true);
|
||||
const [isSidebarHidden, setIsSidebarHidden] = useState(false);
|
||||
const [isSidebarCollapsed, setIsSidebarCollapsed] = useState(() => {
|
||||
if (typeof window !== 'undefined') {
|
||||
return localStorage.getItem('sidebar-collapsed') === 'true';
|
||||
}
|
||||
return false;
|
||||
});
|
||||
const { playlists } = useNavidrome();
|
||||
|
||||
const toggleSidebarCollapse = () => {
|
||||
const newCollapsed = !isSidebarCollapsed;
|
||||
setIsSidebarCollapsed(newCollapsed);
|
||||
if (typeof window !== 'undefined') {
|
||||
localStorage.setItem('sidebar-collapsed', newCollapsed.toString());
|
||||
}
|
||||
};
|
||||
|
||||
const handleTransitionEnd = () => {
|
||||
if (!isSidebarVisible) {
|
||||
setIsSidebarHidden(true); // This will fully hide the sidebar after transition
|
||||
@@ -43,10 +57,12 @@ const Ihateserverside: React.FC<IhateserversideProps> = ({ children }) => {
|
||||
{/* Main Content Area */}
|
||||
<div className="flex-1 flex overflow-hidden">
|
||||
{isSidebarVisible && (
|
||||
<div className="w-64 flex-shrink-0 border-r">
|
||||
<div className={`${isSidebarCollapsed ? 'w-16' : 'w-64'} flex-shrink-0 border-r transition-all duration-200`}>
|
||||
<Sidebar
|
||||
playlists={playlists}
|
||||
className="h-full overflow-y-auto"
|
||||
collapsed={isSidebarCollapsed}
|
||||
onToggle={toggleSidebarCollapse}
|
||||
onTransitionEnd={handleTransitionEnd}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -7,12 +7,15 @@ import { Button } from "../../components/ui/button";
|
||||
import { ScrollArea } from "../../components/ui/scroll-area";
|
||||
import Link from "next/link";
|
||||
import { Playlist } from "@/lib/navidrome";
|
||||
import { ChevronLeft, ChevronRight } from "lucide-react";
|
||||
|
||||
interface SidebarProps extends React.HTMLAttributes<HTMLDivElement> {
|
||||
playlists: Playlist[];
|
||||
collapsed?: boolean;
|
||||
onToggle?: () => void;
|
||||
}
|
||||
|
||||
export function Sidebar({ className, playlists }: SidebarProps) {
|
||||
export function Sidebar({ className, playlists, collapsed = false, onToggle }: SidebarProps) {
|
||||
const isRoot = usePathname() === "/";
|
||||
const isBrowse = usePathname() === "/browse";
|
||||
const isSearch = usePathname() === "/search";
|
||||
@@ -21,18 +24,35 @@ export function Sidebar({ className, playlists }: SidebarProps) {
|
||||
const isQueue = usePathname() === "/queue";
|
||||
const isRadio = usePathname() === "/radio";
|
||||
const isHistory = usePathname() === "/history";
|
||||
const isSongs = usePathname() === "/library/songs"; const isPlaylists = usePathname() === "/library/playlists";
|
||||
const isSongs = usePathname() === "/library/songs";
|
||||
const isPlaylists = usePathname() === "/library/playlists";
|
||||
const isFavorites = usePathname() === "/favorites";
|
||||
const isNew = usePathname() === "/new";
|
||||
|
||||
return (
|
||||
<div className={cn("pb-6", className)}>
|
||||
<div className={cn("pb-6 relative", className)}>
|
||||
{/* Collapse/Expand Button */}
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={onToggle}
|
||||
className="absolute top-2 right-2 z-10 h-6 w-6 p-0"
|
||||
>
|
||||
{collapsed ? <ChevronRight className="h-4 w-4" /> : <ChevronLeft className="h-4 w-4" />}
|
||||
</Button>
|
||||
|
||||
<div className="space-y-4 py-4">
|
||||
<div className="px-3 py-2">
|
||||
<p className="mb-2 px-4 text-lg font-semibold tracking-tight">
|
||||
<p className={cn("mb-2 px-4 text-lg font-semibold tracking-tight", collapsed && "sr-only")}>
|
||||
Discover
|
||||
</p>
|
||||
<div className="space-y-1">
|
||||
<Link href="/">
|
||||
<Button variant={isRoot ? "secondary" : "ghost"} className="w-full justify-start mb-2">
|
||||
<Button
|
||||
variant={isRoot ? "secondary" : "ghost"}
|
||||
className={cn("w-full justify-start mb-2", collapsed && "justify-center px-2")}
|
||||
title={collapsed ? "Listen Now" : undefined}
|
||||
>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 24 24"
|
||||
@@ -41,16 +61,20 @@ export function Sidebar({ className, playlists }: SidebarProps) {
|
||||
strokeWidth="2"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
className="mr-2 h-4 w-4"
|
||||
className={cn("h-4 w-4", !collapsed && "mr-2")}
|
||||
>
|
||||
<circle cx="12" cy="12" r="10" />
|
||||
<polygon points="10 8 16 12 10 16 10 8" />
|
||||
</svg>
|
||||
Listen Now
|
||||
{!collapsed && "Listen Now"}
|
||||
</Button>
|
||||
</Link>
|
||||
<Link href="/browse">
|
||||
<Button variant={isBrowse ? "secondary" : "ghost"} className="w-full justify-start mb-2">
|
||||
<Button
|
||||
variant={isBrowse ? "secondary" : "ghost"}
|
||||
className={cn("w-full justify-start mb-2", collapsed && "justify-center px-2")}
|
||||
title={collapsed ? "Browse" : undefined}
|
||||
>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 24 24"
|
||||
@@ -59,18 +83,22 @@ export function Sidebar({ className, playlists }: SidebarProps) {
|
||||
strokeWidth="2"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
className="mr-2 h-4 w-4"
|
||||
className={cn("h-4 w-4", !collapsed && "mr-2")}
|
||||
>
|
||||
<rect width="7" height="7" x="3" y="3" rx="1" />
|
||||
<rect width="7" height="7" x="14" y="3" rx="1" />
|
||||
<rect width="7" height="7" x="14" y="14" rx="1" />
|
||||
<rect width="7" height="7" x="3" y="14" rx="1" />
|
||||
</svg>
|
||||
Browse
|
||||
{!collapsed && "Browse"}
|
||||
</Button>
|
||||
</Link>
|
||||
<Link href="/search">
|
||||
<Button variant={isSearch ? "secondary" : "ghost"} className="w-full justify-start mb-2">
|
||||
<Button
|
||||
variant={isSearch ? "secondary" : "ghost"}
|
||||
className={cn("w-full justify-start mb-2", collapsed && "justify-center px-2")}
|
||||
title={collapsed ? "Search" : undefined}
|
||||
>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 24 24"
|
||||
@@ -79,16 +107,20 @@ export function Sidebar({ className, playlists }: SidebarProps) {
|
||||
strokeWidth="2"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
className="mr-2 h-4 w-4"
|
||||
className={cn("h-4 w-4", !collapsed && "mr-2")}
|
||||
>
|
||||
<circle cx="11" cy="11" r="8" />
|
||||
<path d="m21 21-4.35-4.35" />
|
||||
</svg>
|
||||
Search
|
||||
{!collapsed && "Search"}
|
||||
</Button>
|
||||
</Link>
|
||||
<Link href="/queue">
|
||||
<Button variant={isQueue ? "secondary" : "ghost"} className="w-full justify-start mb-2">
|
||||
<Button
|
||||
variant={isQueue ? "secondary" : "ghost"}
|
||||
className={cn("w-full justify-start mb-2", collapsed && "justify-center px-2")}
|
||||
title={collapsed ? "Queue" : undefined}
|
||||
>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 24 24"
|
||||
@@ -97,15 +129,19 @@ export function Sidebar({ className, playlists }: SidebarProps) {
|
||||
strokeWidth="2"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
className="mr-2 h-4 w-4"
|
||||
className={cn("h-4 w-4", !collapsed && "mr-2")}
|
||||
>
|
||||
<path d="M3 6h18M3 12h18M3 18h18" />
|
||||
</svg>
|
||||
Queue
|
||||
{!collapsed && "Queue"}
|
||||
</Button>
|
||||
</Link>
|
||||
<Link href="/radio">
|
||||
<Button variant={isRadio ? "secondary" : "ghost"} className="w-full justify-start mb-2">
|
||||
<Button
|
||||
variant={isRadio ? "secondary" : "ghost"}
|
||||
className={cn("w-full justify-start mb-2", collapsed && "justify-center px-2")}
|
||||
title={collapsed ? "Radio" : undefined}
|
||||
>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 24 24"
|
||||
@@ -114,7 +150,7 @@ export function Sidebar({ className, playlists }: SidebarProps) {
|
||||
strokeWidth="2"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
className="mr-2 h-4 w-4"
|
||||
className={cn("h-4 w-4", !collapsed && "mr-2")}
|
||||
>
|
||||
<path d="M4.9 19.1C1 15.2 1 8.8 4.9 4.9"/>
|
||||
<path d="M7.8 16.2c-2.3-2.3-2.3-6.1 0-8.5"/>
|
||||
@@ -122,19 +158,23 @@ export function Sidebar({ className, playlists }: SidebarProps) {
|
||||
<path d="M16.2 7.8c2.3 2.3 2.3 6.1 0 8.5"/>
|
||||
<path d="M19.1 4.9C23 8.8 23 15.2 19.1 19.1"/>
|
||||
</svg>
|
||||
Radio
|
||||
{!collapsed && "Radio"}
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<div className="px-3 py-2">
|
||||
<p className="mb-2 px-4 text-lg font-semibold tracking-tight">
|
||||
<p className={cn("mb-2 px-4 text-lg font-semibold tracking-tight", collapsed && "sr-only")}>
|
||||
Library
|
||||
</p>
|
||||
<div className="space-y-1">
|
||||
<Link href="/library/playlists">
|
||||
<Button variant={isPlaylists ? "secondary" : "ghost"} className="w-full justify-start mb-1">
|
||||
<Button
|
||||
variant={isPlaylists ? "secondary" : "ghost"}
|
||||
className={cn("w-full justify-start mb-1", collapsed && "justify-center px-2")}
|
||||
title={collapsed ? "Playlists" : undefined}
|
||||
>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 24 24"
|
||||
@@ -143,7 +183,7 @@ export function Sidebar({ className, playlists }: SidebarProps) {
|
||||
strokeWidth="2"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
className="mr-2 h-4 w-4"
|
||||
className={cn("h-4 w-4", !collapsed && "mr-2")}
|
||||
>
|
||||
<path d="M21 15V6" />
|
||||
<path d="M18.5 18a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5Z" />
|
||||
@@ -151,29 +191,59 @@ export function Sidebar({ className, playlists }: SidebarProps) {
|
||||
<path d="M16 6H3" />
|
||||
<path d="M12 18H3" />
|
||||
</svg>
|
||||
Playlists
|
||||
{!collapsed && "Playlists"}
|
||||
</Button>
|
||||
</Link>
|
||||
<Link href="/library/songs">
|
||||
<Button variant={isSongs ? "secondary" : "ghost"} className="w-full justify-start mb-2">
|
||||
<svg className="mr-2 h-4 w-4" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
|
||||
<Button
|
||||
variant={isSongs ? "secondary" : "ghost"}
|
||||
className={cn("w-full justify-start mb-2", collapsed && "justify-center px-2")}
|
||||
title={collapsed ? "Songs" : undefined}
|
||||
>
|
||||
<svg
|
||||
className={cn("h-4 w-4", !collapsed && "mr-2")}
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<circle cx="8" cy="18" r="4" />
|
||||
<path d="M12 18V2l7 4" />
|
||||
</svg>
|
||||
Songs
|
||||
{!collapsed && "Songs"}
|
||||
</Button>
|
||||
</Link>
|
||||
<Link href="/library/artists">
|
||||
<Button variant={isArtists ? "secondary" : "ghost"} className="w-full justify-start mb-2">
|
||||
<svg className="mr-2 h-4 w-4" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" >
|
||||
<Button
|
||||
variant={isArtists ? "secondary" : "ghost"}
|
||||
className={cn("w-full justify-start mb-2", collapsed && "justify-center px-2")}
|
||||
title={collapsed ? "Artists" : undefined}
|
||||
>
|
||||
<svg
|
||||
className={cn("h-4 w-4", !collapsed && "mr-2")}
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<path d="m12 8-9.04 9.06a2.82 2.82 0 1 0 3.98 3.98L16 12" />
|
||||
<circle cx="17" cy="7" r="5" />
|
||||
</svg>
|
||||
Artists
|
||||
{!collapsed && "Artists"}
|
||||
</Button>
|
||||
</Link>
|
||||
<Link href="/library/albums">
|
||||
<Button variant={isAlbums ? "secondary" : "ghost"} className="w-full justify-start mb-2">
|
||||
<Button
|
||||
variant={isAlbums ? "secondary" : "ghost"}
|
||||
className={cn("w-full justify-start mb-2", collapsed && "justify-center px-2")}
|
||||
title={collapsed ? "Albums" : undefined}
|
||||
>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 24 24"
|
||||
@@ -182,18 +252,22 @@ export function Sidebar({ className, playlists }: SidebarProps) {
|
||||
strokeWidth="2"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
className="mr-2 h-4 w-4"
|
||||
className={cn("h-4 w-4", !collapsed && "mr-2")}
|
||||
>
|
||||
<path d="m16 6 4 14" />
|
||||
<path d="M12 6v14" />
|
||||
<path d="M8 8v12" />
|
||||
<path d="M4 4v16" />
|
||||
</svg>
|
||||
Albums
|
||||
{!collapsed && "Albums"}
|
||||
</Button>
|
||||
</Link>
|
||||
<Link href="/history">
|
||||
<Button variant={isHistory ? "secondary" : "ghost"} className="w-full justify-start mb-2">
|
||||
<Button
|
||||
variant={isHistory ? "secondary" : "ghost"}
|
||||
className={cn("w-full justify-start mb-2", collapsed && "justify-center px-2")}
|
||||
title={collapsed ? "History" : undefined}
|
||||
>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 24 24"
|
||||
@@ -202,12 +276,33 @@ export function Sidebar({ className, playlists }: SidebarProps) {
|
||||
strokeWidth="2"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
className="mr-2 h-4 w-4"
|
||||
className={cn("h-4 w-4", !collapsed && "mr-2")}
|
||||
>
|
||||
<path d="M12 2C6.48 2 2 6.48 2 12c0 5.52 4.48 10 10 10 5.52 0 10-4.48 10-10 0-5.52-4.48-10-10-10Z" />
|
||||
<path d="M12 8v4l4 2" />
|
||||
</svg>
|
||||
History
|
||||
{!collapsed && "History"}
|
||||
</Button>
|
||||
</Link>
|
||||
<Link href="/favorites">
|
||||
<Button
|
||||
variant={isFavorites ? "secondary" : "ghost"}
|
||||
className={cn("w-full justify-start mb-2", collapsed && "justify-center px-2")}
|
||||
title={collapsed ? "Favorites" : undefined}
|
||||
>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
className={cn("h-4 w-4", !collapsed && "mr-2")}
|
||||
>
|
||||
<path d="M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 0 0 0-7.78z" />
|
||||
</svg>
|
||||
{!collapsed && "Favorites"}
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user