fix clicking twice outside context menu to hide

This commit is contained in:
geoffrey45
2022-10-14 17:53:28 +03:00
committed by Mungai Njoroge
parent 823b52fc04
commit 39fd43aff0
4 changed files with 19 additions and 7 deletions
+2
View File
@@ -44,6 +44,8 @@ onClickOutside(contextMenu, (e) => {
e.stopImmediatePropagation(); e.stopImmediatePropagation();
clickCount = 0; clickCount = 0;
} }
}, {
capture: false
}); });
</script> </script>
+9 -6
View File
@@ -1,7 +1,7 @@
<template> <template>
<div <div
class="songlist-item rounded-sm" class="songlist-item rounded-sm"
:class="[{ current: isCurrent }, { contexton: context_on }]" :class="[{ current: isCurrent }, { contexton: context_menu_showing }]"
@dblclick.prevent="emitUpdate" @dblclick.prevent="emitUpdate"
@contextmenu.prevent="showMenu" @contextmenu.prevent="showMenu"
> >
@@ -51,7 +51,6 @@
<div class="song-duration">{{ formatSeconds(track.duration) }}</div> <div class="song-duration">{{ formatSeconds(track.duration) }}</div>
<div <div
class="options-icon circular" class="options-icon circular"
:class="{ 'btn-active': options_button_clicked }"
@click.stop="showMenu" @click.stop="showMenu"
@dblclick.stop="() => {}" @dblclick.stop="() => {}"
> >
@@ -74,7 +73,7 @@ import ArtistName from "./ArtistName.vue";
const context_on = ref(false); const context_on = ref(false);
const imguri = paths.images.thumb.small; const imguri = paths.images.thumb.small;
const options_button_clicked = ref(false); const context_menu_showing = ref(false);
const artisttitle = ref<HTMLElement | null>(null); const artisttitle = ref<HTMLElement | null>(null);
@@ -95,7 +94,7 @@ function emitUpdate() {
} }
function showMenu(e: MouseEvent) { function showMenu(e: MouseEvent) {
showContext(e, props.track, options_button_clicked); showContext(e, props.track, context_menu_showing);
} }
</script> </script>
@@ -191,8 +190,8 @@ function showMenu(e: MouseEvent) {
} }
} }
.options_button_clicked { .context_menu_showing {
background-color: $gray5; background-color: $gray4;
opacity: 1; opacity: 1;
} }
@@ -235,4 +234,8 @@ function showMenu(e: MouseEvent) {
.songlist-item.current { .songlist-item.current {
background-color: $gray; background-color: $gray;
} }
.songlist-item.contexton {
background-color: $gray;
}
</style> </style>
+7
View File
@@ -8,6 +8,12 @@ import { ContextSrc } from "./enums";
import { Track } from "@/interfaces"; import { Track } from "@/interfaces";
import trackContext from "@/contexts/track_context"; import trackContext from "@/contexts/track_context";
/**
* Handles showing the context menu for a track component.
* @param e The MouseEvent for positioning the context menu
* @param track The track to link to the context menu
* @param flag The boolean that manages the context visibility in the source component
*/
export const showTrackContextMenu = ( export const showTrackContextMenu = (
e: MouseEvent, e: MouseEvent,
track: Track, track: Track,
@@ -20,6 +26,7 @@ export const showTrackContextMenu = (
menu.showContextMenu(e, options, ContextSrc.Track); menu.showContextMenu(e, options, ContextSrc.Track);
flag.value = true; flag.value = true;
// watch for context menu visibility and reset flag
menu.$subscribe((mutation, state) => { menu.$subscribe((mutation, state) => {
if (!state.visible) { if (!state.visible) {
flag.value = false; flag.value = false;
+1 -1
View File
@@ -18,7 +18,7 @@ export default defineStore("context-menu", {
state: () => ({ state: () => ({
visible: false, visible: false,
options: {} as Option[], options: {} as Option[],
src: <null | string>"", src: <null | ContextSrc>"",
elem: <HTMLElement | null>null, elem: <HTMLElement | null>null,
}), }),
actions: { actions: {