-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix fetching and types on single result pages (#2585)
* Fix fetching and types on single result pages * On SSR, fetch the image in middleware * Fix unit test * Use default img props if available * Improve fetching * Remove redundant Loading icon from Related images We show the loading skeleton when the images are loading * Fix report page * Prevent Sentry from capturing the errors twice Capture Sentry errors in components/middleware * Move Sentry capturing to the store * Update the unit test * After-rebase linting * Refactor unsafe call to useContext * Add suggestion from code review * Fix FetchState type * Add changes from code review * Update frontend/src/types/media.ts Co-authored-by: sarayourfriend <[email protected]> * Set `fetchOnServer` to false * Simplify `fetch` and move error handling to `fetchMediaItem` * Add tests * Add CORS header to a tape * Do not fetch related media if main media is null * Update tapes * Move related fetching to the component * Update frontend/src/middleware/single-result.ts Co-authored-by: sarayourfriend <[email protected]> * Update CSR VR test * Revert changes to sources tapes --------- Co-authored-by: sarayourfriend <[email protected]>
- Loading branch information
1 parent
dd49aea
commit a5abdd6
Showing
22 changed files
with
684 additions
and
549 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
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 |
---|---|---|
@@ -1,16 +1,42 @@ | ||
import { useSingleResultStore } from "~/stores/media/single-result" | ||
import { useSearchStore } from "~/stores/search" | ||
import { useRelatedMediaStore } from "~/stores/media/related-media" | ||
|
||
import { AUDIO, IMAGE } from "~/constants/media" | ||
|
||
import type { Middleware } from "@nuxt/types" | ||
|
||
export const singleResultMiddleware: Middleware = ({ route, from, $pinia }) => { | ||
if (from && from.path.includes("/search/")) { | ||
const searchStore = useSearchStore($pinia) | ||
searchStore.setBackToSearchPath(from.fullPath) | ||
const searchTerm = Array.isArray(route.query.q) | ||
? route.query.q[0] | ||
: route.query.q | ||
if (searchTerm) { | ||
searchStore.setSearchTerm(searchTerm) | ||
export const singleResultMiddleware: Middleware = async ({ | ||
route, | ||
from, | ||
error, | ||
$pinia, | ||
}) => { | ||
const mediaType = route.fullPath.includes("/image/") ? IMAGE : AUDIO | ||
const singleResultStore = useSingleResultStore($pinia) | ||
|
||
if (process.server) { | ||
const media = await singleResultStore.fetch(mediaType, route.params.id) | ||
await useRelatedMediaStore($pinia).fetchMedia(mediaType, route.params.id) | ||
|
||
if (!media) { | ||
error(singleResultStore.fetchState.fetchingError ?? {}) | ||
} | ||
} else { | ||
// Client-side rendering | ||
singleResultStore.setMediaById(mediaType, route.params.id) | ||
|
||
if (from && from.path.includes("/search/")) { | ||
const searchStore = useSearchStore($pinia) | ||
searchStore.setBackToSearchPath(from.fullPath) | ||
|
||
const searchTerm = Array.isArray(route.query.q) | ||
? route.query.q[0] | ||
: route.query.q | ||
|
||
if (searchTerm) { | ||
searchStore.setSearchTerm(searchTerm) | ||
} | ||
} | ||
} | ||
} |
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.