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",
|
2021-11-12 12:13:44 +01:00
|
|
|
invite = "Invite",
|
|
|
|
aboutRoom = "Credit",
|
2021-08-11 14:07:34 +02:00
|
|
|
globalMessages = "Global Messages",
|
|
|
|
contact = "Contact",
|
|
|
|
}
|
|
|
|
|
|
|
|
function createSubMenusStore() {
|
|
|
|
const { subscribe, update } = writable<string[]>([
|
|
|
|
SubMenusInterface.profile,
|
|
|
|
SubMenusInterface.globalMessages,
|
|
|
|
SubMenusInterface.contact,
|
2021-11-12 12:13:44 +01:00
|
|
|
SubMenusInterface.settings,
|
|
|
|
SubMenusInterface.invite,
|
|
|
|
SubMenusInterface.aboutRoom,
|
2021-08-11 14:07:34 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
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-21 20:24:53 +02:00
|
|
|
export const contactPageStore = writable<string | undefined>(CONTACT_URL);
|
|
|
|
|
2021-09-08 15:43:46 +02:00
|
|
|
export function checkSubMenuToShow() {
|
2021-09-21 20:24:53 +02:00
|
|
|
subMenusStore.removeMenu(SubMenusInterface.globalMessages);
|
|
|
|
subMenusStore.removeMenu(SubMenusInterface.contact);
|
|
|
|
|
|
|
|
if (get(userIsAdminStore)) {
|
|
|
|
subMenusStore.addMenu(SubMenusInterface.globalMessages);
|
2021-08-26 12:01:07 +02:00
|
|
|
}
|
|
|
|
|
2021-09-21 20:24:53 +02:00
|
|
|
if (get(contactPageStore) !== undefined) {
|
|
|
|
subMenusStore.addMenu(SubMenusInterface.contact);
|
2021-08-26 12:01:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|