Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion app/Http/Controllers/GuildController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use App\Actions\CreateGuild;
use App\Actions\UpdateGuild;
use App\Enums\UserUpdate;
use App\Exceptions\GuildModeratorRemoved;
use App\Http\Requests\CreateGuildRequest;
use App\Http\Requests\ListGuildsRequest;
Expand All @@ -17,6 +18,7 @@
use App\Models\User;
use App\Queries\GuildCommitsQuery;
use App\Queries\GuildsQuery;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Container\Attributes\CurrentUser;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\UploadedFile;
Expand Down Expand Up @@ -60,7 +62,20 @@ public function show(ShowGuildRequest $request, Guild $guild, #[CurrentUser] Use

return Inertia::render('guild/show', [
'handle' => $guild->handle,
'canModerate' => $guild->user_id === $user->id,
'canModerate' => Inertia::live(
fn (): bool => $guild->user_id === $user->id,
on: [UserUpdate::Guilds->value],
channel: new PrivateChannel($user),
),
'moderator' => Inertia::live(
Comment thread
PacketByte marked this conversation as resolved.
Resolved
fn (): ?array => ($owner = $guild->owner) === null ? null : [
'handle' => $owner->handle,
'name' => $owner->name,
'avatar_url' => $owner->avatar_url,
],
on: [UserUpdate::Guilds->value],
channel: new PrivateChannel($user),
Comment thread
PacketByte marked this conversation as resolved.
Resolved
),
'commits' => $commits->currentPage() > 1
? Inertia::merge(ShownStreams::commits($commits))->matchOn('id')
: ShownStreams::commits($commits),
Expand Down
7 changes: 7 additions & 0 deletions app/Models/Guild.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;

Expand Down Expand Up @@ -41,6 +42,12 @@ public function commits(): HasMany
return $this->hasMany(Commit::class);
}

/** @return BelongsTo<User, $this> */
public function owner(): BelongsTo
{
return $this->belongsTo(User::class, 'user_id');
}

/** @return BelongsToMany<User, $this> */
public function members(): BelongsToMany
{
Expand Down
27 changes: 26 additions & 1 deletion resources/js/pages/guild/show.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Head, router, usePage } from '@inertiajs/react';
import { Head, Link, router, usePage } from '@inertiajs/react';
import { Pencil } from 'lucide-react';
import { useState } from 'react';
import { show } from '@/actions/App/Http/Controllers/GuildController';
import { show as showProfile } from '@/actions/App/Http/Controllers/UserController';
import { CommitCard } from '@/components/commit-card';
import { CommitComposer } from '@/components/commit-composer';
import { EmptyFeed } from '@/components/commit-feed';
Expand All @@ -18,18 +19,25 @@ import {
} from '@/components/guild-preferences';
import { Button } from '@/components/ui/button';
import { Spinner } from '@/components/ui/spinner';
import { UserAvatar } from '@/components/user-avatar';
import AppLayout from '@/layouts/app-layout';
import type { Commit } from '@/types';

export default function Show({
handle,
canModerate,
moderator,
commits,
page,
hasMore,
}: {
handle: string;
canModerate: boolean;
moderator: {
handle: string;
name: string;
avatar_url: string | null;
} | null;
commits: Commit[];
page: number;
hasMore: boolean;
Expand Down Expand Up @@ -96,6 +104,23 @@ export default function Show({
<p className="mt-4 text-[15px] leading-relaxed wrap-anywhere whitespace-pre-wrap">
{guild.description}
</p>
{moderator && (
Comment thread
PacketByte marked this conversation as resolved.
Resolved
<div className="mt-4 flex flex-wrap items-center gap-2 text-sm text-muted-foreground">
<span>Moderators</span>
<Link
href={showProfile(moderator.handle)}
prefetch
className="flex items-center gap-1.5 text-foreground hover:underline"
>
<UserAvatar
user={moderator}
className="size-5"
pixels={40}
/>
@{moderator.handle}
</Link>
</div>
)}
<div className="mt-4 flex flex-wrap items-center gap-3">
{!canModerate && <GuildReportButton guild={guild} />}
{auth.isAdmin && !guild.is_paused && (
Expand Down
1 change: 1 addition & 0 deletions tests/Feature/Controllers/GuildControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@

$this->get(route('guild.show', 'jobs'))->assertOk()->assertInertia(fn ($page) => $page
->component('guild/show')->where('canModerate', true)->where('guilds.0.name', 'Jo bs')
->where('moderator.handle', 'admin')
->where('guilds.0.icon_url', null)->missing('guilds.0.user_id')->missing('guilds.0.icon_path'));
$this->actingAs(User::factory()->create(['handle' => 'other-admin']))
->get(route('guild.show', 'jobs'))->assertOk()->assertInertia(fn ($page) => $page->where('canModerate', false));
Expand Down