webapp/src/App.vue
padreug 5788b76000 fix vue-sonner Toast implementation
if there are ever issues with dialogs and toasts together, you may want
to add `pointer-events-auto` to the Toaster class
https://github.com/unovue/shadcn-vue/blob/dev/apps/www/src/content/docs/components/sonner.md#sonner-with-dialog
2025-07-12 18:10:26 +02:00

88 lines
2.6 KiB
Vue

<script setup lang="ts">
import { onMounted, onUnmounted, ref } from 'vue'
import Navbar from '@/components/layout/Navbar.vue'
import Footer from '@/components/layout/Footer.vue'
import ConnectionStatus from '@/components/nostr/ConnectionStatus.vue'
import PasswordDialog from '@/components/nostr/PasswordDialog.vue'
import { Toaster } from '@/components/ui/sonner'
import { useNostr } from '@/composables/useNostr'
import { identity } from '@/composables/useIdentity'
import { toast } from 'vue-sonner'
import { config } from '@/lib/config'
const { isConnected, isConnecting, error, connect, disconnect } = useNostr()
const showPasswordDialog = ref(false)
async function handlePasswordUnlock(password: string) {
try {
await identity.loadWithPassword(password)
showPasswordDialog.value = false
toast.success('Identity unlocked successfully')
} catch (error) {
toast.error('Failed to unlock identity. Please check your password.')
}
}
function handlePasswordCancel() {
showPasswordDialog.value = false
}
onMounted(async () => {
// Check if we have an encrypted identity that needs password
if (identity.hasStoredIdentity() && identity.isStoredIdentityEncrypted()) {
showPasswordDialog.value = true
} else {
// Initialize identity system for non-encrypted identities
try {
await identity.initialize()
} catch (error) {
console.error('Failed to initialize identity:', error)
}
}
// Connect to Nostr relays
await connect()
})
onUnmounted(() => {
disconnect()
})
</script>
<template>
<div class="min-h-screen bg-background font-sans antialiased">
<div class="relative flex min-h-screen flex-col"
style="padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom)">
<header
class="sticky top-0 z-50 w-full border-b bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60">
<nav class="container flex h-14 items-center justify-between">
<Navbar />
<ConnectionStatus
:is-connected="isConnected"
:is-connecting="isConnecting"
:error="error"
/>
</nav>
</header>
<main class="flex-1">
<router-view />
</main>
<Footer />
</div>
<!-- Toast notifications -->
<Toaster />
<!-- Password unlock dialog -->
<PasswordDialog
v-model:is-open="showPasswordDialog"
title="Unlock Identity"
description="Your Nostr identity is encrypted. Enter your password to unlock it."
@password="handlePasswordUnlock"
@cancel="handlePasswordCancel"
/>
</div>
</template>