From d04e98191db4a26df7b56791b30675613dbe9c4a Mon Sep 17 00:00:00 2001 From: ScuffedNewt Date: Sat, 31 Aug 2024 19:30:52 +0100 Subject: [PATCH] fix(comments): add first time load check --- resources/views/comments/_comments.blade.php | 2 +- resources/views/comments/comments.blade.php | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/resources/views/comments/_comments.blade.php b/resources/views/comments/_comments.blade.php index 8d513984c8..aeaa3648d0 100644 --- a/resources/views/comments/_comments.blade.php +++ b/resources/views/comments/_comments.blade.php @@ -1,4 +1,4 @@ -
+
@php $comments = isset($sort) && $sort == 'oldest' ? $comments->sortBy('created_at') : $comments->sortByDesc('created_at'); diff --git a/resources/views/comments/comments.blade.php b/resources/views/comments/comments.blade.php index 01f4b843d1..4c07eccbb6 100644 --- a/resources/views/comments/comments.blade.php +++ b/resources/views/comments/comments.blade.php @@ -33,7 +33,7 @@ 'newest' => 'Newest First', 'oldest' => 'Oldest First', ], - Request::get('sort') ?: 'newest', + Request::get($commentType . '-sort') ?: 'newest', ['class' => 'form-control', 'id' => $commentType.'-sort'], ) !!}
@@ -47,7 +47,7 @@ 50 => '50 Per Page', 100 => '100 Per Page', ], - Request::get('perPage') ?: 5, + Request::get($commentType . '-perPage') ?: 5, ['class' => 'form-control', 'id' => $commentType.'-perPage'], ) !!}
@@ -113,7 +113,10 @@ function sortComments() { success: function(data) { $('#{{ $commentType }}-comments').html(data); // update current url to reflect sort change - if ($('#{{ $commentType }}-sort').val() != 'newest' && $('#{{ $commentType }}-perPage').val() != 5) { // don't add to url if default + if ( + ($('#{{ $commentType }}-sort').val() != 'newest' && $('#{{ $commentType }}-perPage').val() != 5) || + (window.location.href.indexOf('{{ $commentType }}-sort') != -1 || window.location.href.indexOf('{{ $commentType }}-perPage') != -1) + ) { // don't add to url if default var url = new URL(window.location.href); url.searchParams.set('{{ $commentType }}-sort', $('#{{ $commentType }}-sort').val()); url.searchParams.set('{{ $commentType }}-perPage', $('#{{ $commentType }}-perPage').val());