|
@@ -4,7 +4,7 @@ import { api } from "@/api"
|
|
import router from "@/router"
|
|
import router from "@/router"
|
|
import { getLocalToken, removeLocalToken, saveLocalToken } from "@/utils";
|
|
import { getLocalToken, removeLocalToken, saveLocalToken } from "@/utils";
|
|
import type { AppNotification } from '@/interfaces';
|
|
import type { AppNotification } from '@/interfaces';
|
|
-import type { IUserProfile, IUserProfileCreate, IUserProfileUpdate, MainState } from '@/interfaces';
|
|
|
|
|
|
+import type { IUserProfile, IUserProfileCreate, IUserProfileUpdate, MainState, Video} from '@/interfaces';
|
|
|
|
|
|
const defaultState: MainState = {
|
|
const defaultState: MainState = {
|
|
isLoggedIn: null,
|
|
isLoggedIn: null,
|
|
@@ -14,6 +14,7 @@ const defaultState: MainState = {
|
|
dashboardMiniDrawer: false,
|
|
dashboardMiniDrawer: false,
|
|
dashboardShowDrawer: true,
|
|
dashboardShowDrawer: true,
|
|
notifications: [],
|
|
notifications: [],
|
|
|
|
+ videos: [],
|
|
};
|
|
};
|
|
|
|
|
|
export const useMainStore = defineStore("MainStoreId", {
|
|
export const useMainStore = defineStore("MainStoreId", {
|
|
@@ -29,6 +30,7 @@ export const useMainStore = defineStore("MainStoreId", {
|
|
readToken: (state) => state.token,
|
|
readToken: (state) => state.token,
|
|
readIsLoggedIn: (state) => state.isLoggedIn,
|
|
readIsLoggedIn: (state) => state.isLoggedIn,
|
|
readFirstNotification: (state) => state.notifications.length > 0 && state.notifications[0],
|
|
readFirstNotification: (state) => state.notifications.length > 0 && state.notifications[0],
|
|
|
|
+ readVideos: (state) => state.videos,
|
|
},
|
|
},
|
|
|
|
|
|
actions:{
|
|
actions:{
|
|
@@ -39,6 +41,7 @@ export const useMainStore = defineStore("MainStoreId", {
|
|
setUserProfile(payload: IUserProfile) { this.userProfile = payload },
|
|
setUserProfile(payload: IUserProfile) { this.userProfile = payload },
|
|
setDashboardMiniDrawer(payload: boolean) { this.dashboardMiniDrawer = payload; },
|
|
setDashboardMiniDrawer(payload: boolean) { this.dashboardMiniDrawer = payload; },
|
|
setDashboardShowDrawer(payload: boolean) { this.dashboardShowDrawer = payload; },
|
|
setDashboardShowDrawer(payload: boolean) { this.dashboardShowDrawer = payload; },
|
|
|
|
+ setVideos(payload: Video[]) {this.videos = payload},
|
|
addNotification(payload: AppNotification) { this.notifications.push(payload); },
|
|
addNotification(payload: AppNotification) { this.notifications.push(payload); },
|
|
removeNotification(payload: AppNotification) {
|
|
removeNotification(payload: AppNotification) {
|
|
if (payload) {
|
|
if (payload) {
|
|
@@ -225,6 +228,37 @@ export const useMainStore = defineStore("MainStoreId", {
|
|
});
|
|
});
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
+ async uploadPlot(title: string, file: File) {
|
|
|
|
+ const mainStore = useMainStore();
|
|
|
|
+ try {
|
|
|
|
+ const loadingNotification = { content: "sending", showProgress: true };
|
|
|
|
+ mainStore.addNotification(loadingNotification);
|
|
|
|
+ const response = (
|
|
|
|
+ await Promise.all([
|
|
|
|
+ api.uploadPlot(mainStore.token, title, file),
|
|
|
|
+ await new Promise<void>((resolve, _) => setTimeout(() => resolve(), 500)),
|
|
|
|
+ ])
|
|
|
|
+ );
|
|
|
|
+ mainStore.removeNotification(loadingNotification);
|
|
|
|
+ mainStore.addNotification({
|
|
|
|
+ content: "File received",
|
|
|
|
+ color: "success",
|
|
|
|
+ })
|
|
|
|
+ } catch (error) {
|
|
|
|
+ await mainStore.checkApiError(error);
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ async actionGetVideos() {
|
|
|
|
+ const mainStore = useMainStore();
|
|
|
|
+ try {
|
|
|
|
+ const response = await api.getVideos(mainStore.token)
|
|
|
|
+ if (response) {
|
|
|
|
+ this.setVideos(response.data);
|
|
|
|
+ }
|
|
|
|
+ } catch (error) {
|
|
|
|
+ await mainStore.checkApiError(error);
|
|
|
|
+ }
|
|
|
|
+ },
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|