-
Notifications
You must be signed in to change notification settings - Fork 225
Add additional search view pages to the Nuxt app #3140
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
Merged
obulat
merged 21 commits into
main
from
additional_search_views/add-to-store-and-api-service
Dec 5, 2023
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
5d1f4a4
Add and update unit tests
obulat bda127a
Add collections to the search&media stores & service
obulat 093ca4b
Add collection page
obulat 807e043
Add POC media fetching and collection header
obulat c8f193c
Make page matching more strict and set up page
obulat 7100aa9
Add a test to validate-collection-params
obulat ad49b91
Do not show "0 results found" before fetch finished
obulat 2a2ed24
Use getCollectionPath from search store
obulat 59dfbaf
Simplify pages
obulat f67ed98
Fix load more
obulat 914c282
Reset search state
obulat 40ecf67
Set back to results path in single-result middleware
obulat 5440826
Fix paddings
obulat aeed875
Use Results type
obulat 6e2a7cc
Remove page query param
obulat b343769
Refactor creatorHref
obulat 68de881
Add requested changes
obulat 7e74f6b
Fix server rendering
obulat de310db
Add e2e tests
obulat 6440c51
Update bottom margin of the collection header
obulat f1c6cac
Fix e2e tests
obulat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might be misreading this, but doesn't this set
searchStore.strategy
to eitherdefault
or a boolean value, due to this last check? Is that intended?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This computed is written very shortly so it's not easy to understand. I added a bit more verbosity.
This is actually setting
searchStarted
based on whether the strategy isdefault
or not (so, one of thecollection
s). If the strategy isdefault
, it checks thesearchTerm
, otherwise - thecollectionParams
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhhhh, okay I see that now! Thanks!