Skip to content

Commit

Permalink
Merge pull request #31 from pinkary-project/fix-pinned-label-bug
Browse files Browse the repository at this point in the history
Add pinnable property
  • Loading branch information
nunomaduro authored Mar 22, 2024
2 parents 9c3fe75 + fe9470f commit 0d742e4
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 3 deletions.
6 changes: 6 additions & 0 deletions app/Livewire/Questions/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ final class Index extends Component
*/
public int $perPage = 5;

/**
* Whether the pinned label should be displayed or not.
*/
#[Locked]
public bool $pinnable = false;

/**
* Load more questions.
*/
Expand Down
6 changes: 6 additions & 0 deletions app/Livewire/Questions/Show.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ final class Show extends Component
#[Locked]
public bool $inIndex = false;

/**
* Whether the pinned label should be displayed or not.
*/
#[Locked]
public bool $pinnable = false;

/**
* Refresh the component.
*/
Expand Down
7 changes: 6 additions & 1 deletion resources/views/livewire/questions/index.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<section class="mt-4 space-y-10">
@foreach ($questions as $question)
<livewire:questions.show :questionId="$question->id" :key="'question-' . $question->id" :inIndex="true" />
<livewire:questions.show
:questionId="$question->id"
:key="'question-' . $question->id"
:inIndex="true"
:pinnable="$pinnable"
/>
@endforeach

@if ($perPage < 100 && $questions->hasMorePages())
Expand Down
2 changes: 1 addition & 1 deletion resources/views/livewire/questions/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class="ml-1 mt-0.5 h-4 w-4 flex-shrink-0"
</div>
</a>
@endif
@if ($question->pinned && request()->routeIs('profile.show'))
@if ($question->pinned && $pinnable)
<div class="mb-2 flex items-center space-x-1 px-4 text-sm focus:outline-none">
<x-icons.pin class="h-4 w-4 text-slate-400" />
<span class="text-slate-400">Pinned</span>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/profile/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<div class="mt-3 border-t border-gray-800"></div>

<livewire:questions.create :toId="$user->id" />
<livewire:questions.index :userId="$user->id" />
<livewire:questions.index :userId="$user->id" :pinnable="true" />
</div>
</div>
</div>
Expand Down
23 changes: 23 additions & 0 deletions tests/Unit/Livewire/Questions/ShowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,26 @@

$response->assertDontSee('Pinned');
});

test('pinnable', function () {
$user = User::factory()->create();

$question = Question::factory()->create([
'to_id' => $user->id,
'pinned' => true,
]);

$component = Livewire::actingAs($user)->test(Show::class, [
'pinnable' => false,
'questionId' => $question->id,
]);

$component->assertDontSee('Pinned');

$component = Livewire::actingAs($user)->test(Show::class, [
'pinnable' => true,
'questionId' => $question->id,
]);

$component->assertSee('Pinned');
});

0 comments on commit 0d742e4

Please sign in to comment.