christopher commited on
Commit
4f47be9
·
1 Parent(s): 2db3ea5

Update static/app.js

Browse files
Files changed (1) hide show
  1. static/app.js +6 -37
static/app.js CHANGED
@@ -34,45 +34,14 @@ function search() {
34
  }
35
 
36
  function displayPage() {
37
- const start = currentPage * RESULTS_PER_PAGE;
38
- const end = start + RESULTS_PER_PAGE;
39
- const pageResults = allResults.slice(start, end);
40
- const totalPages = Math.ceil(allResults.length / RESULTS_PER_PAGE);
41
-
42
  let html = `<h2>Found ${allResults.length} puzzles in ${window.searchTimeMs.toFixed(0)}ms (page ${currentPage + 1} of ${totalPages})</h2>`;
43
- html += `<div class="pagination">
44
- <button onclick="prevPage()" ${currentPage === 0 ? 'disabled' : ''}>Previous</button>
45
- <button onclick="nextPage()" ${end >= allResults.length ? 'disabled' : ''}>Next</button>
46
- </div>`;
47
-
48
- pageResults.forEach((p, i) => {
49
- const globalIdx = start + i;
50
- html += `
51
- <div class="puzzle">
52
- <div class="puzzle-board" id="result-board-${globalIdx}"></div>
53
- <div class="puzzle-info">
54
- <h3><a href="https://lichess.org/training/${p.PuzzleId}" target="_blank">${p.PuzzleId}</a></h3>
55
- <p>Rating: ${p.Rating} | Popularity: ${p.Popularity}%</p>
56
- <div class="themes">${p.Themes.map(t => `<span class="theme">${t}</span>`).join('')}</div>
57
- <p>Position in puzzle: ${p.MatchedMove}</p>
58
- </div>
59
- </div>`;
60
- });
61
-
62
- html += `<div class="pagination">
63
- <button onclick="prevPage()" ${currentPage === 0 ? 'disabled' : ''}>Previous</button>
64
- <button onclick="nextPage()" ${end >= allResults.length ? 'disabled' : ''}>Next</button>
65
- </div>`;
66
-
67
  document.getElementById('results').innerHTML = html;
68
-
69
- pageResults.forEach((p, i) => {
70
- const globalIdx = start + i;
71
- Chessboard(`result-board-${globalIdx}`, {
72
- position: p.FEN,
73
- pieceTheme: '/static/img/chesspieces/wikipedia/{piece}.png'
74
- });
75
- });
76
  }
77
 
78
  function nextPage() {
 
34
  }
35
 
36
  function displayPage() {
37
+ const start = currentPage * RESULTS_PER_PAGE, end = start + RESULTS_PER_PAGE, pageResults = allResults.slice(start, end), totalPages = Math.ceil(allResults.length / RESULTS_PER_PAGE);
 
 
 
 
38
  let html = `<h2>Found ${allResults.length} puzzles in ${window.searchTimeMs.toFixed(0)}ms (page ${currentPage + 1} of ${totalPages})</h2>`;
39
+ html += `<div class="pagination"><button onclick="prevPage()" ${currentPage === 0 ? 'disabled' : ''}>Previous</button><button onclick="nextPage()" ${end >= allResults.length ? 'disabled' : ''}>Next</button></div>`;
40
+ html += `<div class="puzzle-grid">`;
41
+ pageResults.forEach((p, i) => { const idx = start + i; html += `<div class="puzzle"><div class="puzzle-board" id="result-board-${idx}"></div><div class="puzzle-info"><h3><a href="https://lichess.org/training/${p.PuzzleId}" target="_blank">${p.PuzzleId}</a></h3><p>Rating: ${p.Rating} | Pop: ${p.Popularity}%</p><div class="themes">${p.Themes.map(t => `<span class="theme">${t}</span>`).join(' ')}</div><p>Move ${p.MatchedMove}</p></div></div>`; });
42
+ html += `</div>`;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  document.getElementById('results').innerHTML = html;
44
+ pageResults.forEach((p, i) => Chessboard(`result-board-${start + i}`, { position: p.FEN, pieceTheme: '/static/img/chesspieces/wikipedia/{piece}.png' }));
 
 
 
 
 
 
 
45
  }
46
 
47
  function nextPage() {