feat: Add edit/create/list
sight page
This commit is contained in:
87
src/shared/store/SightsStore/index.tsx
Normal file
87
src/shared/store/SightsStore/index.tsx
Normal file
@ -0,0 +1,87 @@
|
||||
import { authInstance } from "@shared";
|
||||
import { makeAutoObservable, runInAction } from "mobx";
|
||||
|
||||
export type Language = "ru" | "en" | "zh";
|
||||
|
||||
export type MultilingualContent = {
|
||||
[key in Language]: {
|
||||
name: string;
|
||||
description: string;
|
||||
address: string;
|
||||
// Add other fields that need to be multilingual
|
||||
};
|
||||
};
|
||||
|
||||
export type Sight = {
|
||||
id: number;
|
||||
name: string;
|
||||
city_id: number;
|
||||
city: string;
|
||||
address: string;
|
||||
latitude: number;
|
||||
longitude: number;
|
||||
thumbnail: string | null;
|
||||
watermark_lu: string | null;
|
||||
watermark_rd: string | null;
|
||||
left_article: number;
|
||||
preview_media: string;
|
||||
video_preview: string | null;
|
||||
};
|
||||
|
||||
class SightsStore {
|
||||
sights: Sight[] = [];
|
||||
sight: Sight | null = null;
|
||||
cachedMultilingualContent: MultilingualContent | null = null;
|
||||
|
||||
constructor() {
|
||||
makeAutoObservable(this);
|
||||
}
|
||||
|
||||
getSights = async () => {
|
||||
const response = await authInstance.get("/sight");
|
||||
runInAction(() => {
|
||||
this.sights = response.data;
|
||||
});
|
||||
};
|
||||
|
||||
getSight = async (id: number) => {
|
||||
const response = await authInstance.get(`/sight/${id}`);
|
||||
|
||||
runInAction(() => {
|
||||
this.sight = response.data;
|
||||
});
|
||||
};
|
||||
|
||||
setCachedMultilingualContent = (content: MultilingualContent) => {
|
||||
runInAction(() => {
|
||||
this.cachedMultilingualContent = content;
|
||||
});
|
||||
};
|
||||
|
||||
updateCachedLanguageContent = (
|
||||
language: Language,
|
||||
content: Partial<MultilingualContent[Language]>
|
||||
) => {
|
||||
runInAction(() => {
|
||||
if (!this.cachedMultilingualContent) {
|
||||
this.cachedMultilingualContent = {
|
||||
ru: { name: "", description: "", address: "" },
|
||||
en: { name: "", description: "", address: "" },
|
||||
zh: { name: "", description: "", address: "" },
|
||||
};
|
||||
}
|
||||
this.cachedMultilingualContent[language] = {
|
||||
...this.cachedMultilingualContent[language],
|
||||
...content,
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
clearCachedMultilingualContent = () => {
|
||||
runInAction(() => {
|
||||
this.cachedMultilingualContent = null;
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export const sightsStore = new SightsStore();
|
Reference in New Issue
Block a user