diff --git a/src/app/Controllers/HomeController.php b/src/app/Controllers/HomeController.php index c397f83..4ff37e0 100644 --- a/src/app/Controllers/HomeController.php +++ b/src/app/Controllers/HomeController.php @@ -21,17 +21,26 @@ class HomeController extends Controller /** * @throws Exception */ - public function index() + public function index(int $page = 1) { if (Flight::request()->query->count() > 0) { $id = Flight::request()->query->keys()[0]; - Flight::redirect(base_url("$id")); + Flight::redirect(base_url($id)); die; } + $per_page = 10; + $list = $this->ini->playlists + ->where('redirect_id', null) + // ->sortBy('id') + ->forPage($page, $per_page); view('list', [ 'updated_at' => $this->ini->updatedAt(), 'count' => $this->ini->playlists->count(), - 'playlists' => $this->ini->playlists->where('redirect_id', null)->toArray(), + 'pages' => [ + 'count' => (int)($this->ini->playlists->count() / $per_page), + 'current' => $page, + ], + 'playlists' => $list->toArray(), ]); } diff --git a/src/app/Core/Bootstrapper.php b/src/app/Core/Bootstrapper.php index 5e2db9c..00b0176 100644 --- a/src/app/Core/Bootstrapper.php +++ b/src/app/Core/Bootstrapper.php @@ -53,6 +53,10 @@ final class Bootstrapper 'GET /', fn() => (new HomeController())->index() ); + Flight::route( + 'GET /page/@page:[0-9]+', + fn($page) => (new HomeController())->index((int)$page) + ); Flight::route( 'GET /faq', fn() => (new HomeController())->faq() diff --git a/src/views/list.twig b/src/views/list.twig index f7b0394..670cdcb 100644 --- a/src/views/list.twig +++ b/src/views/list.twig @@ -54,6 +54,23 @@ {% endfor %} + {% if pages.count > 0 %} + + {% endif %} {% endblock %} {% block footer %}