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

feat: Add parent tab to GalleryItemDescription #5735

Merged
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
42 changes: 41 additions & 1 deletion components/gallery/GalleryItemDescription.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,29 @@
>
</div>
</o-tab-item>

<!-- parent tab -->
<div v-if="parent">
<o-tab-item value="3" :label="$t('tabs.parent')" class="p-5">
<nuxt-link :to="parentNftUrl">
<MediaItem
:key="parent?.nftImage"
:class="{
'is-flex is-align-items-center is-justify-content-center h-audio':
resolveMedia(parent?.nftMimeType.value) == MediaType.AUDIO,
}"
class="gallery-parent-item"
:src="parent?.nftImage.value"
:animation-src="parent?.nftAnimation.value"
:mime-type="parent?.nftMimeType.value"
:title="parent?.nftMetadata?.value?.name"
is-detail />
<p class="gallery-parent-item__name">
{{ parent?.nftMetadata?.value?.name }}
</p>
</nuxt-link>
</o-tab-item>
</div>
</o-tabs>
</template>

Expand All @@ -99,17 +122,34 @@ import { OTabItem, OTable, OTableColumn, OTabs } from '@oruga-ui/oruga'
import Identity from '@/components/identity/IdentityIndex.vue'
import { sanitizeIpfsUrl } from '@/utils/ipfs'

import { DisablableTab } from '@kodadot1/brick'
import { DisablableTab, MediaItem } from '@kodadot1/brick'

import { useGalleryItem } from './useGalleryItem'
import { useRedirectModal } from '@/components/redirect/useRedirectModal'

import { MediaType } from '@/components/rmrk/types'
import { resolveMedia } from '@/utils/gallery/media'

const { urlPrefix } = usePrefix()
const { nft, nftMimeType, nftMetadata, nftImage, nftAnimation } =
useGalleryItem()
const activeTab = ref('0')
const { version } = useRmrkVersion()

const parent = computed(() => {
if (nft.value?.parent?.id) {
return useGalleryItem(nft.value?.parent?.id)
}
})

const parentNftUrl = computed(() => {
if (parent.value) {
const url = inject('itemUrl', 'gallery') as string

return `/${urlPrefix.value}/${url}/${parent.value?.nft.value?.id}`
}
})

const properties = computed(() => {
// we have different format between rmrk2 and the other chains
if (urlPrefix.value === 'ksm') {
Expand Down
9 changes: 5 additions & 4 deletions components/gallery/useGalleryItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const whichAsset = (data) => {
}
}

export const useGalleryItem = () => {
export const useGalleryItem = (nftId?: string) => {
const { $consola } = useNuxtApp()
const historyStore = useHistoryStore()
const nft = ref<NFT>()
Expand All @@ -41,6 +41,7 @@ export const useGalleryItem = () => {
const nftMetadata = ref<NFTWithMetadata>()

const { params } = useRoute()
const id = nftId || params.id
// const { id: collectionID, item: id } = tokenIdToRoute(params.id)

const queryPath = {
Expand All @@ -53,15 +54,15 @@ export const useGalleryItem = () => {
queryName: 'nftById',
queryPrefix: queryPath[urlPrefix.value],
variables: {
id: params.id,
id,
},
options: {
fetchPolicy: 'network-only',
},
})

useSubscriptionGraphql({
query: ` nft: nftEntityById(id: "${params.id}") {
query: ` nft: nftEntityById(id: "${id}") {
id
currentOwner
price
Expand All @@ -76,7 +77,7 @@ export const useGalleryItem = () => {
watch(data as unknown as NFTData, async (newData) => {
const nftEntity = newData?.nftEntity
if (!nftEntity) {
$consola.log(`NFT with id ${params.id} not found. Fallback to RPC Node`)
$consola.log(`NFT with id ${id} not found. Fallback to RPC Node`)
return
}

Expand Down
1 change: 1 addition & 0 deletions components/rmrk/service/scheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ export interface NFT extends ItemResources {
royalty?: number
recipient?: string
meta?: NFTMetadata
parent?: NFT
}

export type EntityWithId = {
Expand Down
1 change: 1 addition & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,7 @@
"noPropertiesForNFT": "No Properties for this NFT",
"description": "Description",
"details": "Details",
"parent": "Parent",
"offers": "Offers",
"offersDisabled": "Offers Are Not Available on this chain",
"activity": "Activity",
Expand Down
10 changes: 10 additions & 0 deletions queries/subsquid/ksm/nftById.graphql
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
#import "../../fragments/nft.graphql"
#import "../../fragments/nftDetails.graphql"
#import "../../fragments/baseMeta.graphql"

query nftById($id: String!) {
nftEntity: nftEntityById(id: $id) {
...nft
...nftDetails
royalty
recipient
parent {
...nft
...nftDetails
meta {
image
animation_url: animationUrl
...baseMeta
}
}
collection {
id
name
Expand Down
10 changes: 10 additions & 0 deletions queries/subsquid/rmrk/nftById.graphql
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
#import "../../fragments/nft.graphql"
#import "../../fragments/nftDetails.graphql"
#import "../../fragments/baseMeta.graphql"

query nftById($id: String!) {
nftEntity: nftEntityById(id: $id) {
...nft
...nftDetails
parent {
...nft
...nftDetails
meta {
image
animation_url: animationUrl
...baseMeta
}
}
collection {
id
name
Expand Down
12 changes: 12 additions & 0 deletions styles/components/_gallery-item.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@
}
}

.gallery-parent-item {
max-height: 240px;
max-width: 240px;
margin: 0 auto;

&__name {
padding-top: 0.25rem;
width: fit-content;
margin: 0 auto;
}
}

.gallery-item {
.media-object {
@include ktheme() {
Expand Down