-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add additional search view pages to the Nuxt app (#3140)
* Add and update unit tests * Add collections to the search&media stores & service Signed-off-by: Olga Bulat <[email protected]> * Add collection page Signed-off-by: Olga Bulat <[email protected]> * Add POC media fetching and collection header Signed-off-by: Olga Bulat <[email protected]> * Make page matching more strict and set up page Signed-off-by: Olga Bulat <[email protected]> * Add a test to validate-collection-params Signed-off-by: Olga Bulat <[email protected]> * Do not show "0 results found" before fetch finished Signed-off-by: Olga Bulat <[email protected]> * Use getCollectionPath from search store Signed-off-by: Olga Bulat <[email protected]> * Simplify pages Signed-off-by: Olga Bulat <[email protected]> * Fix load more Signed-off-by: Olga Bulat <[email protected]> * Reset search state Signed-off-by: Olga Bulat <[email protected]> * Set back to results path in single-result middleware Signed-off-by: Olga Bulat <[email protected]> * Fix paddings Signed-off-by: Olga Bulat <[email protected]> * Use Results type Signed-off-by: Olga Bulat <[email protected]> * Remove page query param Signed-off-by: Olga Bulat <[email protected]> * Refactor creatorHref Signed-off-by: Olga Bulat <[email protected]> * Add requested changes Signed-off-by: Olga Bulat <[email protected]> * Fix server rendering Signed-off-by: Olga Bulat <[email protected]> * Add e2e tests Signed-off-by: Olga Bulat <[email protected]> * Update bottom margin of the collection header Signed-off-by: Olga Bulat <[email protected]> * Fix e2e tests Signed-off-by: Olga Bulat <[email protected]> --------- Signed-off-by: Olga Bulat <[email protected]>
- Loading branch information
Showing
29 changed files
with
3,533 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<template> | ||
<div class="p-6 pt-0 lg:p-10 lg:pt-2"> | ||
<VCollectionHeader | ||
v-if="collectionParams" | ||
:collection-params="collectionParams" | ||
:creator-url="creatorUrl" | ||
:media-type="mediaType" | ||
:class="mediaType === 'image' ? 'mb-4' : 'mb-2'" | ||
/> | ||
<VAudioCollection | ||
v-if="results.type === 'audio'" | ||
:collection-label="collectionLabel" | ||
:fetch-state="fetchState" | ||
kind="collection" | ||
:results="results.items" | ||
/> | ||
<VImageGrid | ||
v-if="results.type === 'image'" | ||
:image-grid-label="collectionLabel" | ||
:fetch-state="fetchState" | ||
kind="collection" | ||
:results="results.items" | ||
/> | ||
</div> | ||
</template> | ||
<script lang="ts"> | ||
import { computed, defineComponent, PropType } from "vue" | ||
import { useMediaStore } from "~/stores/media" | ||
import { useSearchStore } from "~/stores/search" | ||
import type { SupportedMediaType } from "~/constants/media" | ||
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 VImageGrid from "~/components/VSearchResultsGrid/VImageGrid.vue" | ||
export default defineComponent({ | ||
name: "VCollectionPage", | ||
components: { VAudioCollection, VImageGrid, VCollectionHeader }, | ||
props: { | ||
mediaType: { | ||
type: String as PropType<SupportedMediaType>, | ||
required: true, | ||
}, | ||
}, | ||
setup(props) { | ||
const i18n = useI18n() | ||
const mediaStore = useMediaStore() | ||
const fetchState = computed(() => mediaStore.fetchState) | ||
const results = computed<Results>(() => { | ||
return { | ||
type: props.mediaType, | ||
items: mediaStore.resultItems[props.mediaType], | ||
} as Results | ||
}) | ||
const creatorUrl = computed(() => { | ||
const media = results.value.items | ||
return media.length > 0 ? media[0].creator_url : undefined | ||
}) | ||
const searchStore = useSearchStore() | ||
const collectionParams = computed(() => searchStore.collectionParams) | ||
const collectionLabel = computed(() => { | ||
const collection = collectionParams.value?.collection | ||
switch (collection) { | ||
case "tag": | ||
return i18n | ||
.t(`collection.ariaLabel.tag.${props.mediaType}`, { | ||
tag: collectionParams.value?.tag, | ||
}) | ||
.toString() | ||
case "source": | ||
return i18n | ||
.t(`collection.ariaLabel.source.${props.mediaType}`, { | ||
source: collectionParams.value?.source, | ||
}) | ||
.toString() | ||
case "creator": | ||
return i18n | ||
.t(`collection.ariaLabel.creator.${props.mediaType}`, { | ||
creator: collectionParams.value?.creator, | ||
source: collectionParams.value?.source, | ||
}) | ||
.toString() | ||
default: | ||
return "" | ||
} | ||
}) | ||
return { | ||
fetchState, | ||
results, | ||
creatorUrl, | ||
collectionParams, | ||
collectionLabel, | ||
} | ||
}, | ||
}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { useFeatureFlagStore } from "~/stores/feature-flag" | ||
|
||
import type { Middleware } from "@nuxt/types" | ||
|
||
export const collectionMiddleware: Middleware = async ({ | ||
$pinia, | ||
error: nuxtError, | ||
}) => { | ||
if (!useFeatureFlagStore($pinia).isOn("additional_search_views")) { | ||
nuxtError({ | ||
statusCode: 404, | ||
message: "Additional search views are not enabled", | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.