fix: reverse power boolean

This commit is contained in:
Ben Allfree 2024-12-04 08:49:21 -08:00
parent 6569e5ad03
commit 966b3c8ce0
7 changed files with 21 additions and 14 deletions

View File

@ -12,7 +12,7 @@
const handlePowerChange = (id: InstanceId) => (e: Event) => {
const target = e.target as HTMLInputElement
const power = !target.checked
const power = target.checked
// Update the database with the new value
updateInstance({ id, fields: { power } })
@ -25,7 +25,7 @@
{#each values($globalInstancesStore).sort( (a, b) => a.subdomain.localeCompare(b.subdomain), ) as instance, index}
<button
class={`card min-w-80 lg:max-w-80 flex-1 m-4 transition hover:bg-base-300 ${instance.power ? 'bg-base-200' : 'bg-neutral'}`}
class={`card min-w-80 lg:max-w-80 flex-1 m-4 transition hover:bg-base-300 ${instance.power ? 'bg-neutral' : 'bg-base-200'}`}
on:click={(_) => goto(`/instances/${instance.id}`)}
>
<div class="card-body w-full">
@ -35,9 +35,9 @@
<input
type="checkbox"
class="toggle {instance.power
? 'bg-red-500 hover:bg-red-500'
: 'toggle-success'}"
checked={!instance.power}
? 'toggle-success'
: 'bg-red-500 hover:bg-red-500'}"
checked={instance.power}
on:click={(e) => e.stopPropagation()}
on:change={handlePowerChange(instance.id)}
/>
@ -46,7 +46,7 @@
<p class="text-left">
<span class="text-gray-400"
>Version {instance.version}
<span class={!instance.power ? 'hidden' : ''}>- Powered Off</span
<span class={instance.power ? 'hidden' : ''}>- Powered Off</span
></span
>
</p>

View File

@ -30,7 +30,7 @@
const { updateInstance } = client()
const handlePowerChange = (id: InstanceId) => (isChecked: boolean) => {
const power = !isChecked
const power = isChecked
// Update the database with the new value
updateInstance({ id, fields: { power } })
@ -78,13 +78,13 @@
<div>
<Toggle
checked={!$instance.power}
checked={$instance.power}
onChange={handlePowerChange($instance.id)}
/>
</div>
</div>
{#if $instance.power}
{#if !$instance.power}
<div class="px-4 mb-8">
<AlertBar
message="This instance is turned off and will not respond to requests"

View File

@ -65,7 +65,7 @@
<CardHeader documentation={`/docs/delete`}>Delete Instance</CardHeader>
{#if !power}
{#if power}
<AlertBar
message="Instance must be powered off before deleting."
type="error"

View File

@ -80,7 +80,7 @@
<CardHeader documentation={`/docs/upgrading`}>Version Change</CardHeader>
<div class="max-w-xl">
{#if !power}
{#if power}
<AlertBar
message="Your instance must be powered off to change the version."
type="error"
@ -147,7 +147,7 @@
<button
type="submit"
class="btn btn-error"
disabled={!power || isButtonDisabled}>Change Version</button
disabled={power || isButtonDisabled}>Change Version</button
>
</form>
</div>

View File

@ -166,7 +166,7 @@ export class PhFs implements FileSystem {
if (
instanceRootDir &&
POWERED_OFF_ONLY.includes(instanceRootDir) &&
!instance.power
instance.power
) {
throw new Error(`Instance must be powered off first`)
}

View File

@ -0,0 +1,7 @@
/// <reference path="../src/types/types.d.ts" />
migrate(
(db) => {
db.newQuery('UPDATE instances SET power = not power').execute()
},
(db) => {},
)

View File

@ -346,7 +346,7 @@ export const instanceService = mkSingleton(
power check
*/
dbg(`Checking for power`)
if (instance.power) {
if (!instance.power) {
throw new Error(
`This instance is powered off. See ${DOC_URL(
`power`,