mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-08 06:38:46 +00:00
Feature: add navidrome support
This commit is contained in:
parent
2ab05350a3
commit
210d746ef6
5 changed files with 68 additions and 0 deletions
45
src/widgets/navidrome/component.jsx
Normal file
45
src/widgets/navidrome/component.jsx
Normal file
|
@ -0,0 +1,45 @@
|
|||
import { useTranslation } from "next-i18next";
|
||||
|
||||
import Container from "components/services/widget/container";
|
||||
import Block from "components/services/widget/block";
|
||||
import useWidgetAPI from "utils/proxy/use-widget-api";
|
||||
|
||||
export default function Component({ service }) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const { widget } = service;
|
||||
|
||||
const { data: navidromeData, error: navidromeError } = useWidgetAPI(widget, "getNowPlaying");
|
||||
|
||||
if (navidromeError) {
|
||||
return <Container error={t("widget.api_error")} />;
|
||||
}
|
||||
|
||||
if (!navidromeData || Object.keys(navidromeData["subsonic-response"].nowPlaying).length === 0) {
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="navidrome.user" />
|
||||
<Block label="navidrome.artist" />
|
||||
<Block label="navidrome.song" />
|
||||
<Block label="navidrome.album" />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
const nowPlaying = Object.values(navidromeData["subsonic-response"].nowPlaying.entry);
|
||||
const songList = [];
|
||||
|
||||
nowPlaying.forEach(userPlay => {
|
||||
const playing = (
|
||||
<Container service={service}>
|
||||
<Block label="navidrome.user" value={userPlay.username} />
|
||||
<Block label="navidrome.artist" value={userPlay.artist} />
|
||||
<Block label="navidrome.song" value={userPlay.title} />
|
||||
<Block label="navidrome.album" value={userPlay.album} />
|
||||
</Container>
|
||||
);
|
||||
songList.unshift(playing);
|
||||
});
|
||||
|
||||
return songList;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue