Remove ability to configure field order to match project code convention
This commit is contained in:
parent
82c56270c1
commit
d705ed0464
@ -2,61 +2,12 @@ import Container from "components/services/widget/container";
|
|||||||
import Block from "components/services/widget/block";
|
import Block from "components/services/widget/block";
|
||||||
import useWidgetAPI from "utils/proxy/use-widget-api";
|
import useWidgetAPI from "utils/proxy/use-widget-api";
|
||||||
|
|
||||||
function generateDefinitions(channelsData, statusData, tuner) {
|
|
||||||
return {
|
|
||||||
channels: {
|
|
||||||
label: "hdhomerun.channels",
|
|
||||||
value: channelsData?.length,
|
|
||||||
},
|
|
||||||
hd: {
|
|
||||||
label: "hdhomerun.hd",
|
|
||||||
value: channelsData?.filter((channel) => channel.HD === 1)?.length,
|
|
||||||
},
|
|
||||||
tunerCount: {
|
|
||||||
label: "hdhomerun.tunerCount",
|
|
||||||
value: `${statusData?.filter((num) => num.VctNumber != null).length ?? 0} / ${statusData?.length ?? 0}`,
|
|
||||||
},
|
|
||||||
channelNumber: {
|
|
||||||
label: "hdhomerun.channelNumber",
|
|
||||||
value: statusData[tuner]?.VctNumber ?? null,
|
|
||||||
},
|
|
||||||
channelNetwork: {
|
|
||||||
label: "hdhomerun.channelNetwork",
|
|
||||||
value: statusData[tuner]?.VctName ?? null,
|
|
||||||
},
|
|
||||||
signalStrength: {
|
|
||||||
label: "hdhomerun.signalStrength",
|
|
||||||
value: statusData[tuner]?.SignalStrengthPercent ?? null,
|
|
||||||
},
|
|
||||||
signalQuality: {
|
|
||||||
label: "hdhomerun.signalQuality",
|
|
||||||
value: statusData[tuner]?.SignalQualityPercent ?? null,
|
|
||||||
},
|
|
||||||
symbolQuality: {
|
|
||||||
label: "hdhomerun.symbolQuality",
|
|
||||||
value: statusData[tuner]?.SymbolQualityPercent ?? null,
|
|
||||||
},
|
|
||||||
clientIP: {
|
|
||||||
label: "hdhomerun.clientIP",
|
|
||||||
value: statusData[tuner]?.TargetIP ?? null,
|
|
||||||
},
|
|
||||||
networkRate: {
|
|
||||||
label: "hdhomerun.networkRate",
|
|
||||||
value: statusData[tuner]?.NetworkRate ?? null,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function Component({ service }) {
|
export default function Component({ service }) {
|
||||||
const { widget } = service;
|
const { widget } = service;
|
||||||
const { tuner = 0, refreshInterval = 10000, fields = ["channels", "hd"] } = widget;
|
const { tuner = 0 } = widget;
|
||||||
|
|
||||||
const { data: channelsData, error: channelsError } = useWidgetAPI(widget, "lineup", {
|
const { data: channelsData, error: channelsError } = useWidgetAPI(widget, "lineup");
|
||||||
refreshInterval: Math.max(1000, refreshInterval),
|
const { data: statusData, error: statusError } = useWidgetAPI(widget, "status");
|
||||||
});
|
|
||||||
const { data: statusData, error: statusError } = useWidgetAPI(widget, "status", {
|
|
||||||
refreshInterval: Math.max(1000, refreshInterval),
|
|
||||||
});
|
|
||||||
|
|
||||||
if (channelsError || statusError) {
|
if (channelsError || statusError) {
|
||||||
const finalError = channelsError ?? statusError;
|
const finalError = channelsError ?? statusError;
|
||||||
@ -72,17 +23,30 @@ export default function Component({ service }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const definitions = generateDefinitions(channelsData, statusData, tuner);
|
// Provide a default if not set in the config
|
||||||
|
if (!widget.fields) {
|
||||||
|
widget.fields = ["channels", "hd"];
|
||||||
|
}
|
||||||
|
// Limit to a maximum of 4 at a time
|
||||||
|
if (widget.fields.length > 4) {
|
||||||
|
widget.fields = widget.fields.slice(0, 4);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container service={service}>
|
<Container service={service}>
|
||||||
{fields.slice(0, 4).map((field) => (
|
<Block label="hdhomerun.channels" value={channelsData?.length} />
|
||||||
<Block
|
<Block label="hdhomerun.hd" value={channelsData?.filter((channel) => channel.HD === 1)?.length} />
|
||||||
key={field}
|
<Block
|
||||||
label={definitions[Object.keys(definitions).filter((id) => id === field)].label}
|
label="hdhomerun.tunerCount"
|
||||||
value={definitions[Object.keys(definitions).filter((id) => id === field)].value}
|
value={`${statusData?.filter((num) => num.VctNumber != null).length ?? 0} / ${statusData?.length ?? 0}`}
|
||||||
/>
|
/>
|
||||||
))}
|
<Block label="hdhomerun.channelNumber" value={statusData[tuner]?.VctNumber ?? null} />
|
||||||
|
<Block label="hdhomerun.channelNetwork" value={statusData[tuner]?.VctName ?? null} />
|
||||||
|
<Block label="hdhomerun.signalStrength" value={statusData[tuner]?.SignalStrengthPercent ?? null} />
|
||||||
|
<Block label="hdhomerun.signalQuality" value={statusData[tuner]?.SignalQualityPercent ?? null} />
|
||||||
|
<Block label="hdhomerun.symbolQuality" value={statusData[tuner]?.SymbolQualityPercent ?? null} />
|
||||||
|
<Block label="hdhomerun.clientIP" value={statusData[tuner]?.TargetIP ?? null} />
|
||||||
|
<Block label="hdhomerun.networkRate" value={statusData[tuner]?.NetworkRate ?? null} />
|
||||||
</Container>
|
</Container>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user