dkforest

A forum and chat platform (onion)
git clone https://git.dasho.dev/n0tr1v/dkforest.git
Log | Files | Refs | LICENSE

commit a5867d0a6f627cf05e7a066e164e75427277ce98
parent 4dc7c352221c0620fa799ae2629bd375a97eb1c7
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Sun, 11 Jun 2023 21:43:05 -0700

simplify code

Diffstat:
Mpkg/web/handlers/handlers.go | 58+++++++++++++++++++++-------------------------------------
1 file changed, 21 insertions(+), 37 deletions(-)

diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go @@ -4971,47 +4971,31 @@ input[type=checkbox]:checked + label { g := interceptors.ChessInstance.GetGame(key) isFlipped := authUser.ID == g.Player2.ID - out += `<form method="post" action="/chess/` + key + `"> -<table class="newBoard">` - for i := 0; i < 64; i++ { - id := i - mm := 0 - switch i % 8 { - case 0: - mm = -7 - case 1: - mm = -5 - case 2: - mm = -3 - case 3: - mm = -1 - case 4: - mm = 1 - case 5: - mm = 3 - case 6: - mm = 5 - case 7: - mm = 7 - } - if !isFlipped { - id = (63 - i) + mm + getID := func(row, col int, isFlipped bool) int { + var id int + if isFlipped { + id = row*8 + (7 - col) } else { - id = i - mm + id = (7-row)*8 + col } - if i%8 == 0 { - if i != 0 { - out += "</tr>" - } - out += "<tr>" - } - idStr := strconv.Itoa(id) - out += `<td><div class="idk">` - out += `<input name="sq_` + idStr + `" id="sq_` + idStr + `" type="checkbox" value="1" /><label for="sq_` + idStr + `"></label>` - out += "</div></td>" + return id } + csrf, _ := c.Get("csrf").(string) - out += `</tr></table> + + out += `<form method="post" action="/chess/` + key + `"> +<table class="newBoard">` + for row := 0; row < 8; row++ { + out += "<tr>" + for col := 0; col < 8; col++ { + id := getID(row, col, isFlipped) + out += `<td><div class="idk">` + out += fmt.Sprintf(`<input name="sq_%d" id="sq_%d" type="checkbox" value="1" /><label for="sq_%d"></label>`, id, id, id) + out += "</div></td>" + } + out += "</tr>" + } + out += `</table> <input type="hidden" name="csrf" value="` + csrf + `" /> <input type="hidden" name="message" value="/pm {{ .Username }} /c move" /> <div style="width: 100%; display: flex; margin: 5px 0;">