feat: snapshot realization update for polling usage
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { authInstance } from "@shared";
|
||||
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import { makeAutoObservable, runInAction } from "mobx";
|
||||
import {
|
||||
articlesStore,
|
||||
@@ -25,9 +25,18 @@ type Snapshot = {
|
||||
CreationTime: string;
|
||||
};
|
||||
|
||||
type SnapshotStatus = {
|
||||
ID: string;
|
||||
Status: string;
|
||||
Progress: number;
|
||||
Error: string;
|
||||
};
|
||||
|
||||
class SnapshotStore {
|
||||
snapshots: Snapshot[] = [];
|
||||
snapshot: Snapshot | null = null;
|
||||
lastRequestId: string | null = null;
|
||||
snapshotStatus: SnapshotStatus | null = null;
|
||||
|
||||
constructor() {
|
||||
makeAutoObservable(this);
|
||||
@@ -266,7 +275,27 @@ class SnapshotStore {
|
||||
};
|
||||
|
||||
createSnapshot = async (name: string) => {
|
||||
await authInstance.post(`/snapshots`, { name });
|
||||
this.lastRequestId = uuidv4();
|
||||
|
||||
const response = await authInstance.post(
|
||||
`/snapshots`,
|
||||
{ name },
|
||||
{ headers: { "X-Request-ID": this.lastRequestId } }
|
||||
);
|
||||
|
||||
// Не ждем здесь, так как статус будет загружен в компоненте
|
||||
// this.getSnapshotStatus(response.data.ID);
|
||||
|
||||
return response.data.ID;
|
||||
};
|
||||
|
||||
getSnapshotStatus = async (id: string) => {
|
||||
const response = await authInstance.get(`/snapshots/status/${id}`);
|
||||
|
||||
console.log(response.data);
|
||||
runInAction(() => {
|
||||
this.snapshotStatus = response.data;
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user