Skip to content
Draft
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
34 changes: 25 additions & 9 deletions app/NativeComponents/Guild.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

/**
* A guild's page, as the web shows it at "/guilds/{handle}": its icon or
* emoji beside Commit and Join or Leave, its name, "#handle · Public guild ·
* emoji beside Join or Leave, its name, "#handle · Public guild ·
* N members" (the count opens its members), what it's about and how to post
* there, then its bulletin board, the commits posted in it or tagged with its
* hashtag, newest first, with the one its moderator pinned on top.
Expand All @@ -48,7 +48,7 @@
* so a page loaded later can repeat a commit already showing: those go once,
* as does the pinned commit, which devnull also sends in its place.
*
* The header's Commit posts to the board, as the web's guild page does,
* New commit in the nav bar posts to the board, as the web's guild page does,
* from the compose sheet (see OpensCommitSheet::composeInGuildSheet()), while
* the guild isn't paused. The commit shows on top of the board, staged, until
* devnull has it, as a new commit does on the Log. If devnull turns it down,
Expand Down Expand Up @@ -157,14 +157,30 @@ public function navTitle(): string
}

/**
* ⋯, as on someone else's profile: Share guild, then Mute or Unmute while
* you haven't joined, as the web hides Mute once you join. Commit and Join
* are in the header, as Remote and Follow are on a profile, and so is the
* moderator's Edit. The moderator gets no Report.
* New commit, as the Log has it, while the guild takes posts. Then ⋯, as
* on someone else's profile: Share guild, then Mute or Unmute while you
* haven't joined, as the web hides Mute once you join. Join is in the
* header, as Follow is on a profile, and so is the moderator's Edit. The
* moderator gets no Report.
*
* A guild always opens over the whole tab, never in an iOS workspace's
* column (see Workspace::paneFor()), so New commit takes Lucide's pencil on
* both platforms, as the Log's does outside a workspace.
*/
public function navigationOptions(): ?NavBarOptions
{
$hashtag = '#'.($this->guild->handle ?? $this->handle());
$options = NavBarOptions::make();

if ($this->takesPosts()) {
$options->action(
NavAction::make('compose')
->icon(ios: Lucide::SquarePen->ios(), android: Lucide::SquarePen->android())
->a11yLabel("New commit in {$hashtag}")
->press('composeForGuild'),
);
}

$items = [
NavAction::make('share')
->label('Share guild')
Expand All @@ -188,7 +204,7 @@ public function navigationOptions(): ?NavBarOptions
->press('reportGuild');
}

return NavBarOptions::make()->action(
return $options->action(
NavAction::make('more')
->icon(ios: Lucide::Ellipsis->ios(), android: Lucide::Ellipsis->android())
->a11yLabel("More options for {$hashtag}")
Expand Down Expand Up @@ -334,7 +350,7 @@ public function unmute(): void
}

/**
* The header's Commit: the sheet, for a commit on this guild's board.
* The bar's New commit: the sheet, for a commit on this guild's board.
*/
public function composeForGuild(): void
{
Expand Down Expand Up @@ -526,7 +542,7 @@ protected function showCommitTurnedDown(PendingWrite $write): void
}

/**
* The header's Commit is this page's, so a post to this board devnull turned down opens here again.
* The bar's New commit is this page's, so a post to this board devnull turned down opens here again.
*/
protected function opensComposer(): bool
{
Expand Down
9 changes: 5 additions & 4 deletions resources/views/native/partials/glass-pill-button.blade.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{{--
A header's main buttons on a profile or an organization's page: Follow, Unfollow and Remote. A 40pt pill, a step up
from the small theme button they were, on Liquid Glass on iOS as the app's other floating buttons are (see
sheet-bar-button). $filled draws it in your colour, tinted through the glass on iOS, for the one thing to do next,
like Follow; otherwise it's clear glass on iOS and a tonal pill on Android.
A header's main buttons on a profile, an organization's page or a guild's: Follow, Unfollow and Remote, or Join,
Leave and the moderator's Edit. A 40pt pill, a step up from the small theme button they were, on Liquid Glass on
iOS as the app's other floating buttons are (see sheet-bar-button). $filled draws it in your colour, tinted through
the glass on iOS, for the one thing to do next, like Follow or Join; otherwise it's clear glass on iOS and a tonal
pill on Android.

It's a pressable rather than a theme button, which takes no glass or per-button fill.
--}}
Expand Down
18 changes: 8 additions & 10 deletions resources/views/native/partials/guild-header.blade.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{{--
A guild's header, at the top of its board (see guild.blade.php), in the web's words: its icon or emoji (see
guild-mark) with Commit and Join or Leave beside it, as a profile has Remote and Follow, and Edit between them for
its moderator, as the web's pencil shows them it's theirs. Then its name,
"#handle · Public guild · N members", the count opening its members, what it's about, then how to post there, or
that it's paused while it has no moderator. Commit, which posts to the board, shows while the guild takes posts.
guild-mark) with Join or Leave beside it, as a profile has Follow, and Edit before it for its moderator, as the
web's pencil shows them it's theirs. They are the profile's 40pt pills (see glass-pill-button), with Join in your
colour as the thing to do next. Then its name, "#handle · Public guild · N members", the count opening its
members, what it's about, then how to post there, or that it's paused while it has no moderator. New commit,
which posts to the board, is in the nav bar while the guild takes posts (see Guild::navigationOptions()).
--}}
@php($members = \App\Devnull\Display::count($guild->memberCount, 'member', 'members'))
<native:column ref="guild-header" class="w-full bg-theme-surface">
Expand All @@ -14,16 +15,13 @@
</native:stack>

<native:row class="gap-2 items-center">
@unless ($guild->isPaused)
<native:button ref="guild-commit" variant="secondary" size="sm" :ios-icon="\App\Icons\Lucide::SquarePen->ios()" :android-icon="\App\Icons\Lucide::SquarePen->android()" @press="composeForGuild" a11y-hint="Posts to this guild's board">Commit</native:button>
@endunless
@if ($canModerate)
<native:button ref="guild-edit" variant="secondary" size="sm" @press="editGuild" a11y-hint="Edits {{ $guild->hashtag() }}'s name, description and icon">Edit</native:button>
@include('native.partials.glass-pill-button', ['ref' => 'guild-edit', 'label' => 'Edit', 'press' => 'editGuild', 'hint' => 'Edits '.$guild->hashtag()."'s name, description and icon"])
@endif
@if ($guild->isJoined)
<native:button ref="guild-join" variant="secondary" size="sm" @press="toggleJoined" a11y-hint="Leaves {{ $guild->hashtag() }}">Leave</native:button>
@include('native.partials.glass-pill-button', ['ref' => 'guild-join', 'label' => 'Leave', 'press' => 'toggleJoined', 'hint' => 'Leaves '.$guild->hashtag()])
@else
<native:button ref="guild-join" :variant="$myColour" size="sm" @press="toggleJoined" a11y-hint="Joins {{ $guild->hashtag() }}">Join</native:button>
@include('native.partials.glass-pill-button', ['ref' => 'guild-join', 'label' => 'Join', 'press' => 'toggleJoined', 'hint' => 'Joins '.$guild->hashtag(), 'filled' => true])
@endif
</native:row>
</native:row>
Expand Down
11 changes: 7 additions & 4 deletions tests/Feature/Screens/GuildMenuTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,15 @@ function guildSent(string $method, string $path): bool
->and($screen->instance()->guildReportOpen)->toBeFalse();
});

it('shows the moderator Edit in the guild header, which opens the guild form', function () {
it('shows the moderator Edit in the guild header, a pill like Leave beside it, which opens the guild form', function () {
fakeApi(['GET /api/v1/guilds/rust' => [boardOf(['c1'], overrides: ['can_moderate' => true, 'guild' => guildJson(['is_joined' => true])])]]);

finishRefreshes(Native::visit('/log/guilds/rust'))
->assertSee('Edit')
->tap('guild-edit')
$screen = finishRefreshes(Native::visit('/log/guilds/rust', platform: 'ios'))->assertSee('Edit');

expect(nodeByRef($screen, 'guild-edit-pill')['layout']['height'])->toEqual(nodeByRef($screen, 'guild-join-pill')['layout']['height'])
->and(nodeByRef($screen, 'guild-edit-pill')['props']['glass'] ?? 0)->not->toBe(0);

$screen->tap('guild-edit')
->assertNavigatedTo('/log/guilds/rust/edit', ['name' => 'Rust', 'description' => 'All about rust.', 'emoji' => '💻', 'iconUrl' => null]);
});

Expand Down
37 changes: 28 additions & 9 deletions tests/Feature/Screens/GuildPostTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,42 @@ function pressEditOnToast(TestableComponent $screen, int $writeId): TestableComp
return $screen->emitNative(ToastActionPressed::class, ['toastId' => 'toast-1', 'actionId' => 'edit', 'data' => ['write' => $writeId]]);
}

it('offers Commit in the header, leaving Share alone in the bar', function () {
/**
* The guild page's nav bar actions, left to right, by id. The ⋯ menu's items aren't in it.
*
* @return array<string, array<string, mixed>>
*/
function guildBar(TestableComponent $screen): array
{
return collect($screen->tree()['children'] ?? [])
->filter(fn (array $node): bool => ($node['type'] ?? null) === 'top_bar_action')
->mapWithKeys(fn (array $node): array => [$node['props']['id'] => $node])
->all();
}

it('offers New commit in the bar before the ⋯, as the Log does, and not in the header', function (string $platform) {
fakeApi(['GET /api/v1/guilds/rust' => [boardOf(['c1'])]]);

$screen = finishRefreshes(Native::visit('/log/guilds/rust'))->tap('guild-commit');
$screen = finishRefreshes(Native::visit('/log/guilds/rust', platform: $platform));
$compose = guildBar($screen)['compose'] ?? null;

expect(treeShows(nodeByRef($screen, 'guild-commit'), 'Commit'))->toBeTrue()
->and(hasTopBarAction($screen, 'share'))->toBeTrue()
->and(hasTopBarAction($screen, 'compose'))->toBeFalse()
->and($screen->instance()->sheetOpen)->toBeTrue();
});
expect(array_keys(guildBar($screen)))->toBe(['compose', 'more'])
->and($compose['props'] ?? null)->toMatchArray(['icon' => 'custom:square-pen', 'a11y_label' => 'New commit in #rust'])
->and(rendersRef($screen, 'guild-commit'))->toBeFalse();

// Pressed as the nav bar does, at the action's own callback.
$screen->fireEvent('composeForGuild', TestableComponent::EVENT_PRESS, ['callback_id' => $compose['on_press']]);

expect($screen->instance()->sheetOpen)->toBeTrue()
->and(nodeByRef($screen, 'sheet')['props']['visible'])->toBeTrue();
})->with(['ios', 'android']);

it('offers no Commit on a paused guild, as the web has no composer there', function () {
it('offers no New commit on a paused guild, as the web has no composer there', function () {
fakeApi(['GET /api/v1/guilds/rust' => [boardOf(['c1'], overrides: ['guild' => guildJson(['is_paused' => true])])]]);

$paused = finishRefreshes(Native::visit('/log/guilds/rust'))->call('composeForGuild');

expect(rendersRef($paused, 'guild-commit'))->toBeFalse()
expect(array_keys(guildBar($paused)))->toBe(['more'])
->and($paused->instance()->sheetOpen)->toBeFalse();
});

Expand Down
25 changes: 25 additions & 0 deletions tests/Feature/Screens/GuildTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use App\Devnull\Account;
use App\Devnull\Lane;
use App\NativeComponents\Guild;
use Illuminate\Http\Client\ConnectionException;
use Illuminate\Http\Client\Request;
Expand Down Expand Up @@ -165,6 +166,30 @@ function guildMeta(TestableComponent $screen): string
->and(kept('guilds/rust')['guild']['is_joined'])->toBeFalse();
});

it('draws Join in your colour on glass on iOS, and Leave on clear glass, both 40pt pills as on a profile', function (string $platform, bool $glass) {
fakeApi([
'GET /api/v1/guilds/rust' => [boardOf(['c1'])],
'POST /api/v1/guilds/rust/membership' => [null, 204],
]);

$screen = finishRefreshes(Native::visit('/log/guilds/rust', platform: $platform));
$pill = nodeByRef($screen, 'guild-join-pill');
$mine = config('native-ui.theme.light.'.Lane::token(app(Account::class)->user()?->lane()));

expect((float) $pill['layout']['height'])->toBe(40.0)
->and($pill['style']['bg_color'] ?? null)->toBe($mine)
->and(($pill['props']['glass'] ?? 0) !== 0)->toBe($glass)
->and(nodeByRef($screen, 'guild-join')['props'])->toMatchArray(['a11y_label' => 'Join', 'a11y_hint' => 'Joins #rust']);

$pill = nodeByRef($screen->tap('guild-join'), 'guild-join-pill');

expect(treeShows($pill, 'Leave'))->toBeTrue()
->and((float) $pill['layout']['height'])->toBe(40.0)
->and(($pill['props']['glass'] ?? 0) !== 0)->toBe($glass)
->and($pill['style']['bg_color'] ?? null)->toBe($glass ? null : config('native-ui.theme.light.surface-variant'))
->and(nodeByRef($screen, 'guild-join')['props'])->toMatchArray(['a11y_label' => 'Leave', 'a11y_hint' => 'Leaves #rust']);
})->with(['iOS' => ['ios', true], 'Android' => ['android', false]]);

it('offers Join on a paused guild', function () {
fakeApi(['GET /api/v1/guilds/rust' => [boardOf(['c1'], overrides: ['guild' => guildJson(['is_paused' => true])])]]);

Expand Down