added pagination
This commit is contained in:
parent
00b57f9e20
commit
f67907176f
4
TODO.md
4
TODO.md
@ -55,6 +55,10 @@
|
|||||||
- [ ] Music
|
- [ ] Music
|
||||||
- [ ] Announcements
|
- [ ] 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
|
- [ ] Fixes
|
||||||
- [x] Fix that weird json encoding in the object field of an activity
|
- [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)
|
- [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\Announcement;
|
||||||
use App\Models\Note;
|
use App\Models\Note;
|
||||||
|
|
||||||
|
use App\Helpers\PaginationHelper;
|
||||||
|
|
||||||
use App\Types\TypeActor;
|
use App\Types\TypeActor;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
@ -60,7 +62,7 @@ class Actor extends Model
|
|||||||
|
|
||||||
$all = $posts->merge ($announcements)->sortByDesc ("created_at");
|
$all = $posts->merge ($announcements)->sortByDesc ("created_at");
|
||||||
|
|
||||||
return $all;
|
return PaginationHelper::paginate ($all);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function create_from_user (User $user)
|
public function create_from_user (User $user)
|
||||||
|
@ -3,6 +3,9 @@
|
|||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||||
|
|
||||||
|
use App\Helpers\PaginationHelper;
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
use Illuminate\Notifications\Notifiable;
|
use Illuminate\Notifications\Notifiable;
|
||||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
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 ();
|
$announcements = Announcement::whereIn ("actor_id", $friends_id)->orderBy ("created_at", "desc")->get ();
|
||||||
|
|
||||||
$feed = $notes->merge ($announcements)->sortByDesc ("created_at");
|
$feed = $notes->merge ($announcements)->sortByDesc ("created_at");
|
||||||
|
return PaginationHelper::paginate ($feed, 20, "feed");
|
||||||
return $feed;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,9 @@
|
|||||||
"phpunit/phpunit": "^11.0.1"
|
"phpunit/phpunit": "^11.0.1"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
|
"files": [
|
||||||
|
"app/Helpers/PaginationHelper.php"
|
||||||
|
],
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"App\\": "app/",
|
"App\\": "app/",
|
||||||
"Database\\Factories\\": "database/factories/",
|
"Database\\Factories\\": "database/factories/",
|
||||||
|
@ -2989,7 +2989,7 @@ Master Container
|
|||||||
*/
|
*/
|
||||||
.master-container {
|
.master-container {
|
||||||
margin: auto;
|
margin: auto;
|
||||||
width: 800px;
|
width: 810px;
|
||||||
background-color: white;
|
background-color: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,6 +125,9 @@ else
|
|||||||
<p>
|
<p>
|
||||||
<b>Replies:</b> {{ $display_post->get_replies ()->count () }}
|
<b>Replies:</b> {{ $display_post->get_replies ()->count () }}
|
||||||
</p>
|
</p>
|
||||||
|
<p>
|
||||||
|
<b>Boosts:</b> {{ $display_post->get_boosts ()->count () }}
|
||||||
|
</p>
|
||||||
|
|
||||||
<a href="{{ route ('posts.show', [ 'note' => $display_post ]) }}">
|
<a href="{{ route ('posts.show', [ 'note' => $display_post ]) }}">
|
||||||
<button type="button">View</button>
|
<button type="button">View</button>
|
||||||
|
@ -143,6 +143,8 @@
|
|||||||
@endforeach
|
@endforeach
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
{{ auth ()->user ()->feed ()->links ("pagination::default") }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<div class="master-container">
|
<div class="container">
|
||||||
@include ("partials.header")
|
@include ("partials.header")
|
||||||
|
|
||||||
<main>
|
<main>
|
||||||
|
@ -327,6 +327,8 @@
|
|||||||
@endforeach
|
@endforeach
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
{{ $actor->get_posts ()->links ("pagination::default") }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user