Pages support

This commit is contained in:
Pablo Ferreiro 2022-01-01 20:48:42 +01:00
parent fa632b1f2d
commit c8d991883a
No known key found for this signature in database
GPG key ID: 41FBCE65B779FA24
3 changed files with 14 additions and 3 deletions

View file

@ -12,8 +12,7 @@ php -S localhost:8080
``` ```
## Known issues ## Known issues
* Right now there is an error when trying to fetch the desired user, there is already a pull request fixing this issue on the TikTokApi repo, you can check it out [here](https://github.com/ssovit/TikTok-API-PHP/pull/43) * Right now there is an error when trying to fetch the desired user, there is already a pull request not merged yet fixing this issue on the TikTokApi repo, you can check it out [here](https://github.com/ssovit/TikTok-API-PHP/pull/43)
* Only one page is available to the user
## Credits ## Credits
* [TikTok-API-PHP](https://github.com/ssovit/TikTok-API-PHP) * [TikTok-API-PHP](https://github.com/ssovit/TikTok-API-PHP)

View file

@ -10,9 +10,13 @@ $app->get('/', function () use ($app) {
}); });
$app->get("/users/{user}", function (string $username) { $app->get("/users/{user}", function (string $username) {
$cursor = 0;
if (isset($_GET['cursor']) && is_numeric($_GET['cursor'])) {
$cursor = (int) $_GET['cursor'];
}
$blade = new Blade('./views', './cache/views'); $blade = new Blade('./views', './cache/views');
$api = new \Sovit\TikTok\Api(); $api = new \Sovit\TikTok\Api();
$user = $api->getUserFeed($username); $user = $api->getUserFeed($username, $cursor);
if ($user) { if ($user) {
echo $blade->render('user', ['user' => $user]); echo $blade->render('user', ['user' => $user]);
} else { } else {

View file

@ -34,6 +34,14 @@
</div> </div>
@endforeach @endforeach
</div> </div>
<div class="buttons">
<a class="button" href="javascript:history.back()">Last page</a>
@if ($user->hasMore)
<a class="button" href="?cursor={{ $user->maxCursor }}">Next page</a>
@else
<a class="button is-disabled">Next page</a>
@endif
</div>
</section> </section>
<div id="modal" class="modal"> <div id="modal" class="modal">
<div id="modal-background" class="modal-background"></div> <div id="modal-background" class="modal-background"></div>