feat: Route list page
This commit is contained in:
@@ -19,17 +19,38 @@ export type Route = {
|
||||
};
|
||||
|
||||
class RouteStore {
|
||||
routes: Route[] = [];
|
||||
routes: {
|
||||
data: Route[];
|
||||
loaded: boolean;
|
||||
} = {
|
||||
data: [],
|
||||
loaded: false,
|
||||
};
|
||||
route: Record<string, Route> = {};
|
||||
|
||||
constructor() {
|
||||
makeAutoObservable(this);
|
||||
}
|
||||
|
||||
getRoutes = async () => {
|
||||
if (this.routes.loaded) return;
|
||||
const response = await authInstance.get("/route");
|
||||
|
||||
runInAction(() => {
|
||||
this.routes = response.data;
|
||||
this.routes = {
|
||||
data: response.data,
|
||||
loaded: true,
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
createRoute = async (route: any) => {
|
||||
const response = await authInstance.post("/route", route);
|
||||
const id = response.data.id;
|
||||
|
||||
runInAction(() => {
|
||||
this.route[id] = { ...route, id };
|
||||
this.routes.data = [...this.routes.data, { ...route, id }];
|
||||
});
|
||||
};
|
||||
|
||||
@@ -37,9 +58,12 @@ class RouteStore {
|
||||
await authInstance.delete(`/route/${id}`);
|
||||
|
||||
runInAction(() => {
|
||||
this.routes = this.routes.filter((route) => route.id !== id);
|
||||
this.routes = {
|
||||
data: this.routes.data.filter((route) => route.id !== id),
|
||||
loaded: true,
|
||||
};
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export const routeStore = new RouteStore();
|
||||
export const routeStore = new RouteStore();
|
||||
|
||||
Reference in New Issue
Block a user