webstudio/ui/src/features/create_project/create_project_store.ts

51 lines
1.2 KiB
TypeScript

import makeAutoObservable from "mobx-store-inheritance";
import { CreateProjectRepository } from "./create_project_repository";
import { message } from "antd";
import { SimpleErrorState } from "../../core/store/base_store";
export class CreateProjectStore extends SimpleErrorState {
repository: CreateProjectRepository;
newProjectDescription: string = "";
file?: File;
constructor(repository: CreateProjectRepository) {
super();
this.repository = repository;
makeAutoObservable(this);
}
async init() {}
setDescriptionToNewProject(value: string): void {
this.newProjectDescription = value;
}
async saveProject(): Promise<void> {
if (this.newProjectDescription.isEmpty()) {
message.error("project description is not empty");
return;
}
if (this.file === undefined) {
message.error("upload file");
return;
}
this.isLoading = true;
(
await this.repository.saveProject({
description: this.newProjectDescription,
})
).fold(
(uuid) => {
this.newProjectDescription = "";
this.isLoading = false;
this.repository.setProjectRootFile(this.file as File, uuid.id);
},
(_) => {
this.isError = true;
}
);
//
}
}