|
| 1 | +<template> |
| 2 | + <div |
| 3 | + class="bg-darkBG dark:bg-gray5 modal-animation fixed top-0 bottom-0 left-0 right-0 z-30 flex h-screen w-full items-center justify-center bg-opacity-50 dark:bg-opacity-50" |
| 4 | + @click.self="$emit(`close`)" |
| 5 | + > |
| 6 | + <!-- Container --> |
| 7 | + <div |
| 8 | + v-if="postCID !== null" |
| 9 | + class="popup min-h-40 w-full lg:w-600 bg-lightBG dark:bg-darkBGStop card-animation max-h-90 z-10 overflow-y-auto rounded-lg px-6 pt-4 pb-2 shadow-lg" |
| 10 | + > |
| 11 | + <div class="sticky flex items-center justify-between mb-6"> |
| 12 | + <h2 class="text-lightPrimaryText dark:text-darkPrimaryText text-3xl font-semibold">Quoted this post</h2> |
| 13 | + <button class="focus:outline-none bg-gray1 dark:bg-gray5 rounded-full p-1" @click="$emit(`close`)"> |
| 14 | + <CloseIcon /> |
| 15 | + </button> |
| 16 | + </div> |
| 17 | + <div v-show="isLoading" class="modal-animation flex w-full justify-center z-20 mt-24"> |
| 18 | + <div |
| 19 | + class="loader m-5 border-2 border-gray1 dark:border-gray7 h-8 w-8 rounded-3xl" |
| 20 | + :style="`border-top: 2px solid` + $color.hex" |
| 21 | + ></div> |
| 22 | + </div> |
| 23 | + <article v-if="!isLoading"> |
| 24 | + <div v-for="p in quoteReposts" :key="p.authorID + p.timestamp" class="flex flex-col"> |
| 25 | + <div class="flex items-center"> |
| 26 | + <Avatar :avatar="p.avatar" :authorID="p.authorID" size="w-12 h-12" /> |
| 27 | + <div class="h-12 flex flex-col px-4"> |
| 28 | + <nuxt-link :to="`/id/` + p.authorID" class="flex items-center"> |
| 29 | + <span v-if="p.name != ``" class="text-base font-medium text-lightPrimaryText dark:text-darkPrimaryText"> |
| 30 | + {{ p.name }} |
| 31 | + </span> |
| 32 | + <span v-else class="text-gray5 dark:text-gray3 text-base font-medium"> {{ p.authorID }} </span> |
| 33 | + <span class="text-gray5 dark:text-gray3 text-sm ml-2">@{{ p.authorID }}</span> |
| 34 | + </nuxt-link> |
| 35 | + <span class="mt-1 text-xs text-gray5 dark:text-gray3">{{ $formatDate(p.timestamp) }}</span> |
| 36 | + </div> |
| 37 | + </div> |
| 38 | + <div |
| 39 | + class="my-4 pb-4 border-b border-lightBorder dark:border-darkBorder text-lightPrimaryText dark:text-darkPrimaryText" |
| 40 | + > |
| 41 | + {{ p.content }} |
| 42 | + </div> |
| 43 | + </div> |
| 44 | + </article> |
| 45 | + <p v-if="!isLoading && quoteReposts.length === 0" class="text-sm text-gray5 dark:text-gray3 text-center mt-14"> |
| 46 | + None of the reposters quoted this post |
| 47 | + </p> |
| 48 | + </div> |
| 49 | + </div> |
| 50 | +</template> |
| 51 | + |
| 52 | +<script lang="ts"> |
| 53 | +import Vue from 'vue' |
| 54 | +import CloseIcon from '@/components/icons/X.vue' |
| 55 | +import Avatar from '@/components/Avatar.vue' |
| 56 | +import { getReposts, IGetRepostsOptions } from '@/backend/reposts' |
| 57 | +import { getRegularPost } from '@/backend/post' |
| 58 | +
|
| 59 | +import { createDefaultProfile, getProfile, Profile } from '@/backend/profile' |
| 60 | +import { getPhotoFromIPFS } from '@/backend/getPhoto' |
| 61 | +
|
| 62 | +interface IData { |
| 63 | + isLoading: boolean |
| 64 | + profiles: Array<Profile> |
| 65 | + quoteReposters: Array<string> |
| 66 | + quoteReposts: Array<any> |
| 67 | + followers: Set<string> |
| 68 | +} |
| 69 | +
|
| 70 | +export default Vue.extend({ |
| 71 | + components: { CloseIcon, Avatar }, |
| 72 | + props: { |
| 73 | + postCID: { |
| 74 | + type: String, |
| 75 | + required: true, |
| 76 | + }, |
| 77 | + }, |
| 78 | + data(): IData { |
| 79 | + return { |
| 80 | + isLoading: true, |
| 81 | + profiles: [], |
| 82 | + quoteReposters: [], |
| 83 | + quoteReposts: [], |
| 84 | + followers: new Set(), |
| 85 | + } |
| 86 | + }, |
| 87 | + created() { |
| 88 | + this.getQuoteReposts() |
| 89 | + }, |
| 90 | + methods: { |
| 91 | + updateFollowers(): void { |
| 92 | + this.$emit(`updateFollowers`) |
| 93 | + }, |
| 94 | +
|
| 95 | + async getReposterProfile(p: string) { |
| 96 | + let profile = createDefaultProfile(p) |
| 97 | + let avatar = `` |
| 98 | + await getProfile(p).then((fetchedProfile) => { |
| 99 | + if (fetchedProfile.profile) { |
| 100 | + profile = fetchedProfile.profile |
| 101 | + } |
| 102 | + if (profile.avatar !== ``) { |
| 103 | + getPhotoFromIPFS(profile.avatar).then((a) => { |
| 104 | + avatar = a |
| 105 | + }) |
| 106 | + } |
| 107 | + }) |
| 108 | + return { profile, avatar } |
| 109 | + }, |
| 110 | + async getQuoteReposts() { |
| 111 | + const options: IGetRepostsOptions = { sort: `NEW`, offset: 0, limit: 1000, type: `quote` } |
| 112 | + const reposts = await getReposts({ postCID: this.postCID }, options) |
| 113 | + reposts.forEach((repost) => { |
| 114 | + this.fetchQuote(repost.repost._id, repost.repost.authorID) |
| 115 | + }) |
| 116 | + this.isLoading = false |
| 117 | + }, |
| 118 | + async fetchQuote(cid: string, authorID: string) { |
| 119 | + const { data: content } = await getRegularPost(cid) |
| 120 | + const { profile, avatar } = await this.getReposterProfile(authorID) |
| 121 | + const q = { |
| 122 | + content: content.content, |
| 123 | + timestamp: content.timestamp, |
| 124 | + authorID: content.authorID, |
| 125 | + name: profile.name, |
| 126 | + avatar, |
| 127 | + } |
| 128 | + this.quoteReposts.push(q) |
| 129 | + }, |
| 130 | + }, |
| 131 | +}) |
| 132 | +</script> |
0 commit comments