Skip to content

Commit 3a3e2a4

Browse files
committed
Add new Votes page and update index.ts
A new `Votes.astro` file has been added for the Votes page that fetches and displays poll options. The `index.ts` file was updated to include this new page and its path has been added to the page paths in `ClubsFunctionGetPagePaths`. These changes are crucial to facilitate the display and functionality of voting in the application.
1 parent 5ce593e commit 3a3e2a4

File tree

3 files changed

+109
-2
lines changed

3 files changed

+109
-2
lines changed

src/Pages/Votes.astro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
import {Option} from '../types';
3+
import {ClubsPropsPages, Membership} from '@devprotocol/clubs-core';
4+
import Votes from '../components/Pages/Votes.vue';
5+
import type {OptionsDatabase} from '@devprotocol/clubs-plugin-posts';
6+
7+
interface Props extends ClubsPropsPages {
8+
options: Option[]
9+
propertyAddress: string
10+
adminRolePoints: number
11+
rpcUrl: string
12+
feeds: OptionsDatabase[]
13+
}
14+
15+
const {
16+
options,
17+
feeds
18+
} = Astro.props
19+
---
20+
21+
<Votes client:load options={options} feeds={feeds} />

src/components/Pages/Votes.vue

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<script lang="ts" setup>
2+
3+
import type {Option} from '../../types.ts';
4+
import type {OptionsDatabase} from '@devprotocol/clubs-plugin-posts';
5+
import {decode} from '@devprotocol/clubs-core';
6+
import {onMounted, ref} from 'vue';
7+
8+
type Props = {
9+
options: Option[]
10+
feeds: OptionsDatabase[]
11+
}
12+
const props = defineProps<Props>()
13+
14+
const polls = ref([])
15+
const error = ref('')
16+
const isLoading = ref(true)
17+
18+
const fetchPolls = async () => {
19+
// これでPollのFeedをとってくる
20+
// http://localhost:4321/api/devprotocol:clubs:plugin:posts/default-2/search/has:option/%23poll
21+
22+
const url = new URL(
23+
`/api/devprotocol:clubs:plugin:posts/default-2/search/has:option/%23poll`,
24+
window.location.origin,
25+
)
26+
27+
fetch(url.toString())
28+
.then(async (res) => {
29+
console.log('res', res.status)
30+
if (res.status === 200) {
31+
const json = await res.json()
32+
polls.value = decode(json.contents)
33+
}
34+
})
35+
.catch((err) => {
36+
console.error(err)
37+
error.value =
38+
'Sorry, but there was an error loading the timeline. Please try again later.'
39+
})
40+
.finally(() => {
41+
isLoading.value = false
42+
})
43+
}
44+
45+
onMounted(async () => {
46+
await fetchPolls()
47+
console.log('mounted', polls.value)
48+
})
49+
50+
</script>
51+
52+
<template>
53+
<h1>Votes2</h1>
54+
</template>

src/index.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import type {
2-
ClubsFunctionGetApiPaths,
2+
ClubsFunctionGetApiPaths, ClubsFunctionGetPagePaths,
33
ClubsFunctionGetSlots,
44
ClubsFunctionPlugin,
55
ClubsPluginMeta,
66
} from '@devprotocol/clubs-core'
77
import { ClubsPluginCategory } from '@devprotocol/clubs-core'
8-
import { SlotName } from '@devprotocol/clubs-plugin-posts'
8+
import {type OptionsDatabase, SlotName} from '@devprotocol/clubs-plugin-posts'
99
import { votingHandler } from './ApiHandler'
1010
import Icon from './assets/images/Voting.png'
1111
import Preview1 from './assets/images/voting-preview01.png'
@@ -14,6 +14,8 @@ import Preview3 from './assets/images/voting-preview03.png'
1414
import Readme from './readme.astro'
1515
import AfterContentForm from './components/edit-after-content-form.astro'
1616
import AfterPostContent from './components/feed-after-post-content.astro'
17+
import type {UndefinedOr} from '@devprotocol/util-ts';
18+
import Votes from './Pages/Votes.astro'
1719

1820
export const getSlots = (async () => {
1921
return [
@@ -50,8 +52,38 @@ export const getApiPaths = (async () => {
5052
]
5153
}) satisfies ClubsFunctionGetApiPaths
5254

55+
const getPagePaths = (async (
56+
options,
57+
{propertyAddress, adminRolePoints, rpcUrl},
58+
{getPluginConfigById}
59+
) => {
60+
61+
const [postsPlugin] = getPluginConfigById('devprotocol:clubs:plugin:posts')
62+
63+
const feeds = postsPlugin?.options?.find(
64+
({key}: Readonly<{ readonly key: string }>) => key === 'feeds',
65+
)?.value as UndefinedOr<readonly OptionsDatabase[]>
66+
67+
const props = {
68+
options,
69+
propertyAddress,
70+
adminRolePoints,
71+
rpcUrl,
72+
feeds,
73+
}
74+
75+
return [{
76+
paths: ["votes"],
77+
component: Votes,
78+
props: {
79+
...props
80+
},
81+
}]
82+
}) satisfies ClubsFunctionGetPagePaths
83+
5384
export default {
5485
getSlots,
5586
meta,
5687
getApiPaths,
88+
getPagePaths,
5789
} satisfies ClubsFunctionPlugin

0 commit comments

Comments
 (0)