(programs, channelIdByTvgId)
| 61 | } |
| 62 | |
| 63 | export const mapProgramsByChannel = (programs, channelIdByTvgId) => { |
| 64 | if (!programs?.length || !channelIdByTvgId?.size) { |
| 65 | return new Map(); |
| 66 | } |
| 67 | |
| 68 | const map = new Map(); |
| 69 | const nowMs = getNowMs(); |
| 70 | |
| 71 | programs.forEach((program) => { |
| 72 | const channelIds = channelIdByTvgId.get(String(program.tvg_id)); |
| 73 | if (!channelIds || channelIds.length === 0) { |
| 74 | return; |
| 75 | } |
| 76 | |
| 77 | const startMs = program.startMs ?? convertToMs(program.start_time); |
| 78 | const endMs = program.endMs ?? convertToMs(program.end_time); |
| 79 | |
| 80 | const programData = { |
| 81 | ...program, |
| 82 | startMs, |
| 83 | endMs, |
| 84 | programStart: initializeTime(startMs), |
| 85 | programEnd: initializeTime(endMs), |
| 86 | // Precompute live/past status |
| 87 | isLive: nowMs >= startMs && nowMs < endMs, |
| 88 | isPast: nowMs >= endMs, |
| 89 | }; |
| 90 | |
| 91 | // Add this program to all channels that share the same TVG ID |
| 92 | channelIds.forEach((channelId) => { |
| 93 | if (!map.has(channelId)) { |
| 94 | map.set(channelId, []); |
| 95 | } |
| 96 | map.get(channelId).push(programData); |
| 97 | }); |
| 98 | }); |
| 99 | |
| 100 | map.forEach((list) => { |
| 101 | list.sort((a, b) => a.startMs - b.startMs); |
| 102 | }); |
| 103 | |
| 104 | return map; |
| 105 | }; |
| 106 | |
| 107 | export function computeRowHeights( |
| 108 | filteredChannels, |
no test coverage detected