mirror of
https://github.com/Eugeny/tabby-web.git
synced 2026-08-18 07:16:03 +01:00
25 lines
723 B
TypeScript
25 lines
723 B
TypeScript
|
|
import { Subject } from 'rxjs'
|
||
|
|
import { debounceTime } from 'rxjs/operators'
|
||
|
|
import { HttpClient } from '@angular/common/http'
|
||
|
|
import { Injectable } from '@angular/core'
|
||
|
|
|
||
|
|
@Injectable({ providedIn: 'root' })
|
||
|
|
export class AppConnectorService {
|
||
|
|
config: any
|
||
|
|
private configUpdate = new Subject<string>()
|
||
|
|
|
||
|
|
constructor (private http: HttpClient) {
|
||
|
|
this.configUpdate.pipe(debounceTime(1000)).subscribe(content => {
|
||
|
|
this.http.patch(`/api/1/configs/${this.config.id}`, { content }).toPromise()
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
async loadConfig (): Promise<string> {
|
||
|
|
return this.config.content
|
||
|
|
}
|
||
|
|
|
||
|
|
async saveConfig (content: string): Promise<void> {
|
||
|
|
this.configUpdate.next(content)
|
||
|
|
}
|
||
|
|
}
|