feat: sorting by updated_at on the archive page

This commit is contained in:
Floorb 2023-05-25 09:31:14 -04:00
parent 41d070222e
commit 66676c75a9
7 changed files with 11 additions and 4 deletions

View file

@ -20,6 +20,7 @@ whenReady(() => {
return `<tr>
<td><a href="/${rowData.id}">${escape(rowData.title)}</a></td>
<td><a href="/user/${escape(rowData.author)}">${escape(rowData.author)}</a></td>
<td>${escape(rowData.updated_at)}</td>
<td>${tagsToHtml(rowData.tags)}</td>
</tr>`;
},

View file

@ -18,7 +18,7 @@ $pastes = Paste::with([
'tags' => function($query) {
$query->select('tags.id', 'name', 'slug');
}
])->select(['id', 'user_id', 'title', 'expiry'])
])->select(['id', 'user_id', 'title', 'expiry', 'created_at', 'updated_at'])
->where('visible', Paste::VISIBILITY_PUBLIC)
->where('hidden', false)
->whereRaw("((expiry IS NULL) OR ((expiry != 'SELF') AND (expiry > NOW())))");
@ -37,6 +37,8 @@ header('Content-Type: application/json; charset=UTF-8');
$pastes_json = json_encode(['data' => $pastes->map(function($paste) {
return [
'id' => $paste->id,
'created_at' => $paste->created_at,
'updated_at' => $paste->updated_at ?? $paste->created_at,
'title' => $paste->title,
'author' => $paste->user->username,
'author_id' => $paste->user->id,

View file

@ -28,7 +28,7 @@ $pastes = Paste::with([
'tags' => function($q) {
$q->select('tags.id', 'name', 'slug');
}])
->select('id', 'user_id', 'title', 'created_at')
->select('id', 'user_id', 'title', 'created_at', 'updated_at')
->where('visible', Paste::VISIBILITY_PUBLIC)
->where('hidden', false)
->whereRaw("((expiry IS NULL) OR ((expiry != 'SELF') AND (expiry > NOW())))");

View file

@ -558,6 +558,7 @@ whenReady(() => {
return `<tr>
<td><a href="/${rowData.id}">${escape(rowData.title)}</a></td>
<td><a href="/user/${escape(rowData.author)}">${escape(rowData.author)}</a></td>
<td>${escape(rowData.updated_at)}</td>
<td>${tagsToHtml(rowData.tags)}</td>
</tr>`;
},

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -86,6 +86,7 @@
<tr class="paginator__sort">
<th data-sort-field="title">Title</th>
<th data-sort-field="author">Author</th>
<th data-sort-field="updated_at">Updated</th>
<th data-sort-field="tags">Tags</th>
</tr>
</thead>
@ -94,6 +95,7 @@
<tr>
<td><?= pp_html_escape($paste->title) ?></td>
<td><?= pp_html_escape($paste->user->username) ?></td>
<td><?= pp_html_escape($paste->updated_at ?? $paste->created_at) ?></td>
<td><?= tagsToHtml($paste->tags) ?></td>
</tr>
<?php endforeach; ?>
@ -102,6 +104,7 @@
<tr>
<th>Title</th>
<th>Author</th>
<th>Updated</th>
<th>Tags</th>
</tr>
</tfoot>