Skip to content

Commit badc594

Browse files
committed
comment form
1 parent 31db9c3 commit badc594

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed

components/AddComment.vue

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<script lang="ts" setup>
2+
import { onAuthStateChanged } from 'firebase/auth'
3+
4+
const props = defineProps<{ postId: string, modelValue: boolean }>()
5+
const emit = defineEmits<{
6+
(e: 'update:modelValue', value: boolean): void
7+
}>()
8+
9+
const step = ref(0)
10+
const comment = ref('')
11+
const name = ref('')
12+
const commentForm = ref<HTMLFormElement & { validate: () => Promise<{ valid: boolean }> }>()
13+
const nameForm = ref<HTMLFormElement & { validate: () => Promise<{ valid: boolean }> }>()
14+
15+
const requiredRule = (value: string) => !!value || 'Bitte gib etwas ein'
16+
17+
onAuthStateChanged(firebaseAuth, async (user) => {
18+
name.value = user?.displayName ?? ''
19+
})
20+
21+
async function proceed() {
22+
const { valid } = await commentForm.value!.validate()
23+
if (valid) {
24+
step.value = 1
25+
}
26+
}
27+
28+
async function send() {
29+
const { valid } = await nameForm.value!.validate()
30+
if (valid) {
31+
console.log(name.value, comment.value)
32+
33+
emit('update:modelValue', false)
34+
reset()
35+
}
36+
}
37+
38+
function reset() {
39+
step.value = 0
40+
comment.value = ''
41+
name.value = ''
42+
}
43+
</script>
44+
45+
<template>
46+
<v-tabs-window
47+
v-if="props.modelValue"
48+
v-model="step"
49+
class="pt-6"
50+
>
51+
<v-tabs-window-item :value="0">
52+
<v-form ref="commentForm">
53+
<v-textarea
54+
v-model="comment"
55+
density="compact"
56+
variant="outlined"
57+
label="Gib deinen Senf dazu"
58+
autofocus
59+
:rows="1"
60+
:rules="[requiredRule]"
61+
auto-grow
62+
append-icon="mdi-arrow-right"
63+
@click:append="proceed"
64+
/>
65+
</v-form>
66+
</v-tabs-window-item>
67+
68+
<v-tabs-window-item :value="1">
69+
<v-form
70+
ref="nameForm"
71+
class="d-flex"
72+
>
73+
<v-text-field
74+
v-model="name"
75+
density="compact"
76+
variant="outlined"
77+
label="Name"
78+
name="name"
79+
autocomplete="given-name"
80+
:rules="[requiredRule]"
81+
prepend-icon="mdi-arrow-left"
82+
@click:prepend="step = 0"
83+
/>
84+
<v-btn
85+
color="primary"
86+
class="ml-4"
87+
@click="send"
88+
>
89+
Senden
90+
</v-btn>
91+
</v-form>
92+
</v-tabs-window-item>
93+
</v-tabs-window>
94+
</template>

components/BlogPost.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const { width: windowWidth } = useWindowSize()
99
1010
const textExpanded = ref(false)
1111
const carouselIndex = ref(0)
12+
const isAddingComment = ref(false)
1213
1314
const postUrlHttps = computed(() => {
1415
const url = new URL(props.value.url)
@@ -93,6 +94,7 @@ function onIntersect(isIntersecting: boolean) {
9394
icon="mdi-comment"
9495
variant="text"
9596
v-bind="tooltipProps"
97+
@click="expand(); isAddingComment = true"
9698
/>
9799
</template>
98100
</v-tooltip>
@@ -130,6 +132,10 @@ function onIntersect(isIntersecting: boolean) {
130132
v-if="textExpanded || paragraphs <= visibleParagrahps"
131133
:post-id="value.id"
132134
/>
135+
<AddComment
136+
v-model="isAddingComment"
137+
:post-id="props.value.id"
138+
/>
133139
</div>
134140
</div>
135141
<v-lazy v-if="textExpanded || paragraphs <= visibleParagrahps">

0 commit comments

Comments
 (0)