Skip to content

Convert article overview to blade #763

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 24, 2021
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: 2 additions & 2 deletions app/Concerns/UsesFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

trait UsesFilters
{
public function getFilter(string $default = 'recent'): string
public function getFilter(array $options = ['recent', 'resolved', 'unresolved'], string $default = 'recent'): string
{
$filter = (string) request('filter');

return in_array($filter, ['recent', 'resolved', 'unresolved']) ? $filter : $default;
return in_array($filter, $options) ? $filter : $default;
}
}
31 changes: 27 additions & 4 deletions app/Http/Controllers/Articles/ArticlesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Controllers\Articles;

use App\Concerns\UsesFilters;
use App\Http\Controllers\Controller;
use App\Http\Middleware\Authenticate;
use App\Http\Requests\ArticleRequest;
Expand All @@ -19,28 +20,50 @@

class ArticlesController extends Controller
{
use UsesFilters;

public function __construct()
{
$this->middleware([Authenticate::class, EnsureEmailIsVerified::class], ['except' => ['index', 'show']]);
}

public function index(Request $request)
{
$filter = $this->getFilter(['recent', 'popular', 'trending']);

$pinnedArticles = Article::published()
->pinned()
->latest('submitted_at')
->take(4)
->get();

$articles = Article::published()
->notPinned()
->{$filter}();

$tags = Tag::whereHas('articles', function ($query) {
$query->published();
})->orderBy('name')->get();

if ($activeTag = Tag::where('slug', $request->tag)->first()) {
$articles->forTag($activeTag->slug());
}

$moderators = Cache::remember('moderators', now()->addMinutes(30), function () {
return User::moderators()->get();
});
$canonical = canonical('articles', $request->only('sortBy', 'tag'));

$canonical = canonical('articles', ['filter' => $filter, 'tag' => $activeTag?->slug()]);
$topAuthors = Cache::remember('topAuthors', now()->addMinutes(30), function () {
return User::mostSubmissionsInLastDays(365)->take(5)->get();
});

return view('articles.index', [
return view('articles.overview', [
'pinnedArticles' => $pinnedArticles,
'articles' => $articles->paginate(10),
'tags' => $tags,
'activeTag' => $activeTag,
'filter' => $filter,
'moderators' => $moderators,
'canonical' => $canonical,
'topAuthors' => $topAuthors,
Expand Down Expand Up @@ -74,7 +97,7 @@ public function create()
{
return view('articles.create', [
'tags' => Tag::all(),
'selectedTags' => old('tags', []),
'activeTags' => old('tags', []),
]);
}

Expand All @@ -94,7 +117,7 @@ public function edit(Article $article)
return view('articles.edit', [
'article' => $article,
'tags' => Tag::all(),
'selectedTags' => old('tags', $article->tags()->pluck('id')->toArray()),
'activeTags' => old('tags', $article->tags()->pluck('id')->toArray()),
]);
}

Expand Down
73 changes: 0 additions & 73 deletions app/Http/Livewire/ShowArticles.php

This file was deleted.

89 changes: 0 additions & 89 deletions resources/views/articles/index.blade.php

This file was deleted.

Loading