Skip to content

Commit

Permalink
fix(comments|commans): allow multiple comment instances to exist on o…
Browse files Browse the repository at this point in the history
…ne page, fix multiple subtypes conversion
  • Loading branch information
ScuffedNewt committed Aug 31, 2024
1 parent 0385914 commit 397e452
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
5 changes: 3 additions & 2 deletions app/Console/Commands/ConvertCharacterSubtype.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Models\Character\CharacterImage;
use App\Models\Character\CharacterImageSubtype;
use App\Models\Character\CharacterDesignUpdate;
use Illuminate\Console\Command;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
Expand Down Expand Up @@ -46,11 +47,11 @@ public function handle() {
}

// DESIGN UPDATES
$updates = DB::table('design_updates')->where('subtype_id', '!=', null)->get();
$updates = CharacterDesignUpdate::where('subtype_id', '!=', null)->get();
// make the string into an array
foreach ($updates as $update) {
$update->update([
'subtype_ids' => json_encode([$update->subtype_ids]),
'subtype_ids' => $update->subtype_id,
]);
}
Schema::table('design_updates', function (Blueprint $table) {
Expand Down
34 changes: 20 additions & 14 deletions resources/views/comments/comments.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
$comments = $model->commentz->where('type', 'User-User');
}
}
if (!isset($commentType)) {
$commentType = 'comment';
}
@endphp

@if (!isset($type) || $type == 'User-User')
Expand All @@ -30,7 +34,7 @@
'oldest' => 'Oldest First',
],
Request::get('sort') ?: 'newest',
['class' => 'form-control', 'id' => 'sort'],
['class' => 'form-control', 'id' => $commentType.'-sort'],
) !!}
</div>
<div class="form-group ml-3 mb-3">
Expand All @@ -44,14 +48,14 @@
100 => '100 Per Page',
],
Request::get('perPage') ?: 5,
['class' => 'form-control', 'id' => 'perPage'],
['class' => 'form-control', 'id' => $commentType.'-perPage'],
) !!}
</div>
</div>
</div>
</div>
@endif
<div id="comments">
<div id="{{ $commentType }}-comments">
<div class="justify-content-center text-center mb-2">
<i class="fas fa-spinner fa-spin fa-2x"></i>
</div>
Expand Down Expand Up @@ -93,7 +97,7 @@
});
function sortComments() {
$('#comments').fadeOut();
$('#{{ $commentType }}-comments').fadeOut();
$.ajax({
url: "{{ url('sort-comments/' . base64_encode(urlencode(get_class($model))) . '/' . $model->getKey()) }}",
type: 'GET',
Expand All @@ -102,28 +106,30 @@ function sortComments() {
allow_dislikes: '{{ isset($allow_dislikes) ? $allow_dislikes : false }}',
approved: '{{ isset($approved) ? $approved : false }}',
type: '{{ isset($type) ? $type : null }}',
sort: $('#sort').val(),
perPage: $('#perPage').val(),
sort: $('#{{ $commentType }}-sort').val(),
perPage: $('#{{ $commentType }}-perPage').val(),
page: '{{ request()->query('page') }}',
},
success: function(data) {
$('#comments').html(data);
$('#{{ $commentType }}-comments').html(data);
// update current url to reflect sort change
var url = new URL(window.location.href);
url.searchParams.set('sort', $('#sort').val());
url.searchParams.set('perPage', $('#perPage').val());
if ($('#{{ $commentType }}-sort').val() != 'newest' && $('#{{ $commentType }}-perPage').val() != 5) { // 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());
window.history.pushState({}, '', url);
$('#comments').fadeIn();
window.history.pushState({}, '', url);
}
$('#{{ $commentType }}-comments').fadeIn();
}
});
}
$('#sort').change(function() {
$('#{{ $commentType }}-sort').change(function() {
sortComments();
});
$('#perPage').change(function() {
$('#{{ $commentType }}-perPage').change(function() {
sortComments();
});
Expand Down
2 changes: 1 addition & 1 deletion resources/views/galleries/submission_log.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ class="float-right badge badge-{{ $submission->status == 'Pending' ? 'secondary'
<div class="card-body">
<!-- Staff-User Comments -->
<div class="container">
@comments(['model' => $submission, 'type' => 'Staff-Staff', 'perPage' => 5])
@comments(['model' => $submission, 'type' => 'Staff-Staff', 'perPage' => 5, 'commentType' => 'staff'])
</div>
</div>
</div>
Expand Down

0 comments on commit 397e452

Please sign in to comment.