diff options
| Commit | 4f9a8920b080e6aee7e19e394654bf879c5759e2 (patch) | |
|---|---|---|
| Author | 2021-07-22 09:17:28 +0300 | |
| Committer | 2021-07-22 09:17:28 +0300 | |
| Files | 9792318353c048ccb9b8d304dcd35a68d2bfbbfa /go-src/utils | |
| ctfc-4f9a8920b080e6aee7e19e394654bf879c5759e2.tar ctfc-4f9a8920b080e6aee7e19e394654bf879c5759e2.tar.gz ctfc-4f9a8920b080e6aee7e19e394654bf879c5759e2.zip | ||
| Parent | 12558447c73da90f63276143f4d6a8796ec2fe7b (diff) | |
Moved chat pagination and real time updating to it's own package, implemeneted pagination navigation
1 files changed, 10 insertions, 4 deletions
| -rw-r--r-- | go-src/utils/utils.go | 14 |
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)] } |
