From 2efafbb027fc9e4b0d7933d3ce49a0ad5998563b Mon Sep 17 00:00:00 2001
From: Alexander Jason <alexanderjason526@gmail.com>
Date: Mon, 13 Nov 2023 19:53:40 +0700
Subject: [PATCH] feat: add limit title

---
 app/pages/book/BookListPage.php | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/app/pages/book/BookListPage.php b/app/pages/book/BookListPage.php
index 88f51ed..7e482d9 100644
--- a/app/pages/book/BookListPage.php
+++ b/app/pages/book/BookListPage.php
@@ -68,12 +68,21 @@
             <?php if (!$this->data['book']) : ?>
                     <p class="info">There are no Books yet available on Audibook!</p>
             <?php else: ?>
+            <?php function limit_text_length(string $book_title, int $max_length = 20): string
+                {
+                    if (mb_strlen($book_title) > $max_length) {
+                        return mb_substr($book_title, 0, $max_length) . '...';
+                    } else {
+                        return $book_title;
+                    }
+                } ?>
             <?php foreach ($this->data['book'] as $book): ?>
                 <div class="book-container">
                     <img class="book-image" src="<?= BASE_URL ?>/<?= str_replace('/var/www/html/config/', '', $book['cover_path']) ?>" alt="book-cover" />
-                    <div class="info-text title-text"><?= $book['title'] ?></div>
+                    
+                    <div class="info-text title-text"><?= limit_text_length($book['title']) ?></div>
                     <div class="info-text author-text">
-                        <?= current(explode(',', $book['authors'])) ?>
+                        <?= current(explode(',', limit_text_length($book['authors']))) ?>
                         <?php if (count(explode(',', $book['authors'])) > 1): ?>
                             , dkk
                         <?php endif; ?>
-- 
GitLab