- Updated frontend-nuxt.mdc to specify usage of composables for API calls. - Added new AuthCard and ConfirmModal components for improved UI consistency. - Introduced UserAvatar component for user profile display, replacing previous Gravatar implementation. - Implemented useFormSubmit composable for handling form submissions with loading and error states. - Enhanced vitest.config.ts to include coverage reporting for composables and components. - Removed deprecated useAdminApi and useAuth composables to streamline API interactions. - Updated login and setup pages to utilize new components and composables for better user experience.
90 lines
3.0 KiB
Vue
90 lines
3.0 KiB
Vue
<template>
|
|
<div class="container mx-auto p-4 max-w-2xl min-w-0">
|
|
<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">
|
|
<fieldset class="fieldset">
|
|
<label class="label" for="name">Name</label>
|
|
<input id="name" v-model="form.name" type="text" class="input min-h-11 touch-manipulation" required />
|
|
</fieldset>
|
|
<fieldset class="fieldset">
|
|
<label class="label cursor-pointer gap-2">
|
|
<input v-model="form.hidden" type="checkbox" class="checkbox" />
|
|
<span>Hidden</span>
|
|
</label>
|
|
</fieldset>
|
|
<fieldset class="fieldset">
|
|
<label class="label cursor-pointer gap-2">
|
|
<input v-model="form.priority" type="checkbox" class="checkbox" />
|
|
<span>Priority</span>
|
|
</label>
|
|
</fieldset>
|
|
<p v-if="error" class="text-error text-sm">{{ error }}</p>
|
|
<div class="flex gap-2">
|
|
<button type="submit" class="btn btn-primary min-h-11 touch-manipulation" :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 min-h-11 touch-manipulation">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 min-h-11 touch-manipulation">Back to Admin</NuxtLink>
|
|
</template>
|
|
<p v-else class="text-base-content/70">Loading…</p>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import type { MapInfoAdmin } from '~/types/api'
|
|
|
|
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<MapInfoAdmin | null>(null)
|
|
const mapsLoaded = ref(false)
|
|
const form = ref({ name: '', hidden: false, priority: false })
|
|
const loading = ref(false)
|
|
const error = ref('')
|
|
const adminMapName = useState<string | null>('admin-breadcrumb-map-name', () => null)
|
|
|
|
onMounted(async () => {
|
|
adminMapName.value = null
|
|
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 }
|
|
adminMapName.value = found.Name
|
|
}
|
|
} catch {
|
|
mapsLoaded.value = true
|
|
error.value = 'Failed to load map'
|
|
}
|
|
})
|
|
|
|
onUnmounted(() => {
|
|
adminMapName.value = null
|
|
})
|
|
|
|
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>
|