Bugfix for dynamic urls not properly replaces on Search (#2124)

* Bugfix for search items

* Fixing server side rendering issues
This commit is contained in:
Jelte Lagendijk
2024-09-11 23:53:55 +02:00
committed by GitHub
parent 6a7532b5b7
commit c81612e39b
2 changed files with 7 additions and 1 deletions

View File

@@ -13,6 +13,7 @@ import { useTranslation } from 'next-i18next';
import { useRouter } from 'next/router';
import { ReactNode, forwardRef, useMemo, useRef, useState } from 'react';
import { useConfigContext } from '~/config/provider';
import { useGetExternalUrl } from '~/hooks/useExternalUrl';
import { api } from '~/utils/api';
import { MovieModal } from './Search/MovieModal';
@@ -141,6 +142,7 @@ const getItemComponent = (icon: SearchAutoCompleteItem['icon']) => {
const useConfigApps = (search: string) => {
const { config } = useConfigContext();
const getHref = useGetExternalUrl();
return useMemo(() => {
if (search.trim().length === 0) return [];
const apps = config?.apps.filter((app) =>
@@ -153,7 +155,7 @@ const useConfigApps = (search: string) => {
value: app.name,
sort: 'app',
metaData: {
url: app.behaviour.externalUrl,
url: getHref(app),
},
})) ?? []
);

View File

@@ -3,6 +3,10 @@ import * as tldts from 'tldts';
import { AppType } from '~/types/app';
export const useGetExternalUrl = () => {
if (typeof window === 'undefined') {
return (appType: AppType) => appType.behaviour.externalUrl || appType.url;
}
const parsedUrl = useMemo(() => {
try {
return tldts.parse(window.location.toString());