From e2d77b66712993117f2469b8fb1887efbe8922d1 Mon Sep 17 00:00:00 2001 From: Ashley Date: Wed, 20 Sep 2023 04:16:17 +0100 Subject: [PATCH] refactor: Remove old modal functionality This commit removes the oldmodal.tsx file from the project, which contained deprecated code related to modal functionality. The file is no longer needed and has been deleted. --- frontend/src/plugins/oldmodal.tsx | 193 ------------------------------ 1 file changed, 193 deletions(-) delete mode 100644 frontend/src/plugins/oldmodal.tsx diff --git a/frontend/src/plugins/oldmodal.tsx b/frontend/src/plugins/oldmodal.tsx deleted file mode 100644 index 7f6b3bb0a..000000000 --- a/frontend/src/plugins/oldmodal.tsx +++ /dev/null @@ -1,193 +0,0 @@ -import mitt, { type Emitter, type EventType } from "mitt"; -import type { App, Component, VNodeProps } from "vue"; -import { Transition, createVNode, defineComponent, render } from "vue"; - -declare module "@vue/runtime-core" { - interface ComponentCustomProperties { - $modal: { - eventBus: Emitter>; - create: (modal: Partial) => void; - destroy: () => void; - confirm: (title?: string, message?: string) => Promise; - [key: string]: any; - }; - } -} - -export type ModalOptions = { - modal: { - title?: string | Component; - body?: string | Component; - footer?: string | Component; - buttons?: Array void }>>; - }; - options: { - showCloseButton?: boolean; - showHeader?: boolean; - showBody?: boolean; - showFooter?: boolean; - showOverlay?: boolean; - hideOnOverlayClick?: boolean; - hideOnEscapeKey?: boolean; - closeButtonText?: string; - disableAnimation?: boolean; - callback?: () => void; - }; - isVisible?: boolean; -}; - -const defaultModalOptions: ModalOptions["options"] = { - showCloseButton: true, - showHeader: true, - showBody: true, - showFooter: true, - showOverlay: true, - hideOnOverlayClick: false, - hideOnEscapeKey: true, - closeButtonText: "Cancel", - disableAnimation: false, - callback: () => {}, -}; - -const DefaultModal = defineComponent({ - name: "DefaultModal", - data() { - return { - isVisible: false, - modal: {}, - options: defaultModalOptions, - } as ModalOptions; - }, - methods: { - onDestroy() { - this.modal = {}; - this.options = defaultModalOptions; - this.isVisible = false; - }, - updateModal(modal: Partial) { - this.modal = { ...this.modal, ...modal.modal }; - this.options = { ...this.options, ...modal.options }; - this.isVisible = true; - }, - onCancel() { - this.onDestroy(); - this.options.callback?.(); - }, - }, - mounted() { - addEventListener("keydown", (e: KeyboardEvent) => { - if (this.options.hideOnEscapeKey && e.key === "Escape") { - this.onCancel(); - } - }); - - this.$modal.eventBus.on("create-modal", (modal: Partial) => { - this.updateModal(modal); - }); - - this.$modal.eventBus.on("destroy-modal", () => { - this.onDestroy(); - }); - }, - render() { - return ( - this.onDestroy()} mode="out-in"> - {this.isVisible ? ( -
- {this.options.showOverlay ?
(this.options.hideOnOverlayClick ? this.onCancel() : null)} class="fixed inset-0 bg-gray-700 bg-opacity-75 transition-opacity">
: null} -
- {/* Modal Title */} -
- {this.modal?.title && typeof this.modal.title === "object" ? createVNode(this.modal.title) : null} -

{this.modal?.title && typeof this.modal.title === "string" ? this.modal.title : null}

- -
- - {/* Modal Body */} -
- {this.modal?.body && typeof this.modal.body === "object" ? createVNode(this.modal.body) : null} - {this.modal?.body && typeof this.modal.body === "string" ?

{this.modal.body}

: null} -
- - {/* Modal Footer */} - {this.options.showFooter ? ( -
- {this.modal?.buttons?.map((button) => ( - // @ts-ignore - - ))} - {this.modal?.footer && typeof this.modal.footer === "object" ? createVNode(this.modal.footer) : null} - {this.modal?.footer && typeof this.modal.footer === "string" ?

{this.modal.footer}

: null} - {this.options.showCloseButton ? ( - - ) : null} -
- ) : null} -
-
- ) : null} -
- ); - }, -}); - -const create = (eventBus: Emitter>, modal: Partial) => eventBus.emit("create-modal", modal) as unknown as void; -const destroy = (eventBus: Emitter>) => eventBus.emit("destroy-modal") as unknown as void; -const confirm = async (eventBus: Emitter>, title?: string, message?: string): Promise => { - return new Promise((resolve) => { - eventBus.emit("create-modal", { - options: { - showCloseButton: false, - callback: () => resolve(false), - }, - modal: { - title: title ?? "Are you sure?", - body: message ?? "Are you sure you want to continue?", - buttons: [ - { - class: "!bg-primary", - text: "Confirm", - onClick: () => { - eventBus.emit("destroy-modal"); - resolve(true); - }, - }, - { - text: "Cancel", - onClick: () => { - eventBus.emit("destroy-modal"); - resolve(false); - }, - }, - ], - }, - }); - }); -}; - -/** - * Vue Plugin - * - * This plugin will add a $modal function to the vue instance - * allowing you to create modals from anywhere in your app - */ -const vuePluginModal = { - install(vue: App) { - const eventBus = mitt(); - vue.component("ModalContainer", DefaultModal); - vue.config.globalProperties.$modal = { - eventBus: eventBus, - create: (modal: Partial) => create(eventBus, modal), - destroy: () => destroy(eventBus), - confirm: (title?: string, message?: string) => confirm(eventBus, title, message), - }; - }, -}; - -export default vuePluginModal;