Refactor ChannelsTable row styling logic to use memoized class mapping for improved performance and readability.

This commit is contained in:
SergeantPanda 2026-03-03 10:11:45 -06:00
parent c005a48162
commit 1e629d57ec

View file

@ -269,6 +269,19 @@ const ChannelsTable = ({ onReady }) => {
// store/channelsTable
const data = useChannelsTableStore((s) => s.channels);
const pageCount = useChannelsTableStore((s) => s.pageCount);
const rowClassMap = useMemo(() => {
const map = {};
for (const channel of data) {
const hasStreams = channel.streams?.length > 0;
if (!hasStreams) {
map[channel.id] = 'no-streams-row';
} else if (channel.streams.some((s) => s.is_stale)) {
map[channel.id] = 'partially-stale-streams-row';
}
}
return map;
}, [data]);
const setSelectedChannelIds = useChannelsTableStore(
(s) => s.setSelectedChannelIds
);
@ -1130,20 +1143,8 @@ const ChannelsTable = ({ onReady }) => {
epg: renderHeaderCell,
},
getRowStyles: (row) => {
const hasStreams =
row.original.streams && row.original.streams.length > 0;
const hasStaleStreams =
hasStreams && row.original.streams.some((s) => s.is_stale);
if (!hasStreams) {
return { className: 'no-streams-row' };
}
if (hasStaleStreams) {
return { className: 'partially-stale-streams-row' };
}
return {};
const cls = rowClassMap[row.original.id];
return cls ? { className: cls } : {};
},
});