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

fix: adjust imageSrc on carousel component #6599

Merged
merged 10 commits into from
Aug 10, 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
18 changes: 6 additions & 12 deletions components/carousel/module/CarouselMedia.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,17 @@
<nuxt-link
:to="urlOf({ id: item.id, url, chain: item.chain })"
rel="nofollow">
<PreviewMediaResolver
v-if="item.animationUrl"
:src="item.animationUrl"
:poster="imageSrc || ''"
:metadata="item.metadata" />
<BasicImage
v-else
:src="imageSrc"
:alt="item.name"
custom-class="carousel__image-wrapper" />
vikiival marked this conversation as resolved.
Show resolved Hide resolved
<MediaItem
class="carousel-media-wrapper"
:src="imageSrc || ''"
:animation-src="item.animationUrl || ''"
:title="item.name" />
</nuxt-link>
</div>
</template>

<script lang="ts" setup>
import PreviewMediaResolver from '@/components/media/PreviewMediaResolver.vue'
import BasicImage from '@/components/shared/view/BasicImage.vue'
import { MediaItem } from '@kodadot1/brick'

import type { CarouselNFT } from '@/components/base/types'
import type { NFTWithMetadata } from '@/composables/useNft'
Expand Down
36 changes: 25 additions & 11 deletions components/gallery/GalleryItemDescription.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,21 @@
<p>{{ nft?.royalty }}%</p>
</div>
<hr class="my-2" />
<div class="is-flex is-justify-content-space-between">
<div v-if="nftImage" class="is-flex is-justify-content-space-between">
<p>{{ $t('tabs.tabDetails.media') }}</p>
<a
:href="nftAnimation || nftImage"
target="_blank"
rel="nofollow noopener noreferrer"
class="has-text-link"
data-cy="media-link"
>{{ nftMimeType }}</a
>
<div @click="openLink(nftImage)">
<a class="has-text-link" data-cy="media-link">
{{ nftMimeType }}
</a>
</div>
</div>
<div v-if="nftAnimation" class="is-flex is-justify-content-space-between">
<p>{{ $t('tabs.tabDetails.animatedMedia') }}</p>
<div @click="openLink(nftAnimation)">
<a class="has-text-link">
{{ animationMediaMimeType }}
</a>
</div>
</div>
<div class="is-flex is-justify-content-space-between">
<p>{{ $t('tabs.tabDetails.metadata') }}</p>
Expand Down Expand Up @@ -121,7 +126,6 @@
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">
Expand All @@ -134,6 +138,7 @@
</template>

<script setup lang="ts">
import { obtainMimeType } from '@kodadot1/minipfs'
import {
MediaItem,
NeoTabItem,
Expand All @@ -143,7 +148,7 @@ import {
NeoTooltip,
} from '@kodadot1/brick'
import Identity from '@/components/identity/IdentityIndex.vue'
import { sanitizeIpfsUrl } from '@/utils/ipfs'
import { sanitizeIpfsUrl, toCloudflareIpfsUrl } from '@/utils/ipfs'

import { GalleryItem, useGalleryItem } from './useGalleryItem'

Expand Down Expand Up @@ -218,6 +223,7 @@ const propertiesTabDisabled = computed(() => {

const metadataMimeType = ref('application/json')
const metadataURL = ref('')
const animationMediaMimeType = ref('')

watchEffect(async () => {
if (nft.value?.metadata) {
Expand All @@ -230,5 +236,13 @@ watchEffect(async () => {
response.headers.get('content-type') || 'application/json'
metadataURL.value = sanitizeMetadata
}

if (nftAnimation.value) {
animationMediaMimeType.value = await obtainMimeType(nftAnimation.value)
}
})

const openLink = (link) => {
window.open(toCloudflareIpfsUrl(link), '_blank')
}
</script>
3 changes: 2 additions & 1 deletion composables/useNft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async function getProcessMetadata(nft: NFTWithMetadata) {
const metadata = (await processSingleMetadata(
nft.metadata
)) as NFTWithMetadata
const image = sanitizeIpfsUrl(metadata.image || '')
const image = sanitizeIpfsUrl(metadata.image || metadata.mediaUri || '')
const animation_url = sanitizeIpfsUrl(metadata.animation_url || '')
const getAttributes = () => {
const hasMetadataAttributes =
Expand Down Expand Up @@ -79,6 +79,7 @@ export function getNftMetadata(nft: NFTWithMetadata, prefix: string) {
if (prefix === 'stmn' || prefix === 'stt') {
return getProcessMetadata(nft)
}

if (nft.meta && nft.meta.image) {
return getGeneralMetadata(nft)
}
Expand Down
1 change: 1 addition & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,7 @@
"tokenStandard": "Token Standard",
"royalties": "Royalties",
"media": "Media",
"animatedMedia": "Animated Media",
"metadata": "Metadata"
},
"tabActivity": {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"@google/model-viewer": "^1.12.1",
"@kodadot1/brick": "workspace:*",
"@kodadot1/minimark": "^0.1.10",
"@kodadot1/minipfs": "0.4.0-rc.0",
"@kodadot1/static": "workspace:*",
"@kodadot1/sub-api": "^0.1.2",
"@kodadot1/vuex-options": "0.1.5",
Expand Down
20 changes: 14 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion styles/components/_carousel.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
&:hover {
border-color: theme('border-color');
.carousel-media {
opacity: theme('card-hover-opacity');}
opacity: theme('card-hover-opacity');
}
}
}
}
Expand All @@ -34,6 +35,11 @@
display: block;
}
}

&-wrapper {
box-shadow: none !important;
border: none !important;
}
}

.carousel-info {
Expand Down
5 changes: 5 additions & 0 deletions utils/ipfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,8 @@ export type EntityWithMeta = {
metadata: string
meta?: NFTMetadata
}

export function toCloudflareIpfsUrl(baseurl) {
const url = new URL(baseurl)
return `https://cloudflare-ipfs.com/${url.pathname}`
}
Loading