Add built-in screens (login, profile, menu, posts), per-user and site themes
This commit is contained in:
1 parent
4bf0a8bbb0
commit
351667abaf
46 files changed
+3720
-12
No files matched your search
@@ -0,0 +1,85 @@
|
||||
<script setup lang="ts">
|
||||
import { boot, useForm } from '../api';
|
||||
import Link from '../components/Link.vue';
|
||||
import { t } from '../i18n';
|
||||
import { flash, navigate } from '../state';
|
||||
|
||||
const props = defineProps<{ post: Record<string, any> | null; categories: string[]; known_tags: string[] }>();
|
||||
|
||||
const post = props.post;
|
||||
const form = useForm({
|
||||
title: post?.title ?? '', slug: post?.slug ?? '', excerpt: post?.excerpt ?? '', body: post?.body ?? '',
|
||||
cover_image: post?.cover_image ?? '', category: post?.category ?? '', tags: (post?.tags ?? []) as string[],
|
||||
is_featured: post?.is_featured ?? false, is_published: post?.is_published ?? false, published_at: post?.published_at ?? '',
|
||||
});
|
||||
// Tags are typed as one comma separated line.
|
||||
let tagLine = (post?.tags ?? []).join(', ');
|
||||
|
||||
async function submit(): Promise<void> {
|
||||
form.values.tags = tagLine.split(',').map((tag: string) => tag.trim()).filter(Boolean);
|
||||
const saved = post
|
||||
? await form.send('put', `${boot.base}/posts/${post.id}`)
|
||||
: await form.send('post', `${boot.base}/posts`);
|
||||
|
||||
if (saved) {
|
||||
flash(t(post ? 'Saved.' : 'Created.'));
|
||||
void navigate(`${boot.base}/posts`);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="mb-6 flex items-center justify-between gap-3">
|
||||
<h1 class="font-display text-2xl font-bold">{{ post ? post.title : t('New post') }}</h1>
|
||||
<Link :href="boot.base + '/posts'" class="m-btn m-btn-secondary">{{ t('Back') }}</Link>
|
||||
</div>
|
||||
<form class="m-card max-w-3xl space-y-5 p-5" @submit.prevent="submit">
|
||||
<div>
|
||||
<label for="title" class="m-label">{{ t('Title') }}</label>
|
||||
<input id="title" v-model="form.values.title" required maxlength="255" class="m-input" />
|
||||
<p v-if="form.errors.title" class="m-error">{{ form.errors.title }}</p>
|
||||
</div>
|
||||
<div class="grid gap-5 sm:grid-cols-2">
|
||||
<div>
|
||||
<label for="slug" class="m-label">{{ t('Address (slug)') }}</label>
|
||||
<input id="slug" v-model="form.values.slug" maxlength="255" class="m-input" />
|
||||
<p v-if="form.errors.slug" class="m-error">{{ form.errors.slug }}</p>
|
||||
</div>
|
||||
<div>
|
||||
<label for="category" class="m-label">{{ t('Category') }}</label>
|
||||
<input id="category" v-model="form.values.category" list="categories" maxlength="60" class="m-input" />
|
||||
<datalist id="categories"><option v-for="category in categories" :key="category" :value="category" /></datalist>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label for="excerpt" class="m-label">{{ t('Summary') }}</label>
|
||||
<textarea id="excerpt" v-model="form.values.excerpt" rows="2" maxlength="500" class="m-input" />
|
||||
<p v-if="form.errors.excerpt" class="m-error">{{ form.errors.excerpt }}</p>
|
||||
</div>
|
||||
<div>
|
||||
<label for="body" class="m-label">{{ t('Text (Markdown)') }}</label>
|
||||
<textarea id="body" v-model="form.values.body" rows="14" required class="m-input font-mono" />
|
||||
<p v-if="form.errors.body" class="m-error">{{ form.errors.body }}</p>
|
||||
</div>
|
||||
<div class="grid gap-5 sm:grid-cols-2">
|
||||
<div>
|
||||
<label for="cover" class="m-label">{{ t('Cover image') }}</label>
|
||||
<input id="cover" v-model="form.values.cover_image" maxlength="2048" class="m-input" />
|
||||
</div>
|
||||
<div>
|
||||
<label for="tags" class="m-label">{{ t('Tags (comma separated)') }}</label>
|
||||
<input id="tags" v-model="tagLine" list="known-tags" class="m-input" />
|
||||
<datalist id="known-tags"><option v-for="tag in known_tags" :key="tag" :value="tag" /></datalist>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-wrap items-center gap-6">
|
||||
<label class="flex items-center gap-2 text-sm"><input v-model="form.values.is_featured" type="checkbox" /> {{ t('Featured') }}</label>
|
||||
<label v-if="boot.permissions.includes('posts.publish')" class="flex items-center gap-2 text-sm"><input v-model="form.values.is_published" type="checkbox" /> {{ t('Publish') }}</label>
|
||||
<div v-if="form.values.is_published">
|
||||
<label for="at" class="m-label">{{ t('Publish at') }}</label>
|
||||
<input id="at" v-model="form.values.published_at" type="datetime-local" class="m-input" />
|
||||
</div>
|
||||
</div>
|
||||
<button type="submit" class="m-btn m-btn-primary" :disabled="form.busy">{{ form.busy ? t('Saving…') : t('Save') }}</button>
|
||||
</form>
|
||||
</template>
|
||||
Reference in new issue
Block a user