UNPKG

@tomino/dynamic-form-semantic-ui

Version:

Semantic UI form renderer based on dynamic form generation

84 lines (71 loc) 1.91 kB
import { IProject, IStorage } from './common_storage'; export class ServerStorage implements IStorage { url: string; token: string; constructor(url: string, token: 'jwtToken') { this.url = url; this.token = token; } async listProjects(): Promise<IProject[]> { const projects = await fetch(this.url, { method: 'post', headers: { Accept: 'application/json', 'Content-Type': 'application/json' }, //make sure to serialize your JSON body body: JSON.stringify({ action: 'list', token: localStorage.getItem(this.token) }) }); return projects.json(); } async loadProject(id: string = 'app'): Promise<IProject> { const project = await fetch(this.url, { method: 'post', headers: { Accept: 'application/json', 'Content-Type': 'application/json' }, //make sure to serialize your JSON body body: JSON.stringify({ action: 'load', token: localStorage.getItem(this.token), id }) }); return project.json(); } async deleteProject(id: string): Promise<void> { fetch(this.url, { method: 'post', headers: { Accept: 'application/json', 'Content-Type': 'application/json' }, //make sure to serialize your JSON body body: JSON.stringify({ action: 'delete', token: localStorage.getItem(this.token), id }) }); } saveProject(project: IProject): Promise<void> { fetch(this.url, { method: 'post', headers: { Accept: 'application/json', 'Content-Type': 'application/json' }, //make sure to serialize your JSON body body: JSON.stringify({ action: 'save', token: localStorage.getItem(this.token), project: JSON.stringify(project) }) }); return null; } }