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:
Badri Sunderarajan 2024-03-24 23:10:22 +05:30
parent d36fd1afe8
commit 073176a9c9
Signed by: badrihippo
GPG key ID: 9F594532AD60DE03
2 changed files with 15 additions and 4 deletions

View file

@ -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)

View file

@ -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}