generated from dev-protocol/clubs-plugin-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #480 from dev-protocol/feature/create-votes-page
投票一覧ページ
- Loading branch information
Showing
8 changed files
with
285 additions
and
6,570 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--- | ||
import { Option } from '../types' | ||
import { ClubsPropsPages, Membership } from '@devprotocol/clubs-core' | ||
import Votes from '../components/Pages/Votes.vue' | ||
import type { OptionsDatabase } from '@devprotocol/clubs-plugin-posts' | ||
interface Props extends ClubsPropsPages { | ||
options: Option[] | ||
propertyAddress: string | ||
adminRolePoints: number | ||
rpcUrl: string | ||
feeds: OptionsDatabase[] | ||
postsPluginId: string | ||
} | ||
const { options, feeds, postsPluginId } = Astro.props | ||
--- | ||
|
||
<Votes | ||
client:load | ||
options={options} | ||
feeds={feeds} | ||
postsPluginId={postsPluginId} | ||
/> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
<script lang="ts" setup> | ||
import type { Option } from '../../types.ts' | ||
import type { OptionsDatabase, Posts } from '@devprotocol/clubs-plugin-posts' | ||
import { type ClubsProfile, decode } from '@devprotocol/clubs-core' | ||
import { onMounted, ref } from 'vue' | ||
import Profile from '../Votes/Profile.vue' | ||
import IconLock from '../../assets/images/icon-lock.png' | ||
import { remark } from 'remark' | ||
import strip from 'strip-markdown' | ||
type Props = { | ||
options: Option[] | ||
feeds: OptionsDatabase[] | ||
postsPluginId: string | ||
} | ||
const props = defineProps<Props>() | ||
const polls = ref<any[]>([]) | ||
const { postsPluginId, feeds } = props | ||
type Polls = { | ||
title: string | ||
values: PostsPlus[] | ||
} | ||
type PostsPlus = Posts & { | ||
image: string | ||
profile: Promise<{ | ||
readonly profile: ClubsProfile | undefined | ||
readonly error: Error | undefined | ||
}> | ||
stripedMarkdown: string | ||
} | ||
const feedId = ref('') | ||
const fetchPolls = async (feed: OptionsDatabase): Promise<Polls> => { | ||
feedId.value = feed.id | ||
const title = feed.title | ||
const url = new URL( | ||
`/api/${postsPluginId}/${feedId.value}/search/has:option/%23poll`, | ||
window.location.origin, | ||
) | ||
const res = await fetch(url.toString()) | ||
const json = await res.json() | ||
return { | ||
title: title ? title : feedId.value, | ||
values: decode(json.contents), | ||
} | ||
} | ||
onMounted(async () => { | ||
await Promise.all( | ||
feeds.map(async (feed) => { | ||
const data = await fetchPolls(feed) | ||
data.values = data.values.map((post) => { | ||
post.updated_at = new Date(post.updated_at).toLocaleString('ja-JP') | ||
const images = post.options.find((item) => item.key === '#images') | ||
if (images && images.value.length > 0) { | ||
post.image = images.value[0] | ||
} | ||
remark() | ||
.use(strip) | ||
.process(post.content) | ||
.then((text) => { | ||
post.stripedMarkdown = text.toString() | ||
}) | ||
return post | ||
}) | ||
polls.value = [...polls.value, data] | ||
}), | ||
) | ||
}) | ||
</script> | ||
|
||
<template> | ||
<div class="p-4"> | ||
<div v-for="poll in polls" :key="poll.title"> | ||
<h2 class="mb-4 text-xl">{{ poll.title }}</h2> | ||
<a | ||
v-for="post in poll.values" | ||
:key="post.id" | ||
:href="`/posts/${feedId}/${post.id}`" | ||
class="block mb-4 p-2 bg-gray-100 rounded" | ||
> | ||
<div class="flex justify-between gap-2"> | ||
<div class="w-full"> | ||
<p class="text-lg font-bold">Post_title: {{ post.title }}</p> | ||
<p class="mb-1 text-xs text-gray-400">{{ post.updated_at }}</p> | ||
<div class="flex justify-between gap-2"> | ||
<Profile :address="post.created_by" /> | ||
<p v-if="true" class="flex-grow flex-wrap text-lg truncate"> | ||
{{ post.stripedMarkdown }} | ||
</p> | ||
<div | ||
v-else | ||
class="flex flex-col justify-center items-center flex-grow p-2 bg-gray-200 rounded" | ||
> | ||
<img | ||
class="mb-1 w-5" | ||
:src="IconLock.src" | ||
alt="paper-airplane" | ||
/> | ||
<p class="leading-none">Locked</p> | ||
</div> | ||
</div> | ||
</div> | ||
<figure v-if="!isMasked && post.image"> | ||
<img | ||
:src="post.image" | ||
class="rounded max-w-20 max-h-20 object-cover object-center" | ||
alt="post image" | ||
/> | ||
</figure> | ||
</div> | ||
</a> | ||
<div v-if="poll.length < 1" class="mb-4 p-2 bg-gray-100 rounded"> | ||
<p class="w-full text-gray-400 text-center">Empty :)</p> | ||
</div> | ||
</div> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<script setup lang="ts"> | ||
import { onMounted, ref } from 'vue' | ||
import { ZeroAddress } from 'ethers' | ||
import { Avatar } from '@boringer-avatars/vue3' | ||
import { fetchProfile } from '@devprotocol/clubs-core' | ||
type Props = { | ||
address: string | ||
} | ||
const props = defineProps<Props>() | ||
const avatar = ref('') | ||
const name = ref('') | ||
onMounted(() => { | ||
if (!props.address || props.address === ZeroAddress) { | ||
name.value = truncateEthAddress(props.address) | ||
return | ||
} | ||
// fetch profile | ||
getProfile(props.address) | ||
}) | ||
const truncateEthAddress = (address: string) => { | ||
const match = address.match( | ||
/^(0x[a-zA-Z0-9]{4})[a-zA-Z0-9]+([a-zA-Z0-9]{4})$/, | ||
) | ||
if (!match) return address | ||
return `${match[1]}\u2026${match[2]}` | ||
} | ||
const getProfile = async (address: string) => { | ||
const res = await fetchProfile(address) | ||
if (res?.error) { | ||
console.error(res.error) | ||
return | ||
} | ||
avatar.value = res?.profile?.avatar || '' | ||
name.value = res?.profile?.username ?? truncateEthAddress(address) | ||
} | ||
</script> | ||
|
||
<template> | ||
<div class=""> | ||
<template v-if="avatar"> | ||
<div | ||
class="h-8 w-8 rounded-full bg-cover bg-center bg-no-repeat" | ||
:style="`background-image: url(${avatar})`" | ||
/> | ||
</template> | ||
<template v-else> | ||
<Avatar | ||
class="" | ||
:title="false" | ||
:size="32" | ||
variant="beam" | ||
:name="props.address" | ||
:square="false" | ||
/> | ||
</template> | ||
</div> | ||
</template> | ||
|
||
<style scoped> | ||
.posts-username { | ||
overflow: hidden; | ||
display: -webkit-box; | ||
-webkit-box-orient: vertical; | ||
-webkit-line-clamp: 2; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.