diff --git a/src/components/StoryList.vue b/src/components/StoryList.vue index e2388ad..bcf936f 100644 --- a/src/components/StoryList.vue +++ b/src/components/StoryList.vue @@ -20,20 +20,14 @@ import { onMounted } from 'vue' import StoryContainer from './StoryContainer.vue' import { useStoryStore } from '@/stores/story' +import { useEscapeKey } from '@/composables/EscapeKey' const store = useStoryStore() -const keyboardShortcut = () => { - // if press on escpae key - window.addEventListener('keydown', (e) => { - if (e.key !== 'Escape') return - store.closeStories() - }) -} +useEscapeKey(store.closeStories) onMounted(() => { store.getStories() - keyboardShortcut() }) diff --git a/src/components/player/StoryDrawRect.vue b/src/components/player/StoryDrawRect.vue deleted file mode 100644 index 825d7a2..0000000 --- a/src/components/player/StoryDrawRect.vue +++ /dev/null @@ -1,260 +0,0 @@ - - - - - draw rect - {{ selectedBounds }} - - home - Add Point - Add Rectangle - - - {{ marker.name }} - - - - - - Save - Cancel - - - - - - - - diff --git a/src/components/player/StoryEditor.vue b/src/components/player/StoryEditor.vue index d8b6af2..7398769 100644 --- a/src/components/player/StoryEditor.vue +++ b/src/components/player/StoryEditor.vue @@ -32,9 +32,10 @@ import type { Story, Marker } from '@/types/virages' import { onMounted, ref, inject, nextTick, type Ref, computed } from 'vue' import OpenSeadragon from 'openseadragon' -import { useIsMobile } from '@/composable/IsMobile' -import { useViewer } from '@/composable/Viewer' +import { useIsMobile } from '@/composables/IsMobile' +import { useViewer } from '@/composables/Viewer' import { useStoryStore } from '@/stores/story' +import { useEscapeKey } from '@/composables/EscapeKey' const props = defineProps<{ story: Story }>() const Viewer = inject>('Viewer') @@ -52,6 +53,7 @@ const sortedMarkers = computed(() => { const goHome = () => { Viewer?.value.viewport.goHome(false) + unselectMarker() } const addPoint = () => { @@ -173,15 +175,6 @@ const loadStory = (markers: Marker[]) => { }) } -const keyboardShortcut = () => { - // if press on escpae key - window.addEventListener('keydown', (e) => { - if (e.key !== 'Escape') return - unselectMarker() - goHome() - }) -} - const initScalebar = () => { Viewer.value.scalebar({ type: OpenSeadragon.ScalebarType.MAP, @@ -198,9 +191,10 @@ const initScalebar = () => { }) } -const initUrl = () => { - Viewer.value.bookmarkUrl() -} +useEscapeKey(() => { + unselectMarker() + goHome() +}) onMounted(() => { nextTick(() => { @@ -209,9 +203,8 @@ onMounted(() => { loadStory(props.story.markers) createMarkerOnClick() editMarkerOnDragOrZoom() - keyboardShortcut() initScalebar() - initUrl() + Viewer.value.bookmarkUrl() zoomTo(6) // COMPOSABLE WORKS }) }) diff --git a/src/composables/EscapeKey.ts b/src/composables/EscapeKey.ts new file mode 100644 index 0000000..56f6735 --- /dev/null +++ b/src/composables/EscapeKey.ts @@ -0,0 +1,17 @@ +import { onMounted, onUnmounted } from 'vue' + +export function useEscapeKey(callback: () => void) { + const handleKeydown = (e: KeyboardEvent) => { + if (e.key === 'Escape') { + callback() + } + } + + onMounted(() => { + window.addEventListener('keydown', handleKeydown) + }) + + onUnmounted(() => { + window.removeEventListener('keydown', handleKeydown) + }) +} diff --git a/src/composable/IsMobile.ts b/src/composables/IsMobile.ts similarity index 100% rename from src/composable/IsMobile.ts rename to src/composables/IsMobile.ts diff --git a/src/composable/Viewer.ts b/src/composables/Viewer.ts similarity index 100% rename from src/composable/Viewer.ts rename to src/composables/Viewer.ts