- Added page transition effects in app.vue for smoother navigation. - Updated nuxt.config.ts to include custom font styles and page transitions. - Improved loading indicators in MapPageWrapper.vue and login.vue for better user experience. - Enhanced MapView.vue with a collapsible control panel and improved styling. - Introduced new icons for various components to enhance visual consistency. - Updated Tailwind CSS configuration to extend font families and improve theme management. - Refined layout styles in default.vue and admin pages for better responsiveness and aesthetics. - Implemented error handling and loading states across various forms for improved user feedback.
81 lines
2.7 KiB
Vue
81 lines
2.7 KiB
Vue
<template>
|
|
<div class="container mx-auto p-4 max-w-lg">
|
|
<h1 class="text-2xl font-bold mb-6">Edit map {{ id }}</h1>
|
|
|
|
<form v-if="map" @submit.prevent="submit" class="flex flex-col gap-4">
|
|
<div class="form-control">
|
|
<label class="label" for="name">Name</label>
|
|
<input id="name" v-model="form.name" type="text" class="input input-bordered" required />
|
|
</div>
|
|
<div class="form-control">
|
|
<label class="label cursor-pointer gap-2">
|
|
<input v-model="form.hidden" type="checkbox" class="checkbox" />
|
|
<span class="label-text">Hidden</span>
|
|
</label>
|
|
</div>
|
|
<div class="form-control">
|
|
<label class="label cursor-pointer gap-2">
|
|
<input v-model="form.priority" type="checkbox" class="checkbox" />
|
|
<span class="label-text">Priority</span>
|
|
</label>
|
|
</div>
|
|
<p v-if="error" class="text-error text-sm">{{ error }}</p>
|
|
<div class="flex gap-2">
|
|
<button type="submit" class="btn btn-primary" :disabled="loading">
|
|
<span v-if="loading" class="loading loading-spinner loading-sm" />
|
|
<span v-else>Save</span>
|
|
</button>
|
|
<NuxtLink to="/admin" class="btn btn-ghost">Back</NuxtLink>
|
|
</div>
|
|
</form>
|
|
<template v-else-if="mapsLoaded">
|
|
<p class="text-base-content/70">Map not found.</p>
|
|
<NuxtLink to="/admin" class="btn btn-ghost mt-2">Back to Admin</NuxtLink>
|
|
</template>
|
|
<p v-else class="text-base-content/70">Loading…</p>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
definePageMeta({ middleware: 'admin' })
|
|
|
|
const route = useRoute()
|
|
const router = useRouter()
|
|
const api = useMapApi()
|
|
const id = computed(() => parseInt(route.params.id as string, 10))
|
|
const map = ref<{ ID: number; Name: string; Hidden: boolean; Priority: boolean } | null>(null)
|
|
const mapsLoaded = ref(false)
|
|
const form = ref({ name: '', hidden: false, priority: false })
|
|
const loading = ref(false)
|
|
const error = ref('')
|
|
|
|
onMounted(async () => {
|
|
try {
|
|
const maps = await api.adminMaps()
|
|
mapsLoaded.value = true
|
|
const found = maps.find((m) => m.ID === id.value)
|
|
if (found) {
|
|
map.value = found
|
|
form.value = { name: found.Name, hidden: found.Hidden, priority: found.Priority }
|
|
}
|
|
} catch {
|
|
mapsLoaded.value = true
|
|
error.value = 'Failed to load map'
|
|
}
|
|
})
|
|
|
|
async function submit() {
|
|
if (!map.value) return
|
|
error.value = ''
|
|
loading.value = true
|
|
try {
|
|
await api.adminMapPost(map.value.ID, form.value)
|
|
await router.push('/admin')
|
|
} catch (e: unknown) {
|
|
error.value = e instanceof Error ? e.message : 'Failed'
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
</script>
|