Skip to content

Commit

Permalink
fix(comments): add first time load check
Browse files Browse the repository at this point in the history
  • Loading branch information
ScuffedNewt committed Aug 31, 2024
1 parent 397e452 commit d04e981
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion resources/views/comments/_comments.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div id="comments">
<div>
<div class="d-flex mw-100 row mx-0" style="overflow:hidden;">
@php
$comments = isset($sort) && $sort == 'oldest' ? $comments->sortBy('created_at') : $comments->sortByDesc('created_at');
Expand Down
9 changes: 6 additions & 3 deletions resources/views/comments/comments.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
) !!}
</div>
Expand All @@ -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'],
) !!}
</div>
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit d04e981

Please sign in to comment.