migrated from redux to recoil

This commit is contained in:
2023-07-31 12:27:36 +02:00
parent 8327d1e94c
commit b5731759b0
36 changed files with 810 additions and 741 deletions

View File

@@ -2,27 +2,27 @@
import i18n from "../assets/i18n.yaml"
export default class I18nBuilder {
private language: string
private textMap = i18n.languages
private language: string
private textMap = i18n.languages
constructor(language: string) {
this.language = language
}
constructor(language: string) {
this.language = language
}
getLanguage(): string {
return this.language
}
getLanguage(): string {
return this.language
}
setLanguage(language: string): void {
this.language = language
}
setLanguage(language: string): void {
this.language = language
}
t(key: string): string {
const map = this.textMap[this.language]
if (map) {
const translation = map[key]
return translation ?? 'caption not defined'
}
return 'caption not defined'
t(key: string): string {
const map = this.textMap[this.language]
if (map) {
const translation = map[key]
return translation ?? 'caption not defined'
}
}
return 'caption not defined'
}
}

View File

@@ -1,15 +1,20 @@
import type { DLMetadata, RPCRequest, RPCResponse } from '../types'
import { webSocket } from 'rxjs/webSocket'
import { getHttpRPCEndpoint, getWebSocketEndpoint } from '../utils'
export const socket$ = webSocket<any>(getWebSocketEndpoint())
import { WebSocketSubject, webSocket } from 'rxjs/webSocket'
export class RPCClient {
private seq: number
private httpEndpoint: string
private _socket$: WebSocketSubject<any>
constructor() {
constructor(httpEndpoint: string, webSocketEndpoint: string) {
this.seq = 0
this.httpEndpoint = httpEndpoint
this._socket$ = webSocket<any>(webSocketEndpoint)
}
public get socket$() {
return this._socket$
}
private incrementSeq() {
@@ -17,14 +22,14 @@ export class RPCClient {
}
private send(req: RPCRequest) {
socket$.next({
this._socket$.next({
...req,
id: this.incrementSeq(),
})
}
private async sendHTTP<T>(req: RPCRequest) {
const res = await fetch(getHttpRPCEndpoint(), {
const res = await fetch(this.httpEndpoint, {
method: 'POST',
body: JSON.stringify({
...req,