From c6502e50230beca546cb4686b3c7dc5ae3e00279 Mon Sep 17 00:00:00 2001 From: James Lyne Date: Thu, 23 Jun 2022 21:27:35 +0100 Subject: [PATCH] Migrate ChatControl to vue --- src/App.vue | 7 --- src/components/ChatBox.vue | 36 +++++------- src/components/MapUI.vue | 2 +- src/components/map/control/ChatControl.vue | 66 +++++++++++++++++----- src/leaflet/control/ChatControl.ts | 65 --------------------- 5 files changed, 68 insertions(+), 108 deletions(-) delete mode 100644 src/leaflet/control/ChatControl.ts diff --git a/src/App.vue b/src/App.vue index eaa3539..798bb0c 100644 --- a/src/App.vue +++ b/src/App.vue @@ -18,7 +18,6 @@ - @@ -28,7 +27,6 @@ import {computed, defineComponent, onBeforeUnmount, onMounted, ref, watch} from 'vue'; import Map from './components/Map.vue'; import Sidebar from './components/Sidebar.vue'; -import ChatBox from './components/ChatBox.vue'; import {useStore} from "@/store"; import {ActionTypes} from "@/store/action-types"; import {parseUrl} from '@/util'; @@ -46,7 +44,6 @@ export default defineComponent({ MapUI, Map, Sidebar, - ChatBox, LoginModal }, @@ -58,8 +55,6 @@ export default defineComponent({ currentUrl = computed(() => store.getters.url), currentServer = computed(() => store.state.currentServer), configurationHash = computed(() => store.state.configurationHash), - chatBoxEnabled = computed(() => store.state.components.chatBox), - chatVisible = computed(() => store.state.ui.visibleElements.has('chat')), playerImageUrl = computed(() => store.state.components.players.imageUrl), loggedIn = computed(() => store.state.loggedIn), //Whether the user is currently logged in @@ -229,8 +224,6 @@ export default defineComponent({ }); return { - chatBoxEnabled, - chatVisible, loginEnabled, loginRequired, loginModalVisible diff --git a/src/components/ChatBox.vue b/src/components/ChatBox.vue index fe8ba22..99136fb 100644 --- a/src/components/ChatBox.vue +++ b/src/components/ChatBox.vue @@ -15,18 +15,18 @@ --> @@ -129,18 +129,12 @@ diff --git a/src/leaflet/control/ChatControl.ts b/src/leaflet/control/ChatControl.ts deleted file mode 100644 index ff94791..0000000 --- a/src/leaflet/control/ChatControl.ts +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2022 James Lyne - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {Control, ControlOptions, DomEvent, DomUtil} from 'leaflet'; -import {useStore} from "@/store"; -import {MutationTypes} from "@/store/mutation-types"; -import {watch} from "@vue/runtime-core"; - -import "@/assets/icons/chat.svg"; - -/** - * Leaflet map control providing a chat button which opens the chatbox on click - */ -export class ChatControl extends Control { - declare options: ControlOptions - - constructor(options: ControlOptions) { - super(options); - } - - onAdd() { - const store = useStore(), - chatButton = DomUtil.create('button', - 'leaflet-control-bottom leaflet-control-button leaflet-control-chat') as HTMLButtonElement; - - chatButton.type = 'button'; - chatButton.title = store.state.messages.chatTitle; - chatButton.innerHTML = ` - - - `; - - chatButton.addEventListener('click', e => { - store.commit(MutationTypes.TOGGLE_UI_ELEMENT_VISIBILITY, 'chat'); - e.stopPropagation(); - e.preventDefault(); - }); - - //Open chat on ArrowRight from button - DomEvent.on(chatButton,'keydown', (e: Event) => { - if((e as KeyboardEvent).key === 'ArrowRight') { - store.commit(MutationTypes.SET_UI_ELEMENT_VISIBILITY, {element: 'chat', state: true}); - } - }); - - watch(store.state.ui.visibleElements, (newValue) => { - chatButton.setAttribute('aria-expanded', newValue.has('chat').toString()); - }); - - return chatButton; - } -}