@threenine/nuxstr-comments 1.2.0 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@threenine/nuxstr-comments",
3
3
  "configKey": "nuxstrComments",
4
- "version": "1.2.0",
4
+ "version": "1.2.2",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
@@ -34,59 +34,63 @@ onMounted(() => {
34
34
  </UButton>
35
35
  </div>
36
36
  </div>
37
- <div
38
- v-if="isLoggedIn"
39
- class="text-sm text-muted-foreground"
40
- >
41
- <PostComment :content-id="contentId" />
42
- </div>
43
-
44
- <div class="space-y-4">
37
+ <ClientOnly>
45
38
  <div
46
- v-if="loading"
39
+ v-if="isLoggedIn"
40
+ class="text-sm text-muted-foreground"
47
41
  >
48
- <ScaffoldComment />
42
+ <PostComment :content-id="contentId" />
49
43
  </div>
50
- <div
51
- v-else
52
- class="space-y-6"
53
- >
44
+ </ClientOnly>
45
+ <ClientOnly>
46
+ <div class="space-y-4">
54
47
  <div
55
- v-for="c in comments"
56
- :key="c.id"
57
- class="rounded border p-3 mt-2 mb-2"
48
+ v-if="loading"
58
49
  >
59
- <div class="flex items-center gap-3 mb-3 mt-2">
60
- <div
61
- v-if="c.profile?.image"
62
- class="flex-shrink-0"
63
- >
64
- <UAvatar
65
- :src="c.profile.image"
66
- :alt="c.profile.name || c.profile.display_name || 'User avatar'"
67
- class="w-8 h-8 rounded-full object-cover"
68
- />
69
- </div>
70
- <div class="flex-1 min-w-0">
71
- <div class="truncate">
72
- {{ c.profile?.display_name || c.profile?.name || `${c.pubkey.slice(0, 8)}\u2026` }}
73
- <span class="text-xs">{{ new Date(c.created_at * 1e3).toLocaleString() }}</span>
50
+ <ScaffoldComment />
51
+ </div>
52
+
53
+ <div
54
+ v-else
55
+ class="space-y-6"
56
+ >
57
+ <div
58
+ v-for="c in comments"
59
+ :key="c.id"
60
+ class="rounded border p-3 mt-2 mb-2"
61
+ >
62
+ <div class="flex items-center gap-3 mb-3 mt-2">
63
+ <div
64
+ v-if="c.profile?.image"
65
+ class="flex-shrink-0"
66
+ >
67
+ <UAvatar
68
+ :src="c.profile.image"
69
+ :alt="c.profile.name || c.profile.display_name || 'User avatar'"
70
+ class="w-8 h-8 rounded-full object-cover"
71
+ />
72
+ </div>
73
+ <div class="flex-1 min-w-0">
74
+ <div class="truncate">
75
+ {{ c.profile?.display_name || c.profile?.name || `${c.pubkey.slice(0, 8)}\u2026` }}
76
+ <span class="text-xs">{{ new Date(c.created_at * 1e3).toLocaleString() }}</span>
77
+ </div>
74
78
  </div>
75
79
  </div>
76
- </div>
77
- <div class="prose prose-sm prose-invert mt-2 mb-2">
78
- <!-- eslint-disable-next-line vue/no-v-html -->
79
- <div v-html="marked.parse(c.content)" />
80
+ <div class="prose prose-sm prose-invert mt-2 mb-2">
81
+ <!-- eslint-disable-next-line vue/no-v-html -->
82
+ <div v-html="marked.parse(c.content)" />
80
83
  <!-- eslint-disable-next-line vue/no-v-html -->
84
+ </div>
81
85
  </div>
82
- </div>
83
86
 
84
- <div
85
- v-if="isLoggedIn"
86
- class=" mt-5"
87
- />
87
+ <div
88
+ v-if="isLoggedIn"
89
+ class=" mt-5"
90
+ />
91
+ </div>
88
92
  </div>
89
- </div>
93
+ </ClientOnly>
90
94
  </div>
91
95
  </template>
92
96
 
@@ -1,14 +1,24 @@
1
1
  <script setup>
2
+ import { ref } from "vue";
2
3
  import { useNuxstrComments } from "../composables/useNuxstrComments";
3
4
  const props = defineProps({
4
5
  contentId: { type: String, required: false }
5
6
  });
7
+ const EMPTY_COMMENT = "";
6
8
  const { postComment } = useNuxstrComments(props.contentId);
7
- const comment = ref("");
9
+ const comment = ref(EMPTY_COMMENT);
10
+ function isValidComment(commentText) {
11
+ return commentText.trim().length > 0;
12
+ }
13
+ function clearComment() {
14
+ comment.value = EMPTY_COMMENT;
15
+ }
8
16
  async function handlePost() {
9
- if (!comment.value.trim()) return;
10
- const ok = await postComment(comment.value);
11
- if (ok) comment.value = "";
17
+ if (!isValidComment(comment.value)) return;
18
+ const wasPosted = await postComment(comment.value);
19
+ if (wasPosted) {
20
+ clearComment();
21
+ }
12
22
  }
13
23
  </script>
14
24
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@threenine/nuxstr-comments",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "description": "Nuxstr Comments",
5
5
  "repository": "threenine/nuxstr-comments",
6
6
  "license": "MIT",