Skip to content

Commit 27eeb66

Browse files
committed
✨ modification des composants Livewire pour les articles
1 parent a39885f commit 27eeb66

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

app/Http/Livewire/Articles/Browse.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,25 @@ class Browse extends Component
1313
{
1414
use WithInfiniteScroll, WithTags;
1515

16+
public string $viewMode = 'list';
17+
1618
protected $queryString = [
1719
'tag' => ['except' => ''],
1820
'sortBy' => ['except' => 'recent'],
1921
];
2022

23+
public function mount()
24+
{
25+
$this->viewMode = session('viewMode', $this->viewMode);
26+
}
27+
28+
public function changeViewMode($mode)
29+
{
30+
session()->put('viewMode', $mode);
31+
32+
$this->viewMode = $mode;
33+
}
34+
2135
public function validSort($sort): bool
2236
{
2337
return in_array($sort, [
@@ -29,10 +43,11 @@ public function validSort($sort): bool
2943

3044
public function render(): View
3145
{
32-
$articles = Article::with('tags')->published()
46+
$articles = Article::with('tags')
47+
->published()
3348
->notPinned()
3449
->orderByDesc('sponsored_at')
35-
->orderByDesc('submitted_at');
50+
->orderByDesc('published_at');
3651

3752
$tags = Tag::whereHas('articles', function ($query) {
3853
$query->published();

app/Http/Livewire/Articles/Create.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
use App\Models\User;
1010
use App\Traits\WithArticleAttributes;
1111
use App\Traits\WithTagsAssociation;
12+
use Illuminate\Contracts\View\View;
1213
use Illuminate\Support\Facades\Auth;
14+
use Illuminate\Support\Str;
1315
use Livewire\Component;
1416
use Livewire\WithFileUploads;
1517

@@ -24,15 +26,11 @@ public function mount()
2426
/** @var User $user */
2527
$user = Auth::user();
2628

29+
$this->published_at = now()->toDateTimeLocalString();
2730
$this->submitted_at = $user->hasAnyRole(['admin', 'moderator']) ? now() : null;
2831
$this->approved_at = $user->hasAnyRole(['admin', 'moderator']) ? now() : null;
2932
}
3033

31-
public function onMarkdownUpdate(string $content)
32-
{
33-
$this->body = $content;
34-
}
35-
3634
public function submit()
3735
{
3836
$this->submitted_at = now();
@@ -83,7 +81,7 @@ public function store()
8381
$this->redirectRoute('articles.show', $article);
8482
}
8583

86-
public function render()
84+
public function render(): View
8785
{
8886
return view('livewire.articles.create', [
8987
'tags' => Tag::whereJsonContains('concerns', ['post'])->get(),

app/Http/Livewire/Articles/Edit.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@ public function mount(Article $article)
3838
$this->associateTags = $this->tags_selected = old('tags', $article->tags()->pluck('id')->toArray());
3939
}
4040

41-
public function onMarkdownUpdate(string $content)
42-
{
43-
$this->body = $content;
44-
}
45-
4641
public function submit()
4742
{
4843
$this->alreadySubmitted = $this->article->submitted_at !== null;

0 commit comments

Comments
 (0)