-
Notifications
You must be signed in to change notification settings - Fork 198
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 <obulat@gmail.com> * Add collection page Signed-off-by: Olga Bulat <obulat@gmail.com> * Add POC media fetching and collection header Signed-off-by: Olga Bulat <obulat@gmail.com> * Make page matching more strict and set up page Signed-off-by: Olga Bulat <obulat@gmail.com> * Add a test to validate-collection-params Signed-off-by: Olga Bulat <obulat@gmail.com> * Do not show "0 results found" before fetch finished Signed-off-by: Olga Bulat <obulat@gmail.com> * Use getCollectionPath from search store Signed-off-by: Olga Bulat <obulat@gmail.com> * Simplify pages Signed-off-by: Olga Bulat <obulat@gmail.com> * Fix load more Signed-off-by: Olga Bulat <obulat@gmail.com> * Reset search state Signed-off-by: Olga Bulat <obulat@gmail.com> * Set back to results path in single-result middleware Signed-off-by: Olga Bulat <obulat@gmail.com> * Fix paddings Signed-off-by: Olga Bulat <obulat@gmail.com> * Use Results type Signed-off-by: Olga Bulat <obulat@gmail.com> * Remove page query param Signed-off-by: Olga Bulat <obulat@gmail.com> * Refactor creatorHref Signed-off-by: Olga Bulat <obulat@gmail.com> * Add requested changes Signed-off-by: Olga Bulat <obulat@gmail.com> * Fix server rendering Signed-off-by: Olga Bulat <obulat@gmail.com> * Add e2e tests Signed-off-by: Olga Bulat <obulat@gmail.com> * Update bottom margin of the collection header Signed-off-by: Olga Bulat <obulat@gmail.com> * Fix e2e tests Signed-off-by: Olga Bulat <obulat@gmail.com> --------- Signed-off-by: Olga Bulat <obulat@gmail.com>
- 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.