Skip to content

Commit e5f1341

Browse files
committed
Add last updated information to forum posts
1 parent 62521e8 commit e5f1341

File tree

9 files changed

+148
-22
lines changed

9 files changed

+148
-22
lines changed

app/Http/Controllers/HomeController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function index(Request $request): \Illuminate\Contracts\View\Factory|\Ill
9393
'latest_posts:by-group:'.auth()->user()->group_id,
9494
$expiresAt,
9595
fn () => Post::query()
96-
->with('user', 'user.group', 'topic:id,name')
96+
->with('user', 'user.group', 'topic:id,name', 'updatedBy.group')
9797
->withCount('likes', 'dislikes', 'authorPosts', 'authorTopics')
9898
->withSum('tips', 'bon')
9999
->withExists([

app/Http/Controllers/PostController.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ public function update(Request $request, int $id): \Illuminate\Http\RedirectResp
207207
abort_unless($post->topic()->authorized(canReplyTopic: true)->exists(), 403);
208208

209209
$post->update([
210-
'content' => $request->input('content'),
210+
'content' => $request->input('content'),
211+
'updated_by' => $user->id,
211212
]);
212213

213214
return redirect()->to($postUrl)

app/Http/Controllers/User/PostController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function index(User $user): \Illuminate\Contracts\View\Factory|\Illuminat
2929
return view('user.post.index', [
3030
'user' => $user,
3131
'posts' => $user->posts()
32-
->with('user', 'user.group', 'topic:id,name,state')
32+
->with('user', 'user.group', 'topic:id,name,state', 'updatedBy.group')
3333
->withCount('likes', 'dislikes', 'authorPosts', 'authorTopics')
3434
->withSum('tips', 'bon')
3535
->authorized(canReadTopic: true)

app/Http/Livewire/PostSearch.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ final public function updatingSearch(): void
4343
final public function posts(): \Illuminate\Pagination\LengthAwarePaginator
4444
{
4545
return Post::query()
46-
->with('user', 'user.group', 'topic:id,name,state')
46+
->with('user', 'user.group', 'topic:id,name,state', 'updatedBy.group')
4747
->withCount('likes', 'dislikes', 'authorPosts', 'authorTopics')
4848
->withSum('tips', 'bon')
4949
->withExists([

app/Http/Livewire/TopicPostSearch.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ final public function updatingSearch(): void
5353
final public function posts(): \Illuminate\Pagination\LengthAwarePaginator
5454
{
5555
$posts = Post::query()
56-
->with('user', 'user.group')
56+
->with('user', 'user.group', 'updatedBy.group')
5757
->withCount('likes', 'dislikes', 'authorPosts', 'authorTopics')
5858
->withSum('tips', 'bon')
5959
->where('topic_id', '=', $this->topic->id)

app/Models/Post.php

+12
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
* @property string $content
3131
* @property \Illuminate\Support\Carbon|null $created_at
3232
* @property \Illuminate\Support\Carbon|null $updated_at
33+
* @property int $updated_by
3334
* @property int $user_id
3435
* @property int $topic_id
3536
*/
@@ -49,6 +50,7 @@ class Post extends Model
4950
'content',
5051
'topic_id',
5152
'user_id',
53+
'updated_by',
5254
];
5355

5456
/**
@@ -74,6 +76,16 @@ public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
7476
]);
7577
}
7678

79+
/**
80+
* Belongs To An Updated User.
81+
*
82+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo<User, $this>
83+
*/
84+
public function updatedBy(): \Illuminate\Database\Eloquent\Relations\BelongsTo
85+
{
86+
return $this->belongsTo(User::class, 'updated_by', 'id')->withTrashed();
87+
}
88+
7789
/**
7890
* A Post Has Many Likes.
7991
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* NOTICE OF LICENSE.
7+
*
8+
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
9+
* The details is bundled with this project in the file LICENSE.txt.
10+
*
11+
* @project UNIT3D Community Edition
12+
*
13+
* @author HDVinnie <[email protected]>
14+
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
15+
*/
16+
17+
use Illuminate\Database\Migrations\Migration;
18+
use Illuminate\Database\Schema\Blueprint;
19+
use Illuminate\Support\Facades\Schema;
20+
21+
return new class () extends Migration {
22+
/**
23+
* Run the migrations.
24+
*/
25+
public function up(): void
26+
{
27+
Schema::table('posts', function (Blueprint $table): void {
28+
$table->unsignedInteger('updated_by')->nullable()->after('updated_at');
29+
$table->foreign('updated_by')->references('id')->on('users')->cascadeOnUpdate()->cascadeOnDelete();
30+
});
31+
}
32+
33+
/**
34+
* Reverse the migrations.
35+
*
36+
* @return void
37+
*/
38+
public function down(): void
39+
{
40+
Schema::table('posts', function (Blueprint $table): void {
41+
$table->dropForeign(['updated_by']);
42+
$table->dropColumn('updated_by');
43+
});
44+
}
45+
};

resources/sass/components/forum/_post.scss

+56-10
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
grid-template-areas:
2727
'aside header'
2828
'aside content'
29+
'aside timestamps'
2930
'aside footer';
3031
grid-template-columns: minmax(153px, min-content) minmax(0, 1fr);
3132
grid-template-rows: auto 1fr auto;
@@ -38,8 +39,8 @@
3839
.post__header {
3940
grid-area: header;
4041
display: grid;
41-
grid-template-areas: 'datetime topic . tip-stats toolbar';
42-
grid-template-columns: auto auto 1fr auto auto;
42+
grid-template-areas: '. . topic . tip-stats toolbar';
43+
grid-template-columns: auto auto auto 1fr auto auto;
4344
align-items: center;
4445
gap: 9px;
4546
font-size: 13px;
@@ -48,10 +49,6 @@
4849
padding-left: 9px;
4950
}
5051

51-
.post__datetime {
52-
grid-area: datetime;
53-
}
54-
5552
.post__topic {
5653
grid-area: topic;
5754
}
@@ -158,6 +155,7 @@
158155
background-color: transparent;
159156
color: var(--post-like-fg);
160157
}
158+
161159
.votes__dislike {
162160
background-color: transparent;
163161
color: var(--post-dislike-fg);
@@ -254,6 +252,40 @@
254252
line-height: 1.5;
255253
}
256254

255+
.post__timestamps {
256+
display: grid;
257+
grid-template-areas: '. datetime updated';
258+
grid-template-columns: 1fr auto auto;
259+
border-top: 2px solid var(--post-aside-bg);
260+
padding: 4px;
261+
}
262+
263+
.post__datetime {
264+
grid-area: datetime;
265+
}
266+
267+
.post__updated {
268+
grid-area: updated;
269+
cursor: pointer;
270+
margin-left: 4px;
271+
margin-right: 8px;
272+
}
273+
274+
.post__updated-dropdown {
275+
display: none;
276+
background-color: var(--top-nav-dropdown-menu-item-hover-bg);
277+
position: absolute;
278+
padding: 5px;
279+
box-shadow: var(--post-shadow);
280+
border-radius: 5px;
281+
border: var(--bbcode-input-border);
282+
}
283+
284+
/* Show dropdown menu when the dropdown is focused */
285+
.post__updated:hover .post__updated-dropdown {
286+
display: block;
287+
}
288+
257289
.post__footer {
258290
grid-area: footer;
259291
border-top: 2px solid var(--post-aside-bg);
@@ -282,15 +314,15 @@
282314
cursor: pointer;
283315
}
284316

285-
@media screen and (max-width: 576px) {
317+
@media screen and (max-width: 1358px) {
286318
.post {
287-
grid-template-areas: 'aside' 'header' 'content' 'footer';
319+
grid-template-areas: 'aside' 'header' 'content' 'timestamps' 'footer';
288320
grid-template-columns: 100%;
289321
}
290322

291323
.post__header {
292-
grid-template-areas: 'datetime topic . tip-stats overflow' '. . . . toolbar';
293-
grid-template-columns: auto auto 1fr auto auto;
324+
grid-template-areas: '. . topic tip-stats overflow' '. . . . toolbar';
325+
grid-template-columns: auto auto auto 1fr auto auto;
294326
gap: 0 6px;
295327
}
296328

@@ -353,15 +385,27 @@
353385
}
354386
}
355387

388+
@media screen and (max-width: 867px) {
389+
.post__timestamps {
390+
display: grid;
391+
grid-template-areas: '. datetime updated .';
392+
grid-template-columns: 1fr auto auto 1fr;
393+
border-top: 2px solid var(--post-aside-bg);
394+
padding: 4px;
395+
}
396+
}
397+
356398
@-webkit-keyframes post__like-animation {
357399
0% {
358400
-webkit-transform: scale(1);
359401
transform: scale(1);
360402
}
403+
361404
50% {
362405
-webkit-transform: scale(1.1);
363406
transform: scale(1.1);
364407
}
408+
365409
100% {
366410
-webkit-transform: scale(1);
367411
transform: scale(1);
@@ -373,10 +417,12 @@
373417
-webkit-transform: scale(1);
374418
transform: scale(1);
375419
}
420+
376421
50% {
377422
-webkit-transform: scale(1.1);
378423
transform: scale(1.1);
379424
}
425+
380426
100% {
381427
-webkit-transform: scale(1);
382428
transform: scale(1);

resources/views/components/forum/post.blade.php

+29-7
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,6 @@
44

55
<article class="post" id="post-{{ $post->id }}" x-data>
66
<header class="post__header">
7-
<time
8-
class="post__datetime"
9-
datetime="{{ $post->created_at }}"
10-
title="{{ $post->created_at }}"
11-
>
12-
{{ $post->created_at?->diffForHumans() }}
13-
</time>
147
@if (! Route::is('topics.show'))
158
<span class="post__topic">
169
{{ __('forum.in') }}
@@ -234,6 +227,35 @@ class="post__content bbcode-rendered"
234227
>
235228
@joypixels($post->getContentHtml())
236229
</div>
230+
<span class="post__timestamps">
231+
<time
232+
class="post__datetime"
233+
datetime="{{ $post->created_at }}"
234+
title="{{ $post->created_at }}"
235+
>
236+
{{ $post->created_at?->diffForHumans() }}
237+
</time>
238+
@if ($post->updated_at > $post->created_at)
239+
<div class="post__updated">
240+
&bull; edited
241+
<i class="{{ config('other.font-awesome') }} fa-caret-down"></i>
242+
<div class="post__updated-dropdown">
243+
{{ $post->updated_at?->diffForHumans() }}
244+
by
245+
<a
246+
class="user-tag__link {{ $post->updatedBy->group->icon ?? $post->user->group->icon }}"
247+
href="{{ route('users.show', ['user' => $post->updatedBy ?? $post->user]) }}"
248+
style="
249+
color: {{ $post->updatedBy->group->color ?? $post->user->group->color }};
250+
"
251+
title="{{ $post->updatedBy->group->name ?? $post->user->group->name }}"
252+
>
253+
{{ $post->updatedBy?->username ?? $post->user->username }}
254+
</a>
255+
</div>
256+
</div>
257+
@endif
258+
</span>
237259
@if (! empty($post->user->signature))
238260
<footer class="post__footer" x-init>
239261
<p class="post__signature">

0 commit comments

Comments
 (0)