Skip to content
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

Refactored server implementation #292

Merged
merged 4 commits into from
Aug 8, 2023
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
2 changes: 1 addition & 1 deletion app/Http/Livewire/Server/ServerCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function mount(Server $server)

public function reactivate()
{
Artisan::call('ping:server '.$this->server->uuid.' true');
Artisan::call('server:ping '.$this->server->uuid.' true');
$this->server->active = true;
$this->server->save();
$this->emit('serverUpdated');
Expand Down
30 changes: 22 additions & 8 deletions app/Http/Livewire/Server/ServerCardList.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,42 @@ class ServerCardList extends Component
{
public $servers;

public $my_servers;

public $user;

protected $listeners = [
'serverUpdated' => 'update',
];

public function mount()
{
$this->servers = Server::orderBy('official', 'desc')
->orderBy('last_online_at', 'desc')
->orderBy('ping', 'asc')
->get();
$this->loadData();
}

public function update()
{
$this->servers = Server::orderBy('official', 'desc')
->orderBy('last_online_at', 'desc')
->orderBy('ping', 'asc')
->get();
$this->loadData();
}

public function render()
{
return view('livewire.server.server-card-list');
}

private function loadData(): void
{
$this->user = auth()->user() ?? null;
$this->servers = isset($this->user) ? Server::where('user_id', '!=', $this->user->id)
->where('active', true)
->orderBy('official', 'desc')
->orderBy('last_online_at', 'desc')
->orderBy('ping', 'asc')
->get() : Server::orderBy('official', 'desc')
->where('active', true)
->orderBy('last_online_at', 'desc')
->orderBy('ping', 'asc')
->get();
$this->my_servers = isset($this->user) ? Server::where('user_id', $this->user->id)->get() : collect();
}
}
17 changes: 12 additions & 5 deletions resources/views/livewire/server/server-card-list.blade.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
<div class="flex flex-col">
<div class="-my-2 sm:-mx-6 lg:-mx-8">
<p class="pt-4 pb-1 text-center text-gray-300 dark:text-gray-600">{{ __('All server statuses are updated every hour.') }}</p>
<div class="grid grid-cols-1 gap-4 sm:p-10 sm:grid-cols-2 md:grid-cols-3 auto-rows-auto grid-flow-rows">
@foreach ($this->servers as $server)
<p class="pt-4 pb-1 text-center text-gray-300 dark:text-gray-600">{{ __('All server statuses are updated every hour.') }}</p>
@if($this->my_servers->count() > 0)
<h1 class="text-xl text-gray-600 dark:text-gray-300">{{ __('Your servers') }}:</h1>
<div class="grid grid-cols-1 gap-4 sm:p-5 sm:grid-cols-2 md:grid-cols-3 auto-rows-auto grid-flow-rows">
@foreach($this->my_servers as $server)
@livewire('server.server-card', ['server' => $server])
@endforeach
</div>
<div class="border-t my-8 border-dotted border-gray-300 dark:border-gray-600"></div>
@endif
<div class="grid grid-cols-1 gap-4 sm:p-5 sm:grid-cols-2 md:grid-cols-3 auto-rows-auto grid-flow-rows">
@foreach($this->servers as $server)
@livewire('server.server-card', ['server' => $server])
@endforeach
</div>
</div>
</div>
Loading