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

Combine related media component using VMediaCollection.vue #3831

Merged
merged 5 commits into from Mar 6, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
65 changes: 0 additions & 65 deletions frontend/src/components/VAudioDetails/VRelatedAudio.vue

This file was deleted.

6 changes: 3 additions & 3 deletions frontend/src/components/VCollectionPage.vue
Expand Up @@ -7,7 +7,7 @@
:media-type="mediaType"
:class="mediaType === 'image' ? 'mb-4' : 'mb-2'"
/>
<VAudioCollection
<VAudioList
v-if="results.type === 'audio'"
:collection-label="collectionLabel"
:fetch-state="fetchState"
Expand Down Expand Up @@ -35,12 +35,12 @@ import { Results } from "~/types/result"
import { useI18n } from "~/composables/use-i18n"

import VCollectionHeader from "~/components/VCollectionHeader/VCollectionHeader.vue"
import VAudioCollection from "~/components/VSearchResultsGrid/VAudioCollection.vue"
import VAudioList from "~/components/VSearchResultsGrid/VAudioList.vue"
import VImageGrid from "~/components/VSearchResultsGrid/VImageGrid.vue"

export default defineComponent({
name: "VCollectionPage",
components: { VAudioCollection, VImageGrid, VCollectionHeader },
components: { VAudioList, VImageGrid, VCollectionHeader },
props: {
mediaType: {
type: String as PropType<SupportedMediaType>,
Expand Down
61 changes: 0 additions & 61 deletions frontend/src/components/VImageDetails/VRelatedImages.vue

This file was deleted.

105 changes: 105 additions & 0 deletions frontend/src/components/VMediaInfo/VRelatedMedia.vue
@@ -0,0 +1,105 @@
<template>
<VMediaCollection
v-if="showRelated"
:results="results"
:is-fetching="isFetching"
:collection-label="collectionLabel"
kind="related"
:related-to="relatedTo"
:search-term="searchTerm"
:aria-label="collectionLabel"
>
<template #header>
<h2
id="related-heading"
class="heading-6 mb-6"
:class="results.type === 'image' ? 'md:heading-5' : 'lg:heading-6'"
zackkrida marked this conversation as resolved.
Show resolved Hide resolved
>
{{ collectionLabel }}
</h2>
</template>
</VMediaCollection>
</template>

<script lang="ts">
import { computed, defineComponent, PropType, watch } from "vue"
import { useRoute } from "@nuxtjs/composition-api"

import { useRelatedMediaStore } from "~/stores/media/related-media"
import { useI18n } from "~/composables/use-i18n"

import type { SupportedMediaType } from "~/constants/media"
import type { AudioResults, ImageResults } from "~/types/result"

import VMediaCollection from "~/components/VSearchResultsGrid/VMediaCollection.vue"

export default defineComponent({
name: "VRelatedMedia",
components: { VMediaCollection },
props: {
mediaType: {
type: String as PropType<SupportedMediaType>,
required: true,
},
relatedTo: {
type: String as PropType<string>,
required: true,
},
},
setup(props) {
const relatedMediaStore = useRelatedMediaStore()

const route = useRoute()

const results = computed(() => {
const media = relatedMediaStore.media ?? []
return { type: props.mediaType, items: media } as
| ImageResults
| AudioResults
})
watch(
route,
async (newRoute) => {
if (newRoute.params.id !== relatedMediaStore.mainMediaId) {
await relatedMediaStore.fetchMedia(
props.mediaType,
newRoute.params.id
)
}
},
{ immediate: true }
)

const isFetching = computed(() => relatedMediaStore.fetchState.isFetching)
const showRelated = computed(
() => results.value.items.length > 0 || isFetching.value
)

const searchTerm = computed(() => {
const q = Array.isArray(route.value.query.q)
? route.value.query.q[0]
: route.value.query.q
return q ?? ""
})

const i18n = useI18n()

const collectionLabel = computed(() => {
const key =
props.mediaType === "audio"
? "audioDetails.relatedAudios"
: "imageDetails.relatedImages"
Comment on lines +90 to +91
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this impact our line number matching in the .pot files? I don't think so, because it's the full strings, but want to confirm.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, will need to check. Would the line numbers make the strings fuzzy in GlotPress?

return i18n.t(key).toString()
})

return {
results,
showRelated,
isFetching,

searchTerm,
collectionLabel,
}
},
})
</script>
Expand Up @@ -51,7 +51,7 @@
:search-term="searchTerm"
layout="box"
:size="isSm ? 'l' : 's'"
:is-related="false"
kind="search"
/>
</template>
</ol>
Expand Down