feat(board): BoardPostCard, BoardPostForm, simplify CooperativeTagSelector
This commit is contained in:
parent
78db4be7ba
commit
33d27c5d9e
3 changed files with 507 additions and 85 deletions
231
app/components/BoardPostForm.vue
Normal file
231
app/components/BoardPostForm.vue
Normal file
|
|
@ -0,0 +1,231 @@
|
|||
<template>
|
||||
<form class="post-form" @submit.prevent="handleSubmit">
|
||||
<div class="form-header">
|
||||
<h3 class="form-title">{{ isEdit ? 'Edit post' : 'New post' }}</h3>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label for="post-title">Title</label>
|
||||
<input
|
||||
id="post-title"
|
||||
v-model="form.title"
|
||||
type="text"
|
||||
maxlength="120"
|
||||
placeholder="Short summary"
|
||||
>
|
||||
<div class="char-count">{{ form.title.length }}/120</div>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label for="post-seeking">Seeking</label>
|
||||
<textarea
|
||||
id="post-seeking"
|
||||
v-model="form.seeking"
|
||||
rows="3"
|
||||
maxlength="500"
|
||||
placeholder="What are you looking for?"
|
||||
/>
|
||||
<div class="char-count">{{ form.seeking.length }}/500</div>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label for="post-offering">Offering</label>
|
||||
<textarea
|
||||
id="post-offering"
|
||||
v-model="form.offering"
|
||||
rows="3"
|
||||
maxlength="500"
|
||||
placeholder="What can you offer?"
|
||||
/>
|
||||
<div class="char-count">{{ form.offering.length }}/500</div>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label for="post-note">Note (optional)</label>
|
||||
<textarea
|
||||
id="post-note"
|
||||
v-model="form.note"
|
||||
rows="2"
|
||||
maxlength="300"
|
||||
placeholder="Anything else to add?"
|
||||
/>
|
||||
<div class="char-count">{{ form.note.length }}/300</div>
|
||||
</div>
|
||||
|
||||
<div v-if="tags.length" class="field">
|
||||
<label>Tags</label>
|
||||
<div class="pill-grid">
|
||||
<button
|
||||
v-for="tag in tags"
|
||||
:key="tag.slug"
|
||||
type="button"
|
||||
class="pill"
|
||||
:class="{ selected: form.tags.includes(tag.slug) }"
|
||||
@click="toggleTag(tag.slug)"
|
||||
>{{ tag.label || tag.name || tag.slug }}</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p v-if="error" class="form-error">{{ error }}</p>
|
||||
|
||||
<div class="form-actions">
|
||||
<button type="button" class="btn" @click="$emit('cancel')">Cancel</button>
|
||||
<button type="submit" class="btn btn-primary">
|
||||
{{ isEdit ? 'Save changes' : 'Post' }}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
const props = defineProps({
|
||||
post: { type: Object, default: null },
|
||||
tags: { type: Array, default: () => [] },
|
||||
})
|
||||
|
||||
const emit = defineEmits(['submit', 'cancel'])
|
||||
|
||||
const isEdit = computed(() => !!props.post)
|
||||
|
||||
const form = reactive({
|
||||
title: props.post?.title || '',
|
||||
seeking: props.post?.seeking || '',
|
||||
offering: props.post?.offering || '',
|
||||
note: props.post?.note || '',
|
||||
tags: Array.isArray(props.post?.tags) ? [...props.post.tags] : [],
|
||||
})
|
||||
|
||||
const error = ref('')
|
||||
|
||||
function toggleTag(slug) {
|
||||
const idx = form.tags.indexOf(slug)
|
||||
if (idx === -1) form.tags.push(slug)
|
||||
else form.tags.splice(idx, 1)
|
||||
}
|
||||
|
||||
function handleSubmit() {
|
||||
error.value = ''
|
||||
const title = form.title.trim()
|
||||
const seeking = form.seeking.trim()
|
||||
const offering = form.offering.trim()
|
||||
|
||||
if (!title) {
|
||||
error.value = 'Title is required.'
|
||||
return
|
||||
}
|
||||
if (!seeking && !offering) {
|
||||
error.value = 'Add at least one of Seeking or Offering.'
|
||||
return
|
||||
}
|
||||
|
||||
emit('submit', {
|
||||
title,
|
||||
seeking,
|
||||
offering,
|
||||
note: form.note.trim(),
|
||||
tags: [...form.tags],
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.post-form {
|
||||
border: 1px dashed var(--border);
|
||||
padding: 20px 24px;
|
||||
background: var(--bg);
|
||||
}
|
||||
|
||||
.form-header {
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
.form-title {
|
||||
font-family: "Brygada 1918", serif;
|
||||
font-size: 18px;
|
||||
font-weight: 500;
|
||||
color: var(--text-bright);
|
||||
}
|
||||
|
||||
.field {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.field label {
|
||||
display: block;
|
||||
font-size: 10px;
|
||||
letter-spacing: 0.08em;
|
||||
text-transform: uppercase;
|
||||
color: var(--text-faint);
|
||||
margin-bottom: 3px;
|
||||
}
|
||||
.field input,
|
||||
.field textarea {
|
||||
width: 100%;
|
||||
padding: 5px 8px;
|
||||
font-family: "Commit Mono", monospace;
|
||||
font-size: 13px;
|
||||
color: var(--text-bright);
|
||||
background: var(--input-bg);
|
||||
border: 1px solid var(--border);
|
||||
outline: none;
|
||||
resize: vertical;
|
||||
}
|
||||
.field input:focus,
|
||||
.field textarea:focus {
|
||||
border-color: var(--candle);
|
||||
}
|
||||
|
||||
.char-count {
|
||||
font-size: 9px;
|
||||
font-family: "Commit Mono", monospace;
|
||||
color: var(--text-faint);
|
||||
text-align: right;
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
.pill-grid {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 4px;
|
||||
}
|
||||
.pill {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
padding: 2px 9px;
|
||||
border: 1px dashed var(--border);
|
||||
background: transparent;
|
||||
color: var(--text-faint);
|
||||
font-size: 11px;
|
||||
font-family: "Commit Mono", monospace;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
transition: all 0.12s;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.pill:hover {
|
||||
color: var(--text-dim);
|
||||
border-color: var(--border-d);
|
||||
}
|
||||
.pill.selected {
|
||||
background: var(--surface);
|
||||
color: var(--text-bright);
|
||||
border-color: var(--candle);
|
||||
border-style: solid;
|
||||
}
|
||||
|
||||
.form-error {
|
||||
font-size: 11px;
|
||||
color: var(--ember);
|
||||
margin: 8px 0;
|
||||
padding: 6px 10px;
|
||||
border: 1px dashed var(--ember);
|
||||
background: var(--ember-bg);
|
||||
}
|
||||
|
||||
.form-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 8px;
|
||||
margin-top: 14px;
|
||||
padding-top: 12px;
|
||||
border-top: 1px dashed var(--border);
|
||||
}
|
||||
</style>
|
||||
Loading…
Add table
Add a link
Reference in a new issue