fix(media widget): text size fix and added season + Episode info (#6605)

Co-authored-by: Thomas <thomas@ajnart.fr>
This commit is contained in:
BergashaandThomas authored and GitHub committed 2026-08-18 09:44:12 +02:00
1 parent e842177d9b
commit ebdfeb724b
61 files changed
+254 -182

No files matched your search

@@ -23,8 +23,10 @@
.tableViewport :global(th),
.tableViewport :global(td) {
padding-block: 4px;
padding-block: 8px;
padding-inline: 8px;
overflow: hidden;
vertical-align: top;
}
.tableViewport :global(th) {
@@ -41,7 +43,6 @@
.cellContent {
min-width: 0;
overflow: hidden;
}
.userIdentity {
@@ -9,7 +9,7 @@ import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
import type { StreamSession } from "@homarr/integrations";
import { getMediaServerColumnVisibility, SessionDetailsPopover } from "./component";
import { getMediaServerColumnVisibility, getSeasonEpisodeParams, SessionDetailsPopover } from "./component";
vi.mock("@homarr/translation/client", () => ({
useScopedI18n: () => (key: string) => key,
@@ -108,3 +108,19 @@ describe("getMediaServerColumnVisibility", () => {
expect(getMediaServerColumnVisibility(0, true)).toEqual({ user: true, status: true });
});
});
describe("getSeasonEpisodeParams", () => {
test("zero-pads season and episode numbers", () => {
expect(getSeasonEpisodeParams(4, 12)).toEqual({ season: "04", episode: "12" });
});
test("does not pad numbers already two digits or longer", () => {
expect(getSeasonEpisodeParams(12, 104)).toEqual({ season: "12", episode: "104" });
});
test("returns null when either number is missing", () => {
expect(getSeasonEpisodeParams(undefined, 12)).toBeNull();
expect(getSeasonEpisodeParams(4, null)).toBeNull();
expect(getSeasonEpisodeParams(null, undefined)).toBeNull();
});
});
+40 -14
View File
@@ -77,6 +77,16 @@ function formatBitrate(bitrateKbps: number | null | undefined): string | null {
return bitrateKbps >= 1000 ? `${(bitrateKbps / 1000).toFixed(1)} Mbps` : `${Math.round(bitrateKbps)} kbps`;
}
export function getSeasonEpisodeParams(
seasonNumber: number | null | undefined,
episodeNumber: number | null | undefined,
): { season: string; episode: string } | null {
if (seasonNumber === null || seasonNumber === undefined || episodeNumber === null || episodeNumber === undefined) {
return null;
}
return { season: String(seasonNumber).padStart(2, "0"), episode: String(episodeNumber).padStart(2, "0") };
}
const getSessionSortValue = (session: StreamSession, column: SortColumn) => {
if (column === "user") return session.user?.username ?? session.sessionName;
if (column === "currentlyPlaying") return session.currentlyPlaying?.name ?? session.sessionName;
@@ -124,7 +134,7 @@ function StreamTableHeader({
<Text component="span" size="xs" fw={600} truncate>
{label}
</Text>
<SortIcon size={13} aria-hidden />
<SortIcon size="var(--mantine-font-size-xs)" aria-hidden />
</UnstyledButton>
) : (
<Text size="xs" fw={600} truncate>
@@ -225,7 +235,7 @@ export default function MediaServerWidget({
onChange={(event) => setSearch(event.currentTarget.value)}
placeholder={tGlobal("search.placeholder")}
aria-label={tGlobal("search.placeholder")}
leftSection={<IconSearch size={14} aria-hidden />}
leftSection={<IconSearch size="var(--mantine-font-size-xs)" aria-hidden />}
/>
<WidgetQueryErrorIndicator error={currentStreamsQuery.error} label={t("name")} />
<IntegrationErrorIndicator results={currentStreams} />
@@ -304,13 +314,13 @@ export default function MediaServerWidget({
>
{columnVisibility.user && (
<Table.Td>
<Group gap="xs" wrap="nowrap" style={{ minWidth: 0 }}>
<Avatar size={28} src={session.user?.profilePictureUrl} style={{ flexShrink: 0 }} />
<div className={classes.userIdentity}>
<Text component="div" size="xs" truncate className={classes.userIdentityLine}>
<Group gap="xs" wrap="nowrap" w="100%">
<Avatar size={28} src={session.user?.profilePictureUrl} />
<Stack gap={2} className={classes.cellContent}>
<Text size="xs" truncate>
{session.user?.username ?? t("items.unknownUser")}
</Text>
<Text component="div" size="10px" c="dimmed" truncate className={classes.userIdentityLine}>
<Text size="xs" c="dimmed" truncate>
{session.sessionName}
</Text>
</div>
@@ -329,22 +339,27 @@ export default function MediaServerWidget({
{columnVisibility.status && (
<Table.Td>
{currentlyPlaying && (
<Stack gap={4} align="flex-start" className={classes.cellContent}>
<Stack gap={4} align="flex-start" w="100%" className={classes.cellContent}>
<Badge size="xs" variant="light" color={playbackStatusColorMap[status]}>
{t(`items.${status}` as never)}
</Badge>
{(location ?? bitrateLabel) && (
<Group gap={4} align="center" justify="space-between" wrap="nowrap" w="100%">
<Group gap={4} align="center" wrap="nowrap">
{location && (location === "lan" ? <IconWifi size={12} /> : <IconWorld size={12} />)}
{location &&
(location === "lan" ? (
<IconWifi size="var(--mantine-font-size-xs)" />
) : (
<IconWorld size="var(--mantine-font-size-xs)" />
))}
{location && (
<Text size="10px" c="dimmed" tt="uppercase">
<Text size="xs" c="dimmed" tt="uppercase">
{location}
</Text>
)}
</Group>
{bitrateLabel && (
<Text size="10px" c="dimmed" style={{ whiteSpace: "nowrap" }}>
<Text size="xs" c="dimmed" style={{ whiteSpace: "nowrap" }}>
{bitrateLabel}
</Text>
)}
@@ -372,7 +387,7 @@ export default function MediaServerWidget({
}}
>
<Group gap={4} wrap="nowrap">
<IconVideo size={16} style={{ flexShrink: 0 }} />
<IconVideo size="var(--mantine-font-size-xs)" style={{ flexShrink: 0 }} />
<Text size="sm" style={{ whiteSpace: "nowrap" }}>
{(t as unknown as (key: string, params?: { count: number }) => string)("footer.streams", {
count: flatSessions.length,
@@ -424,14 +439,25 @@ function CurrentlyPlaying({ item }: { item: StreamSession }) {
: null;
const remainingMinutes =
positionMs !== null && durationMs !== null ? Math.max(0, Math.round((durationMs - positionMs) / 60_000)) : null;
const seasonEpisodeParams = getSeasonEpisodeParams(currentlyPlaying.seasonNumber, currentlyPlaying.episodeNumber);
const seasonEpisodeLabel = seasonEpisodeParams ? t("items.seasonEpisode", seasonEpisodeParams) : null;
return (
<Stack gap={4} style={{ minWidth: 0 }}>
<Stack gap={6} style={{ minWidth: 0 }}>
<Group gap="xs" align="center" wrap="nowrap" style={{ minWidth: 0 }}>
<Icon size={16} color={isPaused ? "var(--mantine-color-yellow-6)" : undefined} style={{ flexShrink: 0 }} />
<Icon
size="var(--mantine-font-size-xs)"
color={isPaused ? "var(--mantine-color-yellow-6)" : undefined}
style={{ flexShrink: 0 }}
/>
<Text size="xs" lineClamp={1} style={{ minWidth: 0 }}>
{currentlyPlaying.name}
</Text>
{seasonEpisodeLabel && (
<Text size="xs" c="dimmed" style={{ flexShrink: 0 }}>
{seasonEpisodeLabel}
</Text>
)}
{isPaused ? (
<Text size="xs" c="yellow" style={{ flexShrink: 0 }}>
{t("items.paused")}