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

refactor: move media from rmrk/Media/ to media/ #3718

Merged
merged 30 commits into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
cda8366
test composition api in nuxt
preschian Aug 10, 2022
957abcf
revert nuxt-bridge version
preschian Aug 10, 2022
b73c188
test webpack optimisation
preschian Aug 10, 2022
f09640f
revert
preschian Aug 10, 2022
0039046
use classic nuxt
preschian Aug 10, 2022
6345d6a
cleanup
preschian Aug 10, 2022
16cfea3
Merge branch 'main' of github.com:preschian/nft-gallery into test-com…
preschian Aug 11, 2022
d068de4
convert basic image to composition api
preschian Aug 11, 2022
931b707
move some media components
preschian Aug 12, 2022
2fc13b4
update previewMediaResolver
preschian Aug 12, 2022
ce25ed2
adjust props
preschian Aug 12, 2022
71c5a60
fallback src
preschian Aug 12, 2022
5b78797
remove unused test page
preschian Aug 12, 2022
34ec520
fix deepscan, log event
preschian Aug 12, 2022
7ddcc22
fix deepsource, adjust props and sort imports
preschian Aug 12, 2022
05df1e1
log ev
preschian Aug 12, 2022
d2a8ca5
fix deepsource, set default props on non-required props
preschian Aug 12, 2022
1f79d64
fix review, reorder SFC
preschian Aug 12, 2022
e45bafa
unused defineProps
preschian Aug 12, 2022
d23c5f9
remove axios
preschian Aug 13, 2022
5365b70
use $fetch
preschian Aug 13, 2022
89fd780
Merge branch 'main' of github.com:preschian/nft-gallery into refactor…
preschian Aug 13, 2022
38213f8
fix review, enable auto-imports in editor linter
preschian Aug 14, 2022
e0b27b5
Merge branch 'main' into refactor-media-components
yangwao Aug 15, 2022
a9a40cb
Merge branch 'main' into refactor-media-components
yangwao Aug 15, 2022
5e089cd
fix review, unify import
preschian Aug 15, 2022
2e0e244
update media utils use ohmyfetch
preschian Aug 16, 2022
b0c535e
Merge branch 'main' of github.com:preschian/nft-gallery into refactor…
preschian Aug 16, 2022
e62e696
Merge branch 'main' into refactor-media-components
yangwao Aug 16, 2022
4de15a3
Merge branch 'main' into refactor-media-components
roiLeo Aug 16, 2022
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
7 changes: 4 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ module.exports = {
node: true,
},
extends: [
'eslint:recommended',
'plugin:vue/essential',
'plugin:vue/recommended',
'plugin:@typescript-eslint/recommended',
'prettier',
],
parser: 'vue-eslint-parser',
parserOptions: {
ecmaVersion: 11,
parser: '@typescript-eslint/parser',
ecmaVersion: 2020,
sourceType: 'module',
},
plugins: ['vue', 'prettier', '@typescript-eslint', 'unicorn'],
Expand All @@ -33,6 +33,7 @@ module.exports = {
quotes: ['error', 'single'],
semi: ['error', 'never'],
'max-classes-per-file': ['error', 2],
'sort-imports': ['warn', { allowSeparatedGroups: true }],
},
ignorePatterns: ['*.md'],
overrides: [
Expand Down
7 changes: 4 additions & 3 deletions components/base/CarouselCardList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,12 @@
</template>

<script lang="ts">
import { Component, mixins, Prop } from 'nuxt-property-decorator'
import { Component, Prop, mixins } from 'nuxt-property-decorator'

import AuthMixin from '@/utils/mixins/authMixin'
import PrefixMixin from '@/utils/mixins/prefixMixin'

import type { CarouselNFT } from './types'
import PrefixMixin from '~/utils/mixins/prefixMixin'

const components = {
Loader: () => import('@/components/shared/Loader.vue'),
Expand All @@ -94,7 +95,7 @@ const components = {
BasicImage: () => import('@/components/shared/view/BasicImage.vue'),
Appreciation: () => import('@/components/rmrk/Gallery/Appreciation.vue'),
PreviewMediaResolver: () =>
import('@/components/rmrk/Media/PreviewMediaResolver.vue'),
import('@/components/media/PreviewMediaResolver.vue'),
}

@Component<CarouselList>({
Expand Down
39 changes: 39 additions & 0 deletions components/media/MediaResolver.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<template>
<component
:is="resolveComponent"
v-if="src"
:src="src"
:poster="poster || '/placeholder.webp'"
:description="description"
:preview="preview"
:available-animations="availableAnimations" />
</template>

<script lang="ts" setup>
import { resolveMedia } from '@/utils/gallery/media'

const props = defineProps<{
src?: string
mimeType?: string
poster?: string
description?: string
availableAnimations?: string[]
preview?: boolean
}>()

const SUFFIX = 'Media'
const components = {
VideoMedia: defineAsyncComponent(() => import('./type/VideoMedia.vue')),
ImageMedia: defineAsyncComponent(() => import('./type/ImageMedia.vue')),
AudioMedia: defineAsyncComponent(() => import('./type/AudioMedia.vue')),
JsonMedia: defineAsyncComponent(() => import('./type/JsonMedia.vue')),
ModelMedia: defineAsyncComponent(() => import('./type/ModelMedia.vue')),
IFrameMedia: defineAsyncComponent(() => import('./type/IFrameMedia.vue')),
ObjectMedia: defineAsyncComponent(() => import('./type/ObjectMedia.vue')),
Media: defineAsyncComponent(() => import('./type/UnknownMedia.vue')),
}

const resolveComponent = computed(() => {
preschian marked this conversation as resolved.
Show resolved Hide resolved
return components[resolveMedia(props.mimeType) + SUFFIX]
})
</script>
53 changes: 53 additions & 0 deletions components/media/PreviewMediaResolver.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<template>
<MediaResolver
:src="properSrc"
:mime-type="properType"
:poster="poster"
preview />
</template>

<script lang="ts" setup>
import { get, update } from 'idb-keyval'
import { $fetch } from 'ohmyfetch'

import { NFTMetadata } from '@/components/rmrk/service/scheme'

const MediaResolver = defineAsyncComponent(
() => import('@/components/media/MediaResolver.vue')
)

const props = defineProps({
src: { type: String, default: '' },
metadata: { type: String, default: '' },
mimeType: { type: String, default: '' },
poster: { type: String, default: '' },
})

const type = ref('')

const properType = computed(() => props.mimeType || type.value || 'image/webp')
const properSrc = computed(() => props.src || '/placeholder.webp')

const fetchMimeType = async () => {
if (props.mimeType) {
return
}

const nftMetadata = await get<NFTMetadata>(props.metadata)
type.value = nftMetadata?.type || ''

if (!type.value) {
const response = await $fetch(props.src, { method: 'HEAD' })
type.value = response.type

update(props.metadata, (cached) => ({
...(cached || {}),
type: type.value,
}))
}
}

onMounted(() => {
fetchMimeType()
})
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,13 @@
played-line-color="rgba(0,0,0,0.74)"
noplayed-line-color="#d32e79"
playtime-font-color="rgba(0,0,0,0.74)" />
<!-- <audio controls class="media-audio__player">
<source :src="src" :type="mimeType" />
Unable to show audio
</audio> -->
</div>
</template>

<script lang="ts">
import { Component, Prop, Vue } from 'nuxt-property-decorator'
@Component({})
export default class AppAudio extends Vue {
@Prop() public src!: string
@Prop() public mimeType!: string
}
<script lang="ts" setup>
defineProps<{
src?: string
}>()
</script>

<style>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
allow="accelerometer; camera; gyroscope; microphone; xr-spatial-tracking;" />
</template>

<script lang="ts">
import { Component, Prop, Vue } from 'nuxt-property-decorator'
@Component({})
export default class ImageMedia extends Vue {
@Prop() public src!: string
@Prop() public mimeType!: string
}
<script lang="ts" setup>
defineProps<{
src?: string
mimeType?: string
}>()
</script>

<style scoped>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
</figure>
</template>

<script lang="ts">
import { Component, Prop, Vue } from 'nuxt-property-decorator'
@Component({})
export default class ImageMedia extends Vue {
@Prop() public src!: string
@Prop() public mimeType!: string
}
<script lang="ts" setup>
defineProps<{
src?: string
mimeType?: string
}>()
</script>

<style scoped>
Expand Down
33 changes: 33 additions & 0 deletions components/media/type/JsonMedia.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<template>
<div>
<div v-for="item in data" :key="item.key">
<div>
<b>{{ item.key }}</b
>: {{ item.value }}
</div>
</div>
</div>
</template>

<script lang="ts" setup>
import api from '@/utils/fetch'

const { $consola } = useNuxtApp()
const props = defineProps<{
src?: string
}>()
const data = ref<{ key: string; value: string }[]>([])

onMounted(async () => {
if (props.src) {
const { data } = await api.get(props.src)
$consola.log('data', data)
data.forEach(([key, value]) => {
data.push({
key,
value: JSON.stringify(value),
})
})
}
})
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
:src="src"
:poster="poster"
:alt="description"
:availableAnimations="availableAnimations"
:available-animations="availableAnimations"
auto-rotate
:camera-controls="isDetail"
:ar="isDetail"
Expand All @@ -18,22 +18,18 @@
</div>
</template>

<script lang="ts">
import { Component, Prop, Vue } from 'nuxt-property-decorator'
<script lang="ts" setup>
import '@google/model-viewer'

@Component({})
export default class ViewModel extends Vue {
@Prop({ type: String, default: '' }) public readonly src!: string
@Prop({ type: String, default: '' }) public readonly poster?: string
@Prop({ type: String, default: '' }) public readonly description?: string
@Prop({ type: Array }) public readonly availableAnimations?: string[]
@Prop(Boolean) public preview!: boolean
const props = defineProps({
src: { type: String, default: '' },
poster: { type: String, default: '' },
description: { type: String, default: '' },
availableAnimations: { type: Array, default: () => [] },
preview: Boolean,
})

get isDetail(): boolean {
return !this.preview
}
}
const isDetail = computed(() => !props.preview)
</script>

<style lang="scss" scoped>
Expand Down
18 changes: 18 additions & 0 deletions components/media/type/ObjectMedia.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<template>
<object class="iframe-model__wrapper" :type="mimeType" :data="src" />
</template>

<script lang="ts" setup>
defineProps<{
src?: string
mimeType?: string
}>()
</script>

<style scoped>
.iframe-model__wrapper {
height: 100%;
min-height: 37em;
width: 100%;
}
</style>
13 changes: 13 additions & 0 deletions components/media/type/UnknownMedia.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<template>
<div>
<a :href="src" target="_blank" rel="noopener noreferrer"
>Unknown animated media, click to download</a
>
</div>
</template>

<script lang="ts" setup>
defineProps<{
src?: string
}>()
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,14 @@
</div>
</template>

<script lang="ts">
import { Component, Prop, Vue } from 'nuxt-property-decorator'

@Component({})
export default class VideoMedia extends Vue {
@Prop(String) public src!: string
@Prop(String) public poster?: string
@Prop(String) public mimeType!: string
@Prop(Boolean) public preview!: boolean

get controls(): boolean {
return !this.preview
}
}
<script lang="ts" setup>
const props = defineProps<{
src?: string
poster?: string
mimeType?: string
preview?: boolean
}>()
const controls = computed(() => !props.preview)
</script>

<style lang="scss" scoped>
Expand Down
Loading