Add Map page with basic logic

This commit is contained in:
2025-06-02 18:02:02 +03:00
parent a8777a974a
commit 5814e65953
15 changed files with 2576 additions and 132 deletions

View File

@ -10,7 +10,7 @@ type Media = {
class MediaStore {
media: Media[] = [];
oneMedia: Media | null = null;
constructor() {
makeAutoObservable(this);
}
@ -22,6 +22,60 @@ class MediaStore {
this.media = [...response.data];
});
};
deleteMedia = async (id: string) => {
await authInstance.delete(`/media/${id}`);
this.media = this.media.filter((media) => media.id !== id);
};
getOneMedia = async (id: string) => {
this.oneMedia = null;
const response = await authInstance.get(`/media/${id}`);
runInAction(() => {
this.oneMedia = response.data;
});
};
updateMedia = async (id: string, data: Partial<Media>) => {
const response = await authInstance.patch(`/media/${id}`, data);
runInAction(() => {
// Update in media array
const index = this.media.findIndex((m) => m.id === id);
if (index !== -1) {
this.media[index] = { ...this.media[index], ...response.data };
}
// Update oneMedia if it's the current media being viewed
if (this.oneMedia?.id === id) {
this.oneMedia = { ...this.oneMedia, ...response.data };
}
});
return response.data;
};
updateMediaFile = async (id: string, file: File, filename: string) => {
const formData = new FormData();
formData.append("file", file);
formData.append("filename", filename);
const response = await authInstance.patch(`/media/${id}/file`, formData, {
headers: {
"Content-Type": "multipart/form-data",
},
});
runInAction(() => {
// Update in media array
const index = this.media.findIndex((m) => m.id === id);
if (index !== -1) {
this.media[index] = { ...this.media[index], ...response.data };
}
// Update oneMedia if it's the current media being viewed
if (this.oneMedia?.id === id) {
this.oneMedia = { ...this.oneMedia, ...response.data };
}
});
return response.data;
};
}
export const mediaStore = new MediaStore();

View File

@ -1,7 +1,7 @@
import { API_URL, authInstance } from "@shared";
import { makeAutoObservable } from "mobx";
type Vehicle = {
export type Vehicle = {
vehicle: {
id: number;
tail_number: number;