Allow the options menu to toggle itself
Earlier, the toggle was only happening from the outside, but now we can toggle the options menu from the menu itself. This is useful when we want to close the menu from inside, for example when an option has been selected or the back button has been pressed.
This commit is contained in:
parent
d36fd1afe8
commit
073176a9c9
|
@ -2,6 +2,13 @@
|
|||
import { onMount } from 'svelte'
|
||||
export let title = "Options"
|
||||
|
||||
// Function to call in order to close the menu.
|
||||
// This is triggerd either with the "back" button
|
||||
// or when one of the options is selected.
|
||||
export let toggler = function() {
|
||||
console.error("You didn't provide a toggler function to close the options menu!")
|
||||
}
|
||||
|
||||
// Special navigation for the options menu
|
||||
function optionNav(move) {
|
||||
let currentIndex = Number(document.activeElement.dataset.index || 0)
|
||||
|
|
|
@ -26,6 +26,9 @@
|
|||
|
||||
// Whether the options menu is visible or not
|
||||
let optionsMenuVisible = false
|
||||
function toggleOptionsMenu() {
|
||||
optionsMenuVisible = !optionsMenuVisible
|
||||
}
|
||||
|
||||
|
||||
$: title = chatbox?.attributes?.nickname || chatbox?.attributes?.id || params.chatID || 'Convo'
|
||||
|
@ -96,9 +99,7 @@
|
|||
}
|
||||
|
||||
k.right.label = 'Options'
|
||||
k.right.callback = () => {
|
||||
optionsMenuVisible = !optionsMenuVisible
|
||||
}
|
||||
k.right.callback = toggleOptionsMenu
|
||||
|
||||
return k
|
||||
})
|
||||
|
@ -244,7 +245,10 @@
|
|||
</div>
|
||||
|
||||
{#if optionsMenuVisible}
|
||||
<OptionsMenu title="Options">
|
||||
<OptionsMenu
|
||||
title="Options"
|
||||
toggler={toggleOptionsMenu}
|
||||
>
|
||||
<ListItem
|
||||
text="Close conversation"
|
||||
onclick={closeChat}
|
||||
|
|
Loading…
Reference in a new issue