aboutsummaryrefslogtreecommitdiff
path: root/go-src/utils/utils.go
diff options
context:
space:
mode:
authorSyndamia <kamen.d.mladenov@protonmail.com>2021-07-22 09:17:28 +0300
committerSyndamia <kamen.d.mladenov@protonmail.com>2021-07-22 09:17:28 +0300
commit4f9a8920b080e6aee7e19e394654bf879c5759e2 (patch)
tree9792318353c048ccb9b8d304dcd35a68d2bfbbfa /go-src/utils/utils.go
parent12558447c73da90f63276143f4d6a8796ec2fe7b (diff)
downloadctfc-4f9a8920b080e6aee7e19e394654bf879c5759e2.tar
ctfc-4f9a8920b080e6aee7e19e394654bf879c5759e2.tar.gz
ctfc-4f9a8920b080e6aee7e19e394654bf879c5759e2.zip
Moved chat pagination and real time updating to it's own package, implemeneted pagination navigation
Diffstat (limited to 'go-src/utils/utils.go')
-rw-r--r--go-src/utils/utils.go14
1 files changed, 10 insertions, 4 deletions
diff --git a/go-src/utils/utils.go b/go-src/utils/utils.go
index c1bd8a4..8d0c1c7 100644
--- a/go-src/utils/utils.go
+++ b/go-src/utils/utils.go
@@ -2,6 +2,8 @@ package utils
import (
"os"
+
+ ctfcmath "gitlab.com/Syndamia/ctfc/go-src/ctfcMath"
)
// Repeats a rune given amount of times and returns the result as a string
@@ -34,10 +36,14 @@ func AppendToFile(path string, value string) {
allChatsFile.Close()
}
-func TotalPages(maxSize int, messageAmount int) int {
- return messageAmount / maxSize
+/* Pagination */
+
+const PageSize = 15
+
+func TotalPages(messageAmount int) int {
+ return ctfcmath.CeilDivInt(messageAmount, PageSize)
}
-func Paginate(page int, maxSize int, messages ...string) []string {
- return messages[len(messages)-maxSize*page : len(messages)-maxSize*(page-1)]
+func Paginate(page int, messages ...string) []string {
+ return messages[ctfcmath.MaxInt(len(messages)-PageSize*page, 0) : len(messages)-PageSize*(page-1)]
}