2021-08-24 17:35:06 +02:00
|
|
|
import { get, writable } from "svelte/store";
|
2021-07-29 18:02:36 +02:00
|
|
|
import Timeout = NodeJS.Timeout;
|
2021-08-26 12:01:07 +02:00
|
|
|
import { userIsAdminStore } from "./GameStore";
|
|
|
|
import { CONTACT_URL } from "../Enum/EnvironmentVariable";
|
2021-09-16 18:12:51 +02:00
|
|
|
import { analyticsClient } from "../Administration/AnalyticsClient";
|
2021-05-12 18:32:55 +02:00
|
|
|
|
2021-08-09 14:49:17 +02:00
|
|
|
export const menuIconVisiblilityStore = writable(false);
|
|
|
|
export const menuVisiblilityStore = writable(false);
|
2021-09-15 11:50:25 +02:00
|
|
|
menuVisiblilityStore.subscribe((value) => {
|
|
|
|
if (value) analyticsClient.openedMenu();
|
2021-09-16 18:12:51 +02:00
|
|
|
});
|
2021-08-09 14:49:17 +02:00
|
|
|
export const menuInputFocusStore = writable(false);
|
2021-09-05 18:17:49 +02:00
|
|
|
export const userIsConnected = writable(false);
|
2021-07-29 18:02:36 +02:00
|
|
|
|
|
|
|
let warningContainerTimeout: Timeout | null = null;
|
|
|
|
function createWarningContainerStore() {
|
|
|
|
const { subscribe, set } = writable<boolean>(false);
|
|
|
|
|
|
|
|
return {
|
|
|
|
subscribe,
|
|
|
|
activateWarningContainer() {
|
|
|
|
set(true);
|
|
|
|
if (warningContainerTimeout) clearTimeout(warningContainerTimeout);
|
|
|
|
warningContainerTimeout = setTimeout(() => {
|
|
|
|
set(false);
|
|
|
|
warningContainerTimeout = null;
|
|
|
|
}, 120000);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export const warningContainerStore = createWarningContainerStore();
|
2021-08-11 14:07:34 +02:00
|
|
|
|
|
|
|
export enum SubMenusInterface {
|
|
|
|
settings = "Settings",
|
|
|
|
profile = "Profile",
|
|
|
|
createMap = "Create a Map",
|
|
|
|
aboutRoom = "About the Room",
|
|
|
|
globalMessages = "Global Messages",
|
|
|
|
contact = "Contact",
|
|
|
|
}
|
|
|
|
|
|
|
|
function createSubMenusStore() {
|
|
|
|
const { subscribe, update } = writable<string[]>([
|
|
|
|
SubMenusInterface.settings,
|
|
|
|
SubMenusInterface.profile,
|
|
|
|
SubMenusInterface.createMap,
|
|
|
|
SubMenusInterface.aboutRoom,
|
|
|
|
SubMenusInterface.globalMessages,
|
|
|
|
SubMenusInterface.contact,
|
|
|
|
]);
|
|
|
|
|
|
|
|
return {
|
|
|
|
subscribe,
|
|
|
|
addMenu(menuCommand: string) {
|
|
|
|
update((menuList: string[]) => {
|
|
|
|
if (!menuList.find((menu) => menu === menuCommand)) {
|
|
|
|
menuList.push(menuCommand);
|
|
|
|
}
|
|
|
|
return menuList;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
removeMenu(menuCommand: string) {
|
|
|
|
update((menuList: string[]) => {
|
|
|
|
const index = menuList.findIndex((menu) => menu === menuCommand);
|
|
|
|
if (index !== -1) {
|
|
|
|
menuList.splice(index, 1);
|
|
|
|
}
|
|
|
|
return menuList;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export const subMenusStore = createSubMenusStore();
|
2021-08-26 12:01:07 +02:00
|
|
|
|
2021-09-08 15:43:46 +02:00
|
|
|
export function checkSubMenuToShow() {
|
2021-08-26 12:01:07 +02:00
|
|
|
if (!get(userIsAdminStore)) {
|
|
|
|
subMenusStore.removeMenu(SubMenusInterface.globalMessages);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CONTACT_URL === undefined) {
|
|
|
|
subMenusStore.removeMenu(SubMenusInterface.contact);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-27 10:34:03 +02:00
|
|
|
export const customMenuIframe = new Map<string, { url: string; allowApi: boolean }>();
|
2021-08-24 17:35:06 +02:00
|
|
|
|
|
|
|
export function handleMenuRegistrationEvent(
|
|
|
|
menuName: string,
|
|
|
|
iframeUrl: string | undefined = undefined,
|
2021-08-27 10:34:03 +02:00
|
|
|
source: string | undefined = undefined,
|
|
|
|
options: { allowApi: boolean }
|
2021-08-24 17:35:06 +02:00
|
|
|
) {
|
|
|
|
if (get(subMenusStore).includes(menuName)) {
|
|
|
|
console.warn("The menu " + menuName + " already exist.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
subMenusStore.addMenu(menuName);
|
|
|
|
|
|
|
|
if (iframeUrl !== undefined) {
|
|
|
|
const url = new URL(iframeUrl, source);
|
2021-08-27 10:34:03 +02:00
|
|
|
customMenuIframe.set(menuName, { url: url.toString(), allowApi: options.allowApi });
|
2021-08-24 17:35:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function handleMenuUnregisterEvent(menuName: string) {
|
|
|
|
const subMenuGeneral: string[] = Object.values(SubMenusInterface);
|
|
|
|
if (subMenuGeneral.includes(menuName)) {
|
|
|
|
console.warn("The menu " + menuName + " is a mandatory menu. It can't be remove");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
subMenusStore.removeMenu(menuName);
|
|
|
|
customMenuIframe.delete(menuName);
|
|
|
|
}
|