diff --git a/KNOWLEDGE_BASE.md b/KNOWLEDGE_BASE.md
index 0f47f9f37..cb8955308 100644
--- a/KNOWLEDGE_BASE.md
+++ b/KNOWLEDGE_BASE.md
@@ -660,7 +660,7 @@ Sources: [issue command UI](resources/js/components/issue-command.tsx), [issue v
Guilds are public groups around hashtags and are not generally available yet. In the preview, matching hashtags become small clickable guild labels; ordinary hashtags still open search. Create a guild from the Guilds overview or a hashtag's search page. From the overview, its display name determines the hashtag: “Laravel 4ever” becomes `#laravel4ever`. Display names and handles each allow up to 60 characters. When claiming a hashtag, the display name must match its letters, numbers and underscores, ignoring case; spaces, punctuation and decorative symbols are ignored, so `/dev/null` is valid for `#devnull`. Accents and underscores remain significant. Its creator joins automatically and maintains its icon and description. Each person can create up to 100 guilds. A guild's name, description and icon pass the same automated moderation as commits before the guild is published or edited; a guild that the moderation flags is not saved.
-The Guilds page lists groups by member count. Click a guild's member count to browse its members: the moderator appears first, labeled “(moderator)”, followed by newest joins, with 50 people per page and Load more for the next page. Joining adds matching commits to Following without following every author and clears any existing mute. When a commit appears only because of a joined guild, it says “because you joined” beside the guild label. Leave a guild to reveal its Mute control. Muting hides matching commits from logs and search, including commits by followed authors. You can still open the guild or a commit directly.
+The Guilds page lists groups by member count, with 24 guilds per page. Search matches keywords in guild names, handles, and descriptions, ignoring case; a leading `#` is optional. This directory search is keyword-based, not semantic. Click a guild's member count to browse its members: the moderator appears first, labeled “(moderator)”, followed by newest joins, with 50 people per page and Load more for the next page. Joining adds matching commits to Following without following every author and clears any existing mute. When a commit appears only because of a joined guild, it says “because you joined” beside the guild label. Leave a guild to reveal its Mute control. Muting hides matching commits from logs and search, including commits by followed authors. You can still open the guild or a commit directly.
Each guild's bulletin board shows commits posted directly to it and regular commits containing its exact hashtag—not semantic search. Matching replies bring their thread onto the board, even when the root has no hashtag. Threads show reply previews and expand like a regular commit log, ordered by root date, newest first. Each page contains 30 distinct root commits; replies do not use up that limit, and Load more adds the next page. Posts from the board's composer stay attached to that guild without an automatic hashtag, including scheduled posts. They count toward the author's commit count but do not appear in their profile log or general feeds. They appear in Following when you join the guild, and in semantic search suggestions and results under a divider with the guild's name and icon. Regular hashtag commits keep appearing on profiles and in feeds as usual. Typing a hashtag offers matching guilds in the autocomplete menu; select one with the keyboard or pointer to insert its handle.
diff --git a/app/Http/Controllers/GuildController.php b/app/Http/Controllers/GuildController.php
index 93fd6eaab..9e5f64bd8 100644
--- a/app/Http/Controllers/GuildController.php
+++ b/app/Http/Controllers/GuildController.php
@@ -15,6 +15,7 @@
use App\Models\Guild;
use App\Models\User;
use App\Queries\GuildCommitsQuery;
+use App\Queries\GuildsQuery;
use Illuminate\Container\Attributes\CurrentUser;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\UploadedFile;
@@ -23,9 +24,13 @@
final readonly class GuildController
{
- public function index(ListGuildsRequest $request): Response
+ public function index(ListGuildsRequest $request, GuildsQuery $query): Response
{
- return Inertia::render('guild/index')->withViewData(['robots' => 'noindex, follow']);
+ return Inertia::render('guild/index', [
+ 'query' => $request->term(),
+ 'guildPage' => fn () => $query->paginate($request->term(), $request->integer('page', 1))
+ ->through(fn (Guild $guild): string => $guild->id),
+ ])->withViewData(['robots' => 'noindex, follow']);
}
public function store(CreateGuildRequest $request, #[CurrentUser] User $user, CreateGuild $action): RedirectResponse
diff --git a/app/Http/Requests/ListGuildsRequest.php b/app/Http/Requests/ListGuildsRequest.php
index 6fa867405..2752dfa71 100644
--- a/app/Http/Requests/ListGuildsRequest.php
+++ b/app/Http/Requests/ListGuildsRequest.php
@@ -16,9 +16,17 @@ public function authorize(Features $features): Response
return $features->available(Feature::Guilds, $this->user()) ? Response::allow() : Response::denyAsNotFound();
}
- /** @return array{} */
+ /** @return array
@@ -39,9 +106,94 @@ export default function Index() {
- No guilds yet. Create the first one. + {query !== '' + ? 'No guilds found on this page. Try another keyword or return to the first page.' + : guildPage.current_page > 1 + ? 'No guilds on this page. Return to the first page.' + : 'No guilds yet. Create the first one.'} + {(query !== '' || guildPage.current_page > 1) && ( + + Browse all guilds + + )}
)} > diff --git a/tests/Feature/Controllers/GuildControllerTest.php b/tests/Feature/Controllers/GuildControllerTest.php index da32fae80..54e6eea94 100644 --- a/tests/Feature/Controllers/GuildControllerTest.php +++ b/tests/Feature/Controllers/GuildControllerTest.php @@ -529,6 +529,92 @@ $this->assertDatabaseMissing('guild_preferences', ['guild_id' => $jobs->id, 'user_id' => $admin->id]); }); +it('paginates matching guilds biggest first with handle ordering for ties', function (): void { + $admin = User::factory()->create(['handle' => 'admin']); + $guilds = Guild::factory()->count(25)->state(['user_id' => $admin->id])->sequence(fn ($sequence): array => [ + 'handle' => 'group'.mb_str_pad((string) $sequence->index, 2, '0', STR_PAD_LEFT), + 'name' => 'Builders', + ])->create(); + $popular = $guilds->last(); + $popular->members()->attach($admin, ['joined_at' => now()]); + Guild::factory()->create(['user_id' => $admin->id, 'name' => 'Unrelated', 'handle' => 'unrelated', 'description' => 'Other discussions.']); + + $this->actingAs($admin)->get(route('guild.index', ['q' => 'Builders']))->assertOk()->assertInertia(fn ($page) => $page + ->where('query', 'Builders')->where('guildPage.total', 25)->where('guildPage.last_page', 2) + ->where('guildPage.current_page', 1)->where('guildPage.data', [$popular->id, ...$guilds->take(23)->modelKeys()])); + $this->get(route('guild.index', ['q' => 'Builders', 'page' => 2]))->assertOk()->assertInertia(fn ($page) => $page + ->where('query', 'Builders')->where('guildPage.current_page', 2)->where('guildPage.total', 25) + ->where('guildPage.data', [$guilds[23]->id])); + $this->get(route('guild.index', ['q' => 'Builders', 'page' => 3]))->assertOk()->assertInertia(fn ($page) => $page + ->where('guildPage.data', [])->where('guildPage.total', 25)); +}); + +it('searches guild names handles and descriptions literally without case sensitivity', function (string $term, string $normalized, bool $matches): void { + $admin = User::factory()->create(['handle' => 'admin']); + $guild = Guild::factory()->create(['user_id' => $admin->id, 'handle' => 'rustaceans', 'name' => 'Systems Builders', 'description' => '100% safe_code!']); + Guild::factory()->create(['user_id' => $admin->id, 'handle' => 'other', 'name' => 'Different people', 'description' => '100 percent safeXcode.']); + + $this->actingAs($admin)->get(route('guild.index', ['q' => $term]))->assertOk()->assertInertia(fn ($page) => $page + ->where('query', $normalized)->where('guildPage.data', $matches ? [$guild->id] : [])); +})->with([ + 'name' => ['bUiLdErS', 'bUiLdErS', true], + 'handle' => [' #RuStAcEaNs ', 'RuStAcEaNs', true], + 'description' => ['SAFE_CODE', 'SAFE_CODE', true], + 'literal percent' => ['%', '%', true], + 'literal underscore' => ['_', '_', true], + 'literal escape' => ['!', '!', true], + 'no matches' => ['missing', 'missing', false], +]); + +it('matches Unicode search terms consistently even with C-collated guild columns', function (string $field, string $text, string $term): void { + DB::statement(sprintf('ALTER TABLE guilds ALTER COLUMN %s TYPE text COLLATE "C"', $field)); + $admin = User::factory()->create(['handle' => 'admin']); + $guild = Guild::factory()->create(['user_id' => $admin->id, $field => $text]); + Guild::factory()->create(['user_id' => $admin->id, 'handle' => 'unrelated', 'name' => 'Other', 'description' => 'No match.']); + + $this->actingAs($admin)->get(route('guild.index', ['q' => $term]))->assertOk()->assertInertia(fn ($page) => $page + ->where('guildPage.data', [$guild->id])); +})->with(['handle', 'name', 'description'])->with([ + 'Greek prefix ending in sigma' => ['ΟΣΑ', 'ΟΣ'], + 'lowercase final sigma' => ['κοσμος', 'ΚΟΣΜΟΣ'], + 'uppercase final sigma' => ['ΚΟΣΜΟΣ', 'κοσμος'], + 'accented capital' => ['ÉCOLE', 'école'], +]); + +it('keeps directory results out of membership-only refreshes', function (): void { + $admin = User::factory()->create(['handle' => 'admin']); + $guild = Guild::factory()->create(['user_id' => $admin->id]); + $this->actingAs($admin)->put(route('guild-membership.update', $guild), ['joined' => true])->assertRedirect(); + + $this->get(route('guild.index'), [ + 'X-Inertia-Version' => (string) resolve(HandleInertiaRequests::class)->version(request()), + 'X-Inertia' => 'true', 'X-Inertia-Partial-Component' => 'guild/index', 'X-Inertia-Partial-Data' => 'guilds', + ])->assertOk()->assertJsonPath('props.guilds.0.is_joined', true)->assertJsonMissingPath('props.guildPage'); +}); + +it('includes newly created guild cards when refreshing directory search results', function (): void { + $admin = User::factory()->create(['handle' => 'admin']); + $this->actingAs($admin)->get(route('guild.index'))->assertOk()->assertInertia(fn ($page) => $page->where('guildPage.data', [])); + $guild = Guild::factory()->create(['user_id' => $admin->id, 'handle' => 'rust', 'name' => 'Rust']); + + $this->get(route('guild.index', ['q' => 'rust']), [ + 'X-Inertia-Version' => (string) resolve(HandleInertiaRequests::class)->version(request()), + 'X-Inertia' => 'true', 'X-Inertia-Partial-Component' => 'guild/index', 'X-Inertia-Partial-Data' => 'guildPage,query,guilds', + ])->assertOk()->assertJsonPath('props.guildPage.data', [$guild->id])->assertJsonPath('props.guilds.0.id', $guild->id) + ->assertJsonPath('props.guilds.0.name', 'Rust'); +}); + +it('validates guild directory search and page inputs', function (array $input, string $field): void { + $this->actingAs(User::factory()->create(['handle' => 'admin'])) + ->getJson(route('guild.index', $input))->assertUnprocessable()->assertJsonValidationErrors($field); +})->with([ + 'array query' => [['q' => ['rust']], 'q'], + 'long query' => [['q' => str_repeat('a', 101)], 'q'], + 'zero page' => [['page' => 0], 'page'], + 'fractional page' => [['page' => 1.5], 'page'], + 'large page' => [['page' => 10001], 'page'], +]); + it('guards guild discovery and preferences with the preview flag and validates boolean inputs', function (): void { $guild = Guild::factory()->create(); $this->get(route('guild.index'))->assertRedirectToRoute('home'); diff --git a/tests/Unit/GuildControls.test.tsx b/tests/Unit/GuildControls.test.tsx index 80aa8515c..2a8aaa23c 100644 --- a/tests/Unit/GuildControls.test.tsx +++ b/tests/Unit/GuildControls.test.tsx @@ -8,6 +8,13 @@ import type { Guild } from '../../resources/js/types/guild'; let state: unknown[]; let cursor = 0; const errors = { setError: vi.fn(), clearErrors: vi.fn() }; +vi.doMock('@inertiajs/react', async () => ({ + ...(await vi.importActual('@inertiajs/react')), + usePage: () => ({ props: { guilds: [] } }), +})); +vi.doMock('../../resources/js/layouts/app-layout', () => ({ + default: () => null, +})); vi.doMock('react', () => ({ ...React, useRef: () => ({ current: errors }), @@ -35,6 +42,8 @@ const { GuildDialog } = await import('../../resources/js/components/guild-dialog'); const { GuildPreferences } = await import('../../resources/js/components/guild-preferences'); +const { default: GuildIndex } = + await import('../../resources/js/pages/guild/index'); type Element = ReactElement