Scope power buttons to current server (#849)

* Scope setServerState to current server

* Use match statement

* Reset this
This commit is contained in:
Lance Pioch 2025-01-01 15:20:02 -05:00 committed by GitHub
parent 00ae3b8b61
commit 3a7ddfca5e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 6 deletions

View File

@ -75,17 +75,17 @@ class Console extends Page
Action::make('start')
->color('primary')
->size(ActionSize::ExtraLarge)
->action(fn () => $this->dispatch('setServerState', state: 'start'))
->action(fn () => $this->dispatch('setServerState', state: 'start', uuid: $server->uuid))
->disabled(fn () => $server->isInConflictState() || !$this->status->isStartable()),
Action::make('restart')
->color('gray')
->size(ActionSize::ExtraLarge)
->action(fn () => $this->dispatch('setServerState', state: 'restart'))
->action(fn () => $this->dispatch('setServerState', state: 'restart', uuid: $server->uuid))
->disabled(fn () => $server->isInConflictState() || !$this->status->isRestartable()),
Action::make('stop')
->color('danger')
->size(ActionSize::ExtraLarge)
->action(fn () => $this->dispatch('setServerState', state: 'stop'))
->action(fn () => $this->dispatch('setServerState', state: 'stop', uuid: $server->uuid))
->hidden(fn () => $this->status->isStartingOrStopping() || $this->status->isKillable())
->disabled(fn () => $server->isInConflictState() || !$this->status->isStoppable()),
Action::make('kill')
@ -95,7 +95,7 @@ class Console extends Page
->modalDescription('This can result in data corruption and/or data loss!')
->modalSubmitActionLabel('Kill Server')
->size(ActionSize::ExtraLarge)
->action(fn () => $this->dispatch('setServerState', state: 'kill'))
->action(fn () => $this->dispatch('setServerState', state: 'kill', uuid: $server->uuid))
->hidden(fn () => $server->isInConflictState() || !$this->status->isKillable()),
];
}

View File

@ -167,14 +167,19 @@
}));
};
Livewire.on('setServerState', ({ state }) => {
Livewire.on('setServerState', ({ state, uuid }) => {
const serverUuid = "{{ $this->server->uuid }}";
if (uuid !== serverUuid) {
return;
}
socket.send(JSON.stringify({
'event': 'set state',
'args': [state]
}));
});
$wire.$on('sendServerCommand', ({ command }) => {
$wire.on('sendServerCommand', ({ command }) => {
socket.send(JSON.stringify({
'event': 'send command',
'args': [command]