added pagination
This commit is contained in:
parent
00b57f9e20
commit
f67907176f
4
TODO.md
4
TODO.md
@ -55,6 +55,10 @@
|
||||
- [ ] Music
|
||||
- [ ] Announcements
|
||||
|
||||
- [ ] Security
|
||||
- [ ] Token system for user, there should be a token that is used to consume the API and another one to use the outbox (only the server must know the one for the outbox)
|
||||
- [ ] Verify the signature of the incoming activities
|
||||
|
||||
- [ ] Fixes
|
||||
- [x] Fix that weird json encoding in the object field of an activity
|
||||
- [x] The profile attachments are not working, they are not being federalised somehow (the interests thingy)
|
||||
|
30
app/Helpers/PaginationHelper.php
Normal file
30
app/Helpers/PaginationHelper.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Helpers;
|
||||
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Pagination\Paginator;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class PaginationHelper
|
||||
{
|
||||
public static function paginate (Collection $results, $per_page = 20, $name = "page")
|
||||
{
|
||||
$page_number = Paginator::resolveCurrentPage ($name);
|
||||
|
||||
$total_page_number = $results->count ();
|
||||
|
||||
return self::paginator ($results->forPage ($page_number, $per_page), $total_page_number, $per_page, $page_number, [
|
||||
"path" => Paginator::resolveCurrentPath (),
|
||||
"pageName" => $name,
|
||||
]);
|
||||
}
|
||||
|
||||
protected static function paginator ($items, $total, $perPage, $currentPage, $options)
|
||||
{
|
||||
return Container::getInstance ()->makeWith (LengthAwarePaginator::class, compact (
|
||||
"items", "total", "perPage", "currentPage", "options"
|
||||
));
|
||||
}
|
||||
}
|
@ -6,6 +6,8 @@ use App\Models\User;
|
||||
use App\Models\Announcement;
|
||||
use App\Models\Note;
|
||||
|
||||
use App\Helpers\PaginationHelper;
|
||||
|
||||
use App\Types\TypeActor;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
@ -60,7 +62,7 @@ class Actor extends Model
|
||||
|
||||
$all = $posts->merge ($announcements)->sortByDesc ("created_at");
|
||||
|
||||
return $all;
|
||||
return PaginationHelper::paginate ($all);
|
||||
}
|
||||
|
||||
public function create_from_user (User $user)
|
||||
|
@ -3,6 +3,9 @@
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
|
||||
use App\Helpers\PaginationHelper;
|
||||
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
@ -151,7 +154,6 @@ class User extends Authenticatable
|
||||
$announcements = Announcement::whereIn ("actor_id", $friends_id)->orderBy ("created_at", "desc")->get ();
|
||||
|
||||
$feed = $notes->merge ($announcements)->sortByDesc ("created_at");
|
||||
|
||||
return $feed;
|
||||
return PaginationHelper::paginate ($feed, 20, "feed");
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,9 @@
|
||||
"phpunit/phpunit": "^11.0.1"
|
||||
},
|
||||
"autoload": {
|
||||
"files": [
|
||||
"app/Helpers/PaginationHelper.php"
|
||||
],
|
||||
"psr-4": {
|
||||
"App\\": "app/",
|
||||
"Database\\Factories\\": "database/factories/",
|
||||
|
@ -2989,7 +2989,7 @@ Master Container
|
||||
*/
|
||||
.master-container {
|
||||
margin: auto;
|
||||
width: 800px;
|
||||
width: 810px;
|
||||
background-color: white;
|
||||
}
|
||||
|
||||
|
@ -125,6 +125,9 @@ else
|
||||
<p>
|
||||
<b>Replies:</b> {{ $display_post->get_replies ()->count () }}
|
||||
</p>
|
||||
<p>
|
||||
<b>Boosts:</b> {{ $display_post->get_boosts ()->count () }}
|
||||
</p>
|
||||
|
||||
<a href="{{ route ('posts.show', [ 'note' => $display_post ]) }}">
|
||||
<button type="button">View</button>
|
||||
|
@ -143,6 +143,8 @@
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
{{ auth ()->user ()->feed ()->links ("pagination::default") }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -12,7 +12,7 @@
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="master-container">
|
||||
<div class="container">
|
||||
@include ("partials.header")
|
||||
|
||||
<main>
|
||||
|
@ -327,6 +327,8 @@
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
{{ $actor->get_posts ()->links ("pagination::default") }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user