Skip to content
Merged
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
4 changes: 4 additions & 0 deletions app/Http/Livewire/ShowArticles.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public function mount(): void
public function render(): View
{
$articles = Article::published();
$tags = Tag::whereHas('articles', function ($query) {
$query->published();
})->orderBy('name')->get();

if ($this->tag) {
$articles->forTag($this->tag);
Expand All @@ -39,6 +42,7 @@ public function render(): View

return view('livewire.show-articles', [
'articles' => $articles->paginate(10),
'tags' => $tags,
'selectedTag' => $this->tag,
'selectedSortBy' => $this->sortBy,
]);
Expand Down
13 changes: 10 additions & 3 deletions resources/views/livewire/show-articles.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
<div class="flex items-center justify-between mt-6">
<div class="flex items-center">
<div class="flex-shrink-0">
<a href="#">
<a href="{{ route('profile', $article->author()->username()) }}">
<img class="h-10 w-10 rounded-full" src="{{ $article->author()->gravatarUrl($avatarSize ?? 250) }}" alt="{{ $article->author()->name }}" />
</a>
</div>
<div class="ml-3">
<p class="text-sm leading-5 font-medium text-gray-900">
<a href="#">
<a href="{{ route('profile', $article->author()->username()) }}">
{{ $article->author()->name() }}
</a>
</p>
Expand Down Expand Up @@ -75,14 +75,21 @@
</button>
</span>

<a
href="{{ route('articles.create') }}"
class="button button-primary button-full mb-4"
>
Create Article
</a>

<ul class="tags">
<li class="{{ ! $selectedTag ? ' active' : '' }}">
<button wire:click="toggleTag('')">
All
</button>
</li>

@foreach (App\Models\Tag::whereHas('articles')->orderBy('name')->get() as $tag)
@foreach ($tags as $tag)
<li class="{{ $selectedTag === $tag->slug() ? ' active' : '' }}">
<button wire:click="toggleTag('{{ $tag->slug() }}')">
{{ $tag->name() }}
Expand Down
8 changes: 6 additions & 2 deletions resources/views/users/articles.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
@section('content')
<div class="container mx-auto px-4 py-8 flex flex-wrap flex-col-reverse lg:flex-row">
<div class="w-full md:w-3/4 md:pr-3">
@foreach($articles as $article)
@forelse($articles as $article)
<div class="pb-8 mb-8 border-b-2">
<div>
@if ($article->isNotPublished())
Expand Down Expand Up @@ -102,7 +102,11 @@
</div>
</div>
</div>
@endforeach
@empty
<p class="text-gray-600 text-base">
You haven't created any articles yet
</p>
@endforelse

{{ $articles->links() }}
</div>
Expand Down
14 changes: 14 additions & 0 deletions tests/Feature/ArticleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -618,4 +618,18 @@ public function users_get_a_mail_notification_when_their_article_is_approved()

Notification::assertSentTo($user, ArticleApprovedNotification::class);
}

/** @test */
public function tags_are_not_rendered_for_unpublished_articles()
{
$tag = factory(Tag::class)->create(['name' => 'Test Tag']);
$article = factory(Article::class)->create([
'slug' => 'my-first-article',
'submitted_at' => now()
]);
$article->syncTags([$tag->id]);

$this->get('/articles')
->dontSee('Test Tag');
}
}