Skip to content

Commit

Permalink
Bugfix for dynamic urls not properly replaces on Search (#2124)
Browse files Browse the repository at this point in the history
* Bugfix for search items

* Fixing server side rendering issues
  • Loading branch information
j3lte authored Sep 11, 2024
1 parent 6a7532b commit c81612e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/components/layout/header/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) =>
Expand All @@ -153,7 +155,7 @@ const useConfigApps = (search: string) => {
value: app.name,
sort: 'app',
metaData: {
url: app.behaviour.externalUrl,
url: getHref(app),
},
})) ?? []
);
Expand Down
4 changes: 4 additions & 0 deletions src/hooks/useExternalUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit c81612e

Please sign in to comment.