Skip to content

Commit ae62683

Browse files
authored
CGT: Fix level history page (#10930)
* CGT: Fix level history viewer * More efficiently iterate the array in reverse
1 parent 64b033a commit ae62683

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

server/chat-plugins/cg-teams-leveling.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export const pages: Chat.PageTable = {
129129
let speciesID = query.shift();
130130
let buf;
131131
if (speciesID) {
132-
speciesID = getLevelSpeciesID({ species: query.shift() || '' } as PokemonSet);
132+
speciesID = getLevelSpeciesID({ species: speciesID || '' } as PokemonSet);
133133
const species = Dex.species.get(speciesID);
134134
if (!species.exists ||
135135
species.isNonstandard || species.isNonstandard === 'Unobtainable' ||
@@ -148,14 +148,13 @@ export const pages: Chat.PageTable = {
148148
this.title = `[History] [Gen 9] Computer Generated Teams`;
149149

150150
const MAX_LINES = 100;
151-
let lines = 0;
152151
buf += `<div class="ladder pad"><table><tr><th>Pokemon</th><th>Level</th><th>Timestamp</th>`;
153-
for (const entry of history) {
152+
for (let i = history.length - 1; history.length - i <= MAX_LINES; i--) {
153+
const entry = history[i];
154154
if (speciesID && entry.species_id !== speciesID) continue;
155155
buf += `<tr><td>${entry.species_id}</td><td>${entry.level}</td>`;
156156
const timestamp = new Date(entry.timestamp);
157157
buf += `<td>${timestamp.toLocaleDateString()}, ${timestamp.toLocaleTimeString()}</td></tr>`;
158-
if (++lines >= MAX_LINES) break;
159158
}
160159
buf += `</table></div></div>`;
161160
return buf;

0 commit comments

Comments
 (0)