Skip to content

Commit beda927

Browse files
committed
Add postsPluginId and improve Polls functionality
This commit adds postsPluginId to the Astro.props in the Votes component and improves the functionality of Polls by adding more detailed attributes to the data. The commit also adds new dependencies to the project, including "@boringer-avatars/vue3", "remark", and "strip-markdown", for better handling of Markdown content and rendering user avatars. A new Vue component, Profile.vue, is also introduced for profile handling.
1 parent d7d7d34 commit beda927

File tree

3 files changed

+47
-34
lines changed

3 files changed

+47
-34
lines changed

src/Pages/Votes.astro

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,9 @@ interface Props extends ClubsPropsPages {
1616
const { options, feeds, postsPluginId } = Astro.props
1717
---
1818

19-
<Votes client:load options={options} feeds={feeds} postsPluginId={postsPluginId} />
19+
<Votes
20+
client:load
21+
options={options}
22+
feeds={feeds}
23+
postsPluginId={postsPluginId}
24+
/>

src/components/Pages/Votes.vue

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<script lang="ts" setup>
22
import type { Option } from '../../types.ts'
33
import type { OptionsDatabase, Posts } from '@devprotocol/clubs-plugin-posts'
4-
import {type ClubsProfile, decode} from '@devprotocol/clubs-core'
4+
import { type ClubsProfile, decode } from '@devprotocol/clubs-core'
55
import { onMounted, ref } from 'vue'
6-
import Profile from '../Votes/Profile.vue';
7-
import IconLock from '../../assets/images/icon-lock.png';
8-
import {remark} from 'remark';
6+
import Profile from '../Votes/Profile.vue'
7+
import IconLock from '../../assets/images/icon-lock.png'
8+
import { remark } from 'remark'
99
import strip from 'strip-markdown'
1010
1111
type Props = {
@@ -27,8 +27,8 @@ type Polls = {
2727
type PostsPlus = Posts & {
2828
image: string
2929
profile: Promise<{
30-
readonly profile: ClubsProfile | undefined;
31-
readonly error: Error | undefined;
30+
readonly profile: ClubsProfile | undefined
31+
readonly error: Error | undefined
3232
}>
3333
stripedMarkdown: string
3434
}
@@ -48,34 +48,37 @@ const fetchPolls = async (feed: OptionsDatabase): Promise<Polls> => {
4848
const json = await res.json()
4949
5050
return {
51-
title: title ? title : feedId.value,
52-
values: decode(json.contents)
51+
title: title ? title : feedId.value,
52+
values: decode(json.contents),
5353
}
5454
}
5555
5656
onMounted(async () => {
57-
await Promise.all(feeds.map(async (feed) => {
58-
const data = await fetchPolls(feed)
59-
60-
data.values = data.values.map((post) => {
61-
post.updated_at = new Date(post.updated_at).toLocaleString('ja-JP')
62-
63-
const images = post.options.find((item) => item.key === '#images')
64-
if (images && images.value.length > 0) {
65-
post.image = images.value[0]
66-
}
67-
68-
remark()
69-
.use(strip)
70-
.process(post.content).then((text) => {
57+
await Promise.all(
58+
feeds.map(async (feed) => {
59+
const data = await fetchPolls(feed)
60+
61+
data.values = data.values.map((post) => {
62+
post.updated_at = new Date(post.updated_at).toLocaleString('ja-JP')
63+
64+
const images = post.options.find((item) => item.key === '#images')
65+
if (images && images.value.length > 0) {
66+
post.image = images.value[0]
67+
}
68+
69+
remark()
70+
.use(strip)
71+
.process(post.content)
72+
.then((text) => {
7173
post.stripedMarkdown = text.toString()
72-
})
74+
})
7375
74-
return post
75-
})
76+
return post
77+
})
7678
77-
polls.value = [...polls.value, data]
78-
}))
79+
polls.value = [...polls.value, data]
80+
}),
81+
)
7982
})
8083
</script>
8184

@@ -98,7 +101,10 @@ onMounted(async () => {
98101
<p v-if="true" class="flex-grow flex-wrap text-lg truncate">
99102
{{ post.stripedMarkdown }}
100103
</p>
101-
<div v-else class="flex flex-col justify-center items-center flex-grow p-2 bg-gray-200 rounded">
104+
<div
105+
v-else
106+
class="flex flex-col justify-center items-center flex-grow p-2 bg-gray-200 rounded"
107+
>
102108
<img
103109
class="mb-1 w-5"
104110
:src="IconLock.src"
@@ -109,14 +115,16 @@ onMounted(async () => {
109115
</div>
110116
</div>
111117
<figure v-if="!isMasked && post.image">
112-
<img :src="post.image" class="rounded max-w-20 max-h-20 object-cover object-center" alt="post image" />
118+
<img
119+
:src="post.image"
120+
class="rounded max-w-20 max-h-20 object-cover object-center"
121+
alt="post image"
122+
/>
113123
</figure>
114124
</div>
115125
</a>
116126
<div v-if="poll.length < 1" class="mb-4 p-2 bg-gray-100 rounded">
117-
<p class="w-full text-gray-400 text-center">
118-
Empty :)
119-
</p>
127+
<p class="w-full text-gray-400 text-center">Empty :)</p>
120128
</div>
121129
</div>
122130
</div>

src/components/Votes/Profile.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { onMounted, ref } from 'vue'
33
import { ZeroAddress } from 'ethers'
44
import { Avatar } from '@boringer-avatars/vue3'
5-
import {fetchProfile} from '@devprotocol/clubs-core';
5+
import { fetchProfile } from '@devprotocol/clubs-core'
66
77
type Props = {
88
address: string

0 commit comments

Comments
 (0)