Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FeedItem checks if id is curation or not #108

Merged
merged 4 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 83 additions & 21 deletions components/FeedItemCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
cols="12"
class="text-h5 font-weight-md-thin scale-text text-center"
>
{{ id }}
{{ props.id }}
</v-col>
<v-col cols="12">
<v-progress-linear
Expand Down Expand Up @@ -68,12 +68,14 @@
<v-row align="end" class="fill-height pa-1 pl-4">
<v-col>
<a class="text-white font-weight-bold">
{{ artwork?.publication.title }}
{{
isCuration ? data?.title : data?.publication?.title
}}
</a>
<br>
<a class="text-white font-italic">
<ResolveUsername
:address="artwork ? artwork.publication.creator : ''"
:address="`${itemAddress}`"
no-link
/>
</a>
Expand Down Expand Up @@ -105,48 +107,108 @@


<script setup lang="ts">
import { RouteLocationRaw } from '.nuxt/vue-router'
import { VImg } from 'vuetify/lib/components/index.mjs'
import {
CollaborativeWhitelistCurationState
} from '@artbycity/sdk/dist/web/curations'

const img = ref<VImg>()

const hasError = computed(() => {
if (pending.value) { return false }

return artwork.value === null
return data.value === null
})

const props = defineProps<{ id: string, to?: RouteLocationRaw }>()
const props = defineProps<{ id: string }>()
const abc = useArtByCity()
const { protocol, host, port } = abc.arweave.api.config
const gatewayBase = `${protocol}://${host}:${port}`
const isCuration = ref<boolean>(false)

const { data: artwork, pending } = useLazyAsyncData(props.id, async () => {
const publication = await abc.legacy.fetchPublication(props.id)
const username =
await abc.usernames.resolveUsernameFromAddress(publication.creator)
const { data, pending } = useLazyAsyncData(props.id, async () => {
const checkId = await abc.curations.getTransaction(props.id)

return { publication, username }
if (checkId) {
if (checkId.tags.find(o => o.name === 'Entity-Type')?.value === 'curation'){
isCuration.value = true
try {
const curation = abc
.curations
.get<CollaborativeWhitelistCurationState>(props.id)

const { cachedValue: { state } } = await curation.contract.readState()
const curatedPublications = []

let count = 0
for (let i of state.items) {
curatedPublications.push(
await abc.legacy.fetchPublication(i)
)
count += 1
if (count === 3){ break }
}

return {
contract: curation,
title: state.title,
desc: state.metadata.description as string,
state,
curatedPublications,
username: await abc.usernames.resolveUsernameFromAddress(state.owner)
}
} catch (error) {
console.error('Error fetching curation', props.id, error)
}
} else {
const publication = await abc.legacy.fetchPublication(props.id)
const username =
await abc.usernames.resolveUsernameFromAddress(publication.creator)

return { publication, username }
}
}
})

const src = computed(() => {
if (!artwork.value?.publication) { return '' }
if (!data.value) { return '' }

return artwork.value.publication.image.preview.startsWith('data:image')
? artwork.value.publication.image.preview
: `${gatewayBase}/${artwork.value.publication.image.preview}`
if (data.value.publication) {
return data.value.publication.image.preview.startsWith('data:image')
? data.value.publication.image.preview
: `${gatewayBase}/${data.value.publication.image.preview}`
} else if (data.value.curatedPublications) {
return data.value.curatedPublications[0]?.image.preview
.startsWith('data:image')
? data.value.curatedPublications[0]?.image.preview
: `${gatewayBase}/${data.value.curatedPublications[0]?.image.preview}`
}

})

const isPlayable = computed(() => {
if (!artwork.value?.publication) { return false }
if (!data.value) { return false }

return artwork.value.publication.image.animated ||
!!artwork.value.publication.audio || !!artwork.value.publication.model
if (!isCuration.value) {
return data.value.publication?.image.animated
|| !!data.value.publication?.audio
|| !!data.value.publication?.model
}
})

const to = computed(() => {
return `/${artwork.value?.username || artwork.value?.publication.creator}/${
artwork.value?.publication.slug || artwork.value?.publication.id
}` || props.to
if (!isCuration.value) {
return `/${data.value?.username || data.value?.publication?.creator}/${
data.value?.publication?.slug || data.value?.publication?.id
}`
} else {
return `/curations/${data.value?.contract?.contractId}`
}
})

const itemAddress = computed(() => {
return isCuration.value
? data?.value?.state?.owner
: data?.value?.publication?.creator
})
</script>
43 changes: 24 additions & 19 deletions pages/curations/[curationId]/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,30 @@
</span>
</v-col>
<v-col cols="3">
<v-btn
v-if="isAuthedUserOwner"
variant="outlined"
color="primary"
elevation="2"
density="compact"
:to="`/curations/${curationId}/edit`"
>
Edit
</v-btn>
<v-btn
variant="outlined"
color="primary"
elevation="2"
density="compact"
:to="`/portals/${curationId}`"
>
Portal
</v-btn>
<CurateMenu :item="curation.contract.contractId" class="ml-7" />
<v-row>
<v-col>
<v-btn
v-if="isAuthedUserOwner"
variant="outlined"
color="primary"
elevation="2"
density="compact"
:to="`/curations/${curationId}/edit`"
>
Edit
</v-btn>
<v-btn
variant="outlined"
color="primary"
elevation="2"
density="compact"
:to="`/portals/${curationId}`"
>
Portal
</v-btn>
</v-col>
</v-row>
</v-col>
</v-row>
<v-row dense>
Expand Down
1 change: 0 additions & 1 deletion pages/discover/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<v-col cols="12" md="6" lg="9" xl="10" xxl="12">
<FeedItemCard
:id="pub.id"
:to="`/${pub.creator}/${pub.slug || pub.id}`"
/>
</v-col>
</v-row>
Expand Down
Loading