pinafore/src/routes/_components/settings/instance/InstanceActions.html

52 lines
1.5 KiB
HTML

<form class="instance-actions" aria-label="Switch to or log out of this instance">
{#if $loggedInInstancesInOrder.length > 1 && $currentInstance !== instanceName}
<button class="primary"
on:click="onSwitchToThisInstance(event)">
Switch to this instance
</button>
{/if}
<button on:click="onLogOut(event)">Log out</button>
</form>
<style>
.instance-actions {
width: 100%;
display: flex;
justify-content: right;
margin: 20px 0;
}
.instance-actions button {
margin: 0 5px;
flex-basis: 100%;
}
</style>
<script>
import { store } from '../../../_store/store'
import { importShowTextConfirmationDialog } from '../../dialog/asyncDialogs'
import { switchToInstance, logOutOfInstance } from '../../../_actions/instances'
export default {
store: () => store,
methods: {
onSwitchToThisInstance (e) {
e.preventDefault()
let { instanceName } = this.get()
switchToInstance(instanceName)
},
async onLogOut (e) {
e.preventDefault()
let { instanceName } = this.get()
let showTextConfirmationDialog = await importShowTextConfirmationDialog()
showTextConfirmationDialog({
text: `Log out of ${instanceName}?`
}).on('positive', () => {
// TODO: dumb timing hack because the modal navigates back while we're trying to navigate forward
setTimeout(() => {
/* no await */logOutOfInstance(instanceName)
}, 200)
})
}
}
}
</script>