feat: Add more pages
This commit is contained in:
@ -25,10 +25,19 @@ class ArticlesStore {
|
||||
en: [],
|
||||
zh: [],
|
||||
};
|
||||
articleList: Article[] = [];
|
||||
articleData: Article | null = null;
|
||||
articleMedia: Media | null = null;
|
||||
articleLoading: boolean = false;
|
||||
|
||||
getArticleList = async () => {
|
||||
const response = await authInstance.get("/article");
|
||||
|
||||
runInAction(() => {
|
||||
this.articleList = response.data;
|
||||
});
|
||||
};
|
||||
|
||||
getArticles = async (language: Language) => {
|
||||
this.articleLoading = true;
|
||||
const response = await authInstance.get("/article");
|
||||
|
76
src/shared/store/CarrierStore/index.tsx
Normal file
76
src/shared/store/CarrierStore/index.tsx
Normal file
@ -0,0 +1,76 @@
|
||||
import { authInstance } from "@shared";
|
||||
import { makeAutoObservable, runInAction } from "mobx";
|
||||
|
||||
export type Carrier = {
|
||||
id: number;
|
||||
short_name: string;
|
||||
full_name: string;
|
||||
slogan: string;
|
||||
city: string;
|
||||
city_id: number;
|
||||
logo: string;
|
||||
main_color: string;
|
||||
left_color: string;
|
||||
right_color: string;
|
||||
};
|
||||
|
||||
class CarrierStore {
|
||||
carriers: Carrier[] = [];
|
||||
carrier: Carrier | null = null;
|
||||
constructor() {
|
||||
makeAutoObservable(this);
|
||||
}
|
||||
|
||||
getCarriers = async () => {
|
||||
const response = await authInstance.get("/carrier");
|
||||
|
||||
runInAction(() => {
|
||||
this.carriers = response.data;
|
||||
});
|
||||
};
|
||||
|
||||
deleteCarrier = async (id: number) => {
|
||||
await authInstance.delete(`/carrier/${id}`);
|
||||
|
||||
runInAction(() => {
|
||||
this.carriers = this.carriers.filter((carrier) => carrier.id !== id);
|
||||
});
|
||||
};
|
||||
|
||||
getCarrier = async (id: number) => {
|
||||
const response = await authInstance.get(`/carrier/${id}`);
|
||||
runInAction(() => {
|
||||
this.carrier = response.data;
|
||||
});
|
||||
return response.data;
|
||||
};
|
||||
|
||||
createCarrier = async (
|
||||
fullName: string,
|
||||
shortName: string,
|
||||
city: string,
|
||||
cityId: number,
|
||||
primaryColor: string,
|
||||
secondaryColor: string,
|
||||
accentColor: string,
|
||||
slogan: string,
|
||||
logoId: string
|
||||
) => {
|
||||
const response = await authInstance.post("/carrier", {
|
||||
full_name: fullName,
|
||||
short_name: shortName,
|
||||
city,
|
||||
city_id: cityId,
|
||||
primary_color: primaryColor,
|
||||
secondary_color: secondaryColor,
|
||||
accent_color: accentColor,
|
||||
slogan,
|
||||
logo: logoId,
|
||||
});
|
||||
runInAction(() => {
|
||||
this.carriers.push(response.data);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export const carrierStore = new CarrierStore();
|
@ -11,19 +11,53 @@ type City = {
|
||||
|
||||
class CityStore {
|
||||
cities: City[] = [];
|
||||
|
||||
city: City | null = null;
|
||||
constructor() {
|
||||
makeAutoObservable(this);
|
||||
}
|
||||
|
||||
getCities = async () => {
|
||||
if (this.cities.length !== 0) return;
|
||||
|
||||
const response = await authInstance.get("/city");
|
||||
|
||||
runInAction(() => {
|
||||
this.cities = response.data;
|
||||
});
|
||||
};
|
||||
|
||||
deleteCity = async (id: number) => {
|
||||
await authInstance.delete(`/city/${id}`);
|
||||
|
||||
runInAction(() => {
|
||||
this.cities = this.cities.filter((city) => city.id !== id);
|
||||
});
|
||||
};
|
||||
|
||||
getCity = async (id: string) => {
|
||||
const response = await authInstance.get(`/city/${id}`);
|
||||
|
||||
runInAction(() => {
|
||||
this.city = response.data;
|
||||
});
|
||||
|
||||
return response.data;
|
||||
};
|
||||
|
||||
createCity = async (
|
||||
name: string,
|
||||
country: string,
|
||||
countryCode: string,
|
||||
mediaId: string
|
||||
) => {
|
||||
const response = await authInstance.post("/city", {
|
||||
name: name,
|
||||
country: country,
|
||||
country_code: countryCode,
|
||||
arms: mediaId,
|
||||
});
|
||||
runInAction(() => {
|
||||
this.cities.push(response.data);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export const cityStore = new CityStore();
|
||||
|
49
src/shared/store/CountryStore/index.ts
Normal file
49
src/shared/store/CountryStore/index.ts
Normal file
@ -0,0 +1,49 @@
|
||||
import { authInstance } from "@shared";
|
||||
import { makeAutoObservable, runInAction } from "mobx";
|
||||
|
||||
export type Country = {
|
||||
code: string;
|
||||
name: string;
|
||||
};
|
||||
|
||||
class CountryStore {
|
||||
countries: Country[] = [];
|
||||
country: Country | null = null;
|
||||
|
||||
constructor() {
|
||||
makeAutoObservable(this);
|
||||
}
|
||||
|
||||
getCountries = async () => {
|
||||
const response = await authInstance.get("/country");
|
||||
|
||||
runInAction(() => {
|
||||
this.countries = response.data;
|
||||
});
|
||||
};
|
||||
|
||||
getCountry = async (code: string) => {
|
||||
const response = await authInstance.get(`/country/${code}`);
|
||||
|
||||
runInAction(() => {
|
||||
this.country = response.data;
|
||||
});
|
||||
};
|
||||
|
||||
deleteCountry = async (code: string) => {
|
||||
await authInstance.delete(`/country/${code}`);
|
||||
|
||||
runInAction(() => {
|
||||
this.countries = this.countries.filter(
|
||||
(country) => country.code !== code
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
createCountry = async (code: string, name: string) => {
|
||||
await authInstance.post("/country", { code: code, name: name });
|
||||
await this.getCountries();
|
||||
};
|
||||
}
|
||||
|
||||
export const countryStore = new CountryStore();
|
@ -76,6 +76,16 @@ class MediaStore {
|
||||
});
|
||||
return response.data;
|
||||
};
|
||||
|
||||
createMedia = async (name: string, type: string) => {
|
||||
const response = await authInstance.post("/media", {
|
||||
media_name: name,
|
||||
media_type: type,
|
||||
});
|
||||
runInAction(() => {
|
||||
this.media.push(response.data);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export const mediaStore = new MediaStore();
|
||||
|
45
src/shared/store/RouteStore/index.ts
Normal file
45
src/shared/store/RouteStore/index.ts
Normal file
@ -0,0 +1,45 @@
|
||||
import { makeAutoObservable, runInAction } from "mobx";
|
||||
import { authInstance } from "@shared";
|
||||
|
||||
export type Route = {
|
||||
carrier: string;
|
||||
carrier_id: number;
|
||||
center_latitude: number;
|
||||
center_longitude: number;
|
||||
governor_appeal: number;
|
||||
id: number;
|
||||
path: number[][];
|
||||
rotate: number;
|
||||
route_direction: boolean;
|
||||
route_number: string;
|
||||
route_sys_number: string;
|
||||
scale_max: number;
|
||||
scale_min: number;
|
||||
video_preview: string;
|
||||
};
|
||||
|
||||
class RouteStore {
|
||||
routes: Route[] = [];
|
||||
|
||||
constructor() {
|
||||
makeAutoObservable(this);
|
||||
}
|
||||
|
||||
getRoutes = async () => {
|
||||
const response = await authInstance.get("/route");
|
||||
|
||||
runInAction(() => {
|
||||
this.routes = response.data;
|
||||
});
|
||||
};
|
||||
|
||||
deleteRoute = async (id: number) => {
|
||||
await authInstance.delete(`/route/${id}`);
|
||||
|
||||
runInAction(() => {
|
||||
this.routes = this.routes.filter((route) => route.id !== id);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export const routeStore = new RouteStore();
|
@ -219,6 +219,11 @@ class SightsStore {
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
deleteListSight = async (id: number) => {
|
||||
await authInstance.delete(`/sight/${id}`);
|
||||
this.sights = this.sights.filter((sight) => sight.id !== id);
|
||||
};
|
||||
}
|
||||
|
||||
export const sightsStore = new SightsStore();
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { authInstance } from "@shared";
|
||||
import { API_URL } from "@shared";
|
||||
import { makeAutoObservable } from "mobx";
|
||||
|
||||
import { makeAutoObservable, runInAction } from "mobx";
|
||||
|
||||
type Snapshot = {
|
||||
ID: string;
|
||||
@ -11,14 +11,42 @@ type Snapshot = {
|
||||
|
||||
class SnapshotStore {
|
||||
snapshots: Snapshot[] = [];
|
||||
snapshot: Snapshot | null = null;
|
||||
|
||||
constructor() {
|
||||
makeAutoObservable(this);
|
||||
}
|
||||
|
||||
getSnapshots = async () => {
|
||||
const response = await authInstance.get(`${API_URL}/snapshots`);
|
||||
this.snapshots = response.data;
|
||||
const response = await authInstance.get(`/snapshots`);
|
||||
|
||||
runInAction(() => {
|
||||
this.snapshots = response.data;
|
||||
});
|
||||
};
|
||||
|
||||
deleteSnapshot = async (id: string) => {
|
||||
await authInstance.delete(`/snapshots/${id}`);
|
||||
|
||||
runInAction(() => {
|
||||
this.snapshots = this.snapshots.filter((snapshot) => snapshot.ID !== id);
|
||||
});
|
||||
};
|
||||
|
||||
getSnapshot = async (id: string) => {
|
||||
const response = await authInstance.get(`/snapshots/${id}`);
|
||||
|
||||
runInAction(() => {
|
||||
this.snapshot = response.data;
|
||||
});
|
||||
};
|
||||
|
||||
restoreSnapshot = async (id: string) => {
|
||||
await authInstance.post(`/snapshots/${id}/restore`);
|
||||
};
|
||||
|
||||
createSnapshot = async (name: string) => {
|
||||
await authInstance.post(`/snapshots`, { name });
|
||||
};
|
||||
}
|
||||
|
||||
|
76
src/shared/store/StationsStore/index.ts
Normal file
76
src/shared/store/StationsStore/index.ts
Normal file
@ -0,0 +1,76 @@
|
||||
import { authInstance } from "@shared";
|
||||
import { makeAutoObservable, runInAction } from "mobx";
|
||||
|
||||
type Station = {
|
||||
id: number;
|
||||
address: string;
|
||||
city: string;
|
||||
city_id: number;
|
||||
description: string;
|
||||
direction: boolean;
|
||||
icon: string;
|
||||
latitude: number;
|
||||
longitude: number;
|
||||
name: string;
|
||||
offset_x: number;
|
||||
offset_y: number;
|
||||
system_name: string;
|
||||
transfers: {
|
||||
bus: string;
|
||||
metro_blue: string;
|
||||
metro_green: string;
|
||||
metro_orange: string;
|
||||
metro_purple: string;
|
||||
metro_red: string;
|
||||
train: string;
|
||||
tram: string;
|
||||
trolleybus: string;
|
||||
};
|
||||
};
|
||||
|
||||
class StationsStore {
|
||||
stations: Station[] = [];
|
||||
station: Station | null = null;
|
||||
|
||||
constructor() {
|
||||
makeAutoObservable(this);
|
||||
}
|
||||
|
||||
getStations = async () => {
|
||||
const response = await authInstance.get("/station");
|
||||
|
||||
runInAction(() => {
|
||||
this.stations = response.data;
|
||||
});
|
||||
};
|
||||
|
||||
deleteStation = async (id: number) => {
|
||||
await authInstance.delete(`/station/${id}`);
|
||||
|
||||
runInAction(() => {
|
||||
this.stations = this.stations.filter((station) => station.id !== id);
|
||||
});
|
||||
};
|
||||
|
||||
getStation = async (id: number) => {
|
||||
const response = await authInstance.get(`/station/${id}`);
|
||||
this.station = response.data;
|
||||
};
|
||||
|
||||
createStation = async (
|
||||
name: string,
|
||||
systemName: string,
|
||||
direction: string
|
||||
) => {
|
||||
const response = await authInstance.post("/station", {
|
||||
station_name: name,
|
||||
system_name: systemName,
|
||||
direction,
|
||||
});
|
||||
runInAction(() => {
|
||||
this.stations.push(response.data);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export const stationsStore = new StationsStore();
|
44
src/shared/store/UserStore/index.ts
Normal file
44
src/shared/store/UserStore/index.ts
Normal file
@ -0,0 +1,44 @@
|
||||
import { authInstance } from "@shared";
|
||||
import { makeAutoObservable, runInAction } from "mobx";
|
||||
|
||||
export type User = {
|
||||
id: number;
|
||||
email: string;
|
||||
is_admin: boolean;
|
||||
name: string;
|
||||
};
|
||||
|
||||
class UserStore {
|
||||
users: User[] = [];
|
||||
user: User | null = null;
|
||||
|
||||
constructor() {
|
||||
makeAutoObservable(this);
|
||||
}
|
||||
|
||||
getUsers = async () => {
|
||||
const response = await authInstance.get("/user");
|
||||
|
||||
runInAction(() => {
|
||||
this.users = response.data;
|
||||
});
|
||||
};
|
||||
|
||||
getUser = async (id: number) => {
|
||||
const response = await authInstance.get(`/user/${id}`);
|
||||
|
||||
runInAction(() => {
|
||||
this.user = response.data as User;
|
||||
});
|
||||
};
|
||||
|
||||
deleteUser = async (id: number) => {
|
||||
await authInstance.delete(`/users/${id}`);
|
||||
|
||||
runInAction(() => {
|
||||
this.users = this.users.filter((user) => user.id !== id);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export const userStore = new UserStore();
|
@ -1,4 +1,4 @@
|
||||
import { API_URL, authInstance } from "@shared";
|
||||
import { authInstance } from "@shared";
|
||||
import { makeAutoObservable } from "mobx";
|
||||
|
||||
export type Vehicle = {
|
||||
@ -22,15 +22,43 @@ export type Vehicle = {
|
||||
|
||||
class VehicleStore {
|
||||
vehicles: Vehicle[] = [];
|
||||
vehicle: Vehicle | null = null;
|
||||
|
||||
constructor() {
|
||||
makeAutoObservable(this);
|
||||
}
|
||||
|
||||
getVehicles = async () => {
|
||||
const response = await authInstance.get(`${API_URL}/vehicle`);
|
||||
const response = await authInstance.get(`/vehicle`);
|
||||
this.vehicles = response.data;
|
||||
};
|
||||
|
||||
deleteVehicle = async (id: number) => {
|
||||
await authInstance.delete(`/vehicle/${id}`);
|
||||
this.vehicles = this.vehicles.filter(
|
||||
(vehicle) => vehicle.vehicle.id !== id
|
||||
);
|
||||
};
|
||||
|
||||
getVehicle = async (id: number) => {
|
||||
const response = await authInstance.get(`/vehicle/${id}`);
|
||||
this.vehicle = response.data;
|
||||
};
|
||||
|
||||
createVehicle = async (
|
||||
tailNumber: number,
|
||||
type: string,
|
||||
carrier: string,
|
||||
carrierId: number
|
||||
) => {
|
||||
await authInstance.post("/vehicle", {
|
||||
tail_number: tailNumber,
|
||||
type,
|
||||
carrier,
|
||||
carrier_id: carrierId,
|
||||
});
|
||||
await this.getVehicles();
|
||||
};
|
||||
}
|
||||
|
||||
export const vehicleStore = new VehicleStore();
|
||||
|
@ -9,3 +9,8 @@ export * from "./ArticlesStore";
|
||||
export * from "./EditSightStore";
|
||||
export * from "./MediaStore";
|
||||
export * from "./CreateSightStore";
|
||||
export * from "./CountryStore";
|
||||
export * from "./RouteStore";
|
||||
export * from "./UserStore";
|
||||
export * from "./CarrierStore";
|
||||
export * from "./StationsStore";
|
||||
|
Reference in New Issue
Block a user