ignore missing matches records in widget
[sc2-widget] / widget.html
index c2a351dc14951302d6881a810a87acb4f191dde8..ccc9e78af0b2fbef82fbc963cac13fe736b1536b 100644 (file)
                return res.json()
        })
        .then(clan => {
+               let laddercmp = {}
+               clan.ladders = clan.ladders.filter(l => !(
+                       laddercmp[l.members] = l.members in laddercmp ? l : null
+               ))
                let tiernum = (rank) => rank <= 8 ? 1 : rank <= 25 ? 2 : rank <= 50 ? 3 : 4;
                let matchtime = (d) => d.getDate() + '/' + (d.getMonth() + 1) +
                        ' ' + d.getHours() + ":" + ('0' + d.getMinutes()).slice(-2);
                                        ladder.season ? ' old' : null,
                                ].join('')}"
                                 data-members="${ladder.members}"
-                                title="Division ${ladder.division} (${ladder.wins}:${ladder.losses})">
+                                title="Division ${ladder.division} (${ladder.wins}:${ladder.losses})${
+                                       (l => l ? `\nprevious season ${l.wins}:${l.losses} in ${l.league}` : '')
+                                               (laddercmp[ladder.members])
+                                }">
                                        ${ladder.league} <small>#${ladder.rank}</small>
                                </li>
                        `).join('')}
@@ -51,7 +58,7 @@
                        `).join('')}
                        </ul>
                        <ul class=matches>
-                       ${clan.matches.splice(0, 3).map(match => `
+                       ${(clan.matches || []).splice(0, 3).map(match => `
                                <li data-members="${match.players}" class=${match.decision.toLowerCase()}>
                                        ${matchtime(new Date(match.date * 1000))} ${match.type}
                                </li>