mirror of
https://github.com/NyaaStudios/nyaabooru.git
synced 2025-12-10 05:42:58 +00:00
add models, setup livewire, setup mongodb
This commit is contained in:
parent
c0590a3412
commit
be4c848eee
27 changed files with 2508 additions and 0 deletions
81
app/Livewire/Posts/Edit.php
Normal file
81
app/Livewire/Posts/Edit.php
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
|
||||
namespace App\Livewire\Posts;
|
||||
|
||||
use App\Models\Post;
|
||||
use App\Models\Tag;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Livewire\Attributes\Validate;
|
||||
use Livewire\Component;
|
||||
|
||||
class Edit extends Component
|
||||
{
|
||||
public Post $post;
|
||||
public Collection $tags;
|
||||
public Collection $selectableTags;
|
||||
|
||||
#[Validate('exists:tags,id')]
|
||||
public string $tag = '';
|
||||
|
||||
#[Validate('required|in:safe,suggestive,explicit')]
|
||||
public string $rating = 'unknown';
|
||||
|
||||
public $featured = false;
|
||||
|
||||
public string $deleteTagId = '';
|
||||
|
||||
public function mount(Post $post)
|
||||
{
|
||||
$this->post = $post;
|
||||
$this->tags = $post->tags;
|
||||
$this->rating = $post->rating;
|
||||
$this->featured = $post->featured;
|
||||
$this->selectableTags = Tag::whereDoesntHave('posts', function ($query) {
|
||||
$query->where('id', $this->post->id);
|
||||
})->get();
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.posts.edit')->title("Edit post {$this->post->id}");
|
||||
}
|
||||
|
||||
public function updated()
|
||||
{
|
||||
$this->validate();
|
||||
|
||||
if ($this->tag)
|
||||
{
|
||||
if ($tag = Tag::find($this->tag))
|
||||
{
|
||||
$this->post->tags()->attach($tag);
|
||||
if ($tag->implies)
|
||||
{
|
||||
foreach ($tag->implies as $implied_id)
|
||||
{
|
||||
if ($impliedTag = Tag::find($implied_id))
|
||||
{
|
||||
$this->post->tags()->attach($impliedTag);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->post->rating = $this->rating;
|
||||
if ($this->post->rating == 'safe')
|
||||
{
|
||||
$this->post->featured = $this->featured;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->post->featured = null;
|
||||
}
|
||||
$this->post->save();
|
||||
|
||||
$this->tags = $this->post->tags;
|
||||
$this->selectableTags = Tag::whereDoesntHave('posts', function ($query) {
|
||||
$query->where('id', $this->post->id);
|
||||
})->get();
|
||||
}
|
||||
}
|
||||
27
app/Livewire/Posts/Image.php
Normal file
27
app/Livewire/Posts/Image.php
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace App\Livewire\Posts;
|
||||
|
||||
use App\Models\Post;
|
||||
use Livewire\Component;
|
||||
|
||||
class Image extends Component
|
||||
{
|
||||
public Post $post;
|
||||
|
||||
public function placeholder()
|
||||
{
|
||||
return <<<'HTML'
|
||||
<div class="wa-stack" style="display: flex; align-items: center; justify-content: center; max-height: 80vh;">
|
||||
<div class="wa-frame wa-border-radius-l" style="max-inline-size: 100%;">
|
||||
<wa-spinner></wa-spinner>
|
||||
</div>
|
||||
</div>
|
||||
HTML;
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.posts.image');
|
||||
}
|
||||
}
|
||||
21
app/Livewire/Posts/Index.php
Normal file
21
app/Livewire/Posts/Index.php
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace App\Livewire\Posts;
|
||||
|
||||
use App\Models\Post;
|
||||
use Livewire\Attributes\Title;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithPagination;
|
||||
|
||||
class Index extends Component
|
||||
{
|
||||
use WithPagination;
|
||||
|
||||
#[Title('Posts')]
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.posts.index', [
|
||||
'posts' => Post::orderBy('created_at', 'desc')->paginate(25),
|
||||
]);
|
||||
}
|
||||
}
|
||||
26
app/Livewire/Posts/Thumbnail.php
Normal file
26
app/Livewire/Posts/Thumbnail.php
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace App\Livewire\Posts;
|
||||
|
||||
use App\Models\Post;
|
||||
use Livewire\Component;
|
||||
|
||||
class Thumbnail extends Component
|
||||
{
|
||||
public Post $post;
|
||||
|
||||
public function placeholder()
|
||||
{
|
||||
return <<<'HTML'
|
||||
<div style="display: flex; align-items: center; justify-content: center; width: 256px; height: 256px;">
|
||||
<wa-spinner style="font-size: 4rem;"></wa-spinner>
|
||||
</div>
|
||||
HTML;
|
||||
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.posts.thumbnail');
|
||||
}
|
||||
}
|
||||
22
app/Livewire/Posts/View.php
Normal file
22
app/Livewire/Posts/View.php
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace App\Livewire\Posts;
|
||||
|
||||
use App\Models\Post;
|
||||
use Livewire\Attributes\Validate;
|
||||
use Livewire\Component;
|
||||
|
||||
class View extends Component
|
||||
{
|
||||
public Post $post;
|
||||
|
||||
#[Validate('string|max:240')]
|
||||
public $comment = '';
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.posts.view', [
|
||||
// 'comments' => $this->post->comments
|
||||
])->title("Post {$this->post->id}");
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue