mirror of
https://github.com/gethomepage/homepage.git
synced 2026-09-24 21:15:46 -07:00
Enhancement: Add album count to Jellyfin widget (#6974)
Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
This commit is contained in:
@@ -132,7 +132,8 @@
|
||||
"movies": "Movies",
|
||||
"series": "Series",
|
||||
"episodes": "Episodes",
|
||||
"songs": "Songs"
|
||||
"songs": "Songs",
|
||||
"albums": "Albums"
|
||||
},
|
||||
"esphome": {
|
||||
"offline": "Offline",
|
||||
|
||||
@@ -176,6 +176,13 @@ function SessionEntry({ playCommand, session, enableUser, showEpisodeNumber, ena
|
||||
|
||||
function CountBlocks({ service, countData }) {
|
||||
const { t } = useTranslation();
|
||||
const { widget } = service;
|
||||
|
||||
if (!widget.fields || widget.fields.length === 0) {
|
||||
widget.fields = ["movies", "series", "episodes", "songs"];
|
||||
} else if (widget.fields?.length > 4) {
|
||||
widget.fields = widget.fields.slice(0, 4);
|
||||
}
|
||||
|
||||
if (!countData) {
|
||||
return (
|
||||
@@ -184,6 +191,7 @@ function CountBlocks({ service, countData }) {
|
||||
<Block label="jellyfin.series" />
|
||||
<Block label="jellyfin.episodes" />
|
||||
<Block label="jellyfin.songs" />
|
||||
<Block label="jellyfin.albums" />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
@@ -194,6 +202,7 @@ function CountBlocks({ service, countData }) {
|
||||
<Block label="jellyfin.series" value={t("common.number", { value: countData.SeriesCount })} />
|
||||
<Block label="jellyfin.episodes" value={t("common.number", { value: countData.EpisodeCount })} />
|
||||
<Block label="jellyfin.songs" value={t("common.number", { value: countData.SongCount })} />
|
||||
<Block label="jellyfin.albums" value={t("common.number", { value: countData.AlbumCount })} />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ describe("widgets/jellyfin/component", () => {
|
||||
useWidgetAPI
|
||||
.mockReturnValueOnce({ data: [], error: undefined, mutate: vi.fn() }) // sessions
|
||||
.mockReturnValueOnce({
|
||||
data: { MovieCount: 1, SeriesCount: 2, EpisodeCount: 3, SongCount: 4 },
|
||||
data: { MovieCount: 1, SeriesCount: 2, EpisodeCount: 3, SongCount: 4, AlbumCount: 5 },
|
||||
error: undefined,
|
||||
}); // count
|
||||
|
||||
@@ -89,4 +89,21 @@ describe("widgets/jellyfin/component", () => {
|
||||
expect(screen.getByText(/00:00/)).toBeInTheDocument();
|
||||
expect(screen.getByText(/01:00/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders optional albums field when included", () => {
|
||||
useWidgetAPI
|
||||
.mockReturnValueOnce({ data: [], error: undefined, mutate: vi.fn() }) // sessions
|
||||
.mockImplementation(() => ({
|
||||
data: { MovieCount: 1, SeriesCount: 2, EpisodeCount: 3, SongCount: 4, AlbumCount: 5 },
|
||||
error: undefined,
|
||||
}));
|
||||
|
||||
renderWithProviders(
|
||||
<Component
|
||||
service={{
|
||||
widget: { type: "jellyfin", url: "http://x", fields: ["movies", "series", "episodes", "albums"] },
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user