fix: address comments

This commit is contained in:
waterplea
2025-11-05 11:10:33 +04:00
parent 056a9ff9b6
commit e0995a63ca
5 changed files with 25 additions and 10 deletions

View File

@@ -52,6 +52,7 @@ import { getIp, DeviceData, MappedSubnet, subnetValidator } from './utils'
<select
tuiSelect
formControlName="subnet"
placeholder="Select Subnet"
[items]="context.data.subnets()"
></select>
} @else {
@@ -87,9 +88,7 @@ import { getIp, DeviceData, MappedSubnet, subnetValidator } from './utils'
}
}
<footer>
<button tuiButton (click)="onSave()" [disabled]="form.invalid">
Save
</button>
<button tuiButton (click)="onSave()">Save</button>
</footer>
</form>
`,
@@ -147,6 +146,7 @@ export class DevicesAdd {
protected async onSave() {
if (this.form.invalid) {
tuiMarkControlAsTouchedAndValidate(this.form)
return
}

View File

@@ -25,7 +25,9 @@ export interface DeviceData {
}
export function subnetValidator({ value }: AbstractControl<MappedSubnet>) {
return value && getIp(value) ? null : { noHosts: 'No hosts available' }
return !value?.clients || getIp(value)
? null
: { noHosts: 'No hosts available' }
}
export function getIp({ clients, range }: MappedSubnet) {

View File

@@ -39,6 +39,7 @@ import { MappedDevice, PortForwardsData } from './utils'
<select
tuiSelect
formControlName="externalip"
placeholder="Select IP"
[items]="context.data.ips()"
></select>
} @else {
@@ -76,6 +77,7 @@ import { MappedDevice, PortForwardsData } from './utils'
<select
tuiSelect
formControlName="device"
placeholder="Select Device"
[items]="context.data.devices()"
></select>
} @else {

View File

@@ -1,8 +1,20 @@
import { Injectable, signal } from '@angular/core'
import { effect, inject, Injectable, signal } from '@angular/core'
import { WA_LOCAL_STORAGE } from '@ng-web-apis/common'
const KEY = '_startos/tunnel-loggedIn'
@Injectable({
providedIn: 'root',
})
export class AuthService {
readonly authenticated = signal(false)
private readonly storage = inject(WA_LOCAL_STORAGE)
private readonly effect = effect(() => {
if (this.authenticated()) {
this.storage.setItem(KEY, JSON.stringify(true))
} else {
this.storage.removeItem(KEY)
}
})
readonly authenticated = signal(Boolean(this.storage.getItem(KEY)))
}

View File

@@ -1,4 +1,5 @@
import { Inject, Injectable, DOCUMENT } from '@angular/core'
import { inject, Injectable } from '@angular/core'
import { WA_LOCAL_STORAGE } from '@ng-web-apis/common'
const PREFIX = '_startos/'
@@ -6,9 +7,7 @@ const PREFIX = '_startos/'
providedIn: 'root',
})
export class StorageService {
private readonly storage = this.document.defaultView!.localStorage
constructor(@Inject(DOCUMENT) private readonly document: Document) {}
private readonly storage = inject(WA_LOCAL_STORAGE)
get<T>(key: string): T {
return JSON.parse(String(this.storage.getItem(`${PREFIX}${key}`)))