feat: add notes app
This commit is contained in:
@@ -1,35 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
const emit = defineEmits<{ unlocked: [] }>()
|
||||
|
||||
const password = ref('')
|
||||
const error = ref<string>()
|
||||
const unlocking = ref(false)
|
||||
|
||||
async function unlock() {
|
||||
if (!password.value) return
|
||||
unlocking.value = true
|
||||
error.value = undefined
|
||||
try {
|
||||
await $fetch('/api/diary/login', { method: 'POST', body: { password: password.value } })
|
||||
emit('unlocked')
|
||||
} catch (e) {
|
||||
error.value = errorMessage(e) ?? 'Couldn\'t unlock the diary'
|
||||
password.value = ''
|
||||
} finally {
|
||||
unlocking.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<UModal :open="true" :dismissible="false" :close="false" title="Diary" description="Enter your password to open the diary.">
|
||||
<template #body>
|
||||
<form class="space-y-4" @submit.prevent="unlock">
|
||||
<UFormField label="Password" :error="error">
|
||||
<UInput v-model="password" type="password" autocomplete="current-password" class="w-full" autofocus />
|
||||
</UFormField>
|
||||
<UButton type="submit" label="Unlock" icon="i-lucide-lock-open" :loading="unlocking" :disabled="!password" />
|
||||
</form>
|
||||
</template>
|
||||
</UModal>
|
||||
</template>
|
||||
@@ -1,12 +1,9 @@
|
||||
<script setup lang="ts">
|
||||
useHead({ title: 'Diary' })
|
||||
|
||||
const { data: session, refresh } = await useFetch<{ unlocked: boolean }>('/api/diary/session', { key: 'diary-session' })
|
||||
const unlocked = computed(() => !!session.value?.unlocked)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<template v-if="unlocked">
|
||||
<PasswordGate title="Diary">
|
||||
<UMain>
|
||||
<UContainer class="py-8">
|
||||
<DiaryTimeline />
|
||||
@@ -14,7 +11,5 @@ const unlocked = computed(() => !!session.value?.unlocked)
|
||||
</UMain>
|
||||
|
||||
<LogModal />
|
||||
</template>
|
||||
|
||||
<PasswordModal v-else @unlocked="refresh()" />
|
||||
</PasswordGate>
|
||||
</template>
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
interface FetchErrorLike {
|
||||
data?: { statusMessage?: string }
|
||||
statusMessage?: string
|
||||
message?: string
|
||||
}
|
||||
|
||||
export function errorMessage(error: unknown): string | undefined {
|
||||
const e = error as FetchErrorLike | null
|
||||
return e?.data?.statusMessage || e?.statusMessage || e?.message
|
||||
}
|
||||
Reference in New Issue
Block a user