links open in same tab in /search
This commit is contained in:
@@ -28,9 +28,17 @@ type Props = {
|
||||
isRunning: boolean;
|
||||
className?: string;
|
||||
enableKeyboardNavigation?: boolean;
|
||||
openLinksInNewTab?: boolean;
|
||||
};
|
||||
|
||||
export function SearchResultsPanel({ search, isLoading, isRunning, className, enableKeyboardNavigation = false }: Props) {
|
||||
export function SearchResultsPanel({
|
||||
search,
|
||||
isLoading,
|
||||
isRunning,
|
||||
className,
|
||||
enableKeyboardNavigation = false,
|
||||
openLinksInNewTab = true,
|
||||
}: Props) {
|
||||
const ANSWER_COLLAPSED_HEIGHT_CLASS = "h-[3rem]";
|
||||
const [isAnswerExpanded, setIsAnswerExpanded] = useState(false);
|
||||
const [canExpandAnswer, setCanExpandAnswer] = useState(false);
|
||||
@@ -92,12 +100,16 @@ export function SearchResultsPanel({ search, isLoading, isRunning, className, en
|
||||
const result = search.results[activeResultIndex >= 0 ? activeResultIndex : 0];
|
||||
if (!result?.url) return;
|
||||
event.preventDefault();
|
||||
window.open(result.url, "_blank", "noopener,noreferrer");
|
||||
if (openLinksInNewTab) {
|
||||
window.open(result.url, "_blank", "noopener,noreferrer");
|
||||
} else {
|
||||
window.location.assign(result.url);
|
||||
}
|
||||
};
|
||||
|
||||
window.addEventListener("keydown", onKeyDown);
|
||||
return () => window.removeEventListener("keydown", onKeyDown);
|
||||
}, [activeResultIndex, enableKeyboardNavigation, search]);
|
||||
}, [activeResultIndex, enableKeyboardNavigation, openLinksInNewTab, search]);
|
||||
|
||||
const citationEntries = (search?.answerCitations ?? [])
|
||||
.map((citation, index) => {
|
||||
@@ -185,8 +197,8 @@ export function SearchResultsPanel({ search, isLoading, isRunning, className, en
|
||||
<a
|
||||
key={`${citation.href}-${citation.index}`}
|
||||
href={citation.href}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
target={openLinksInNewTab ? "_blank" : undefined}
|
||||
rel={openLinksInNewTab ? "noreferrer" : undefined}
|
||||
className="rounded-md border border-violet-400/40 px-2 py-1 text-xs text-violet-200 hover:bg-violet-500/20"
|
||||
>
|
||||
<span className="mr-1 rounded bg-violet-900/70 px-1 py-0.5 text-[10px] text-violet-100">{citation.index}</span>
|
||||
@@ -218,7 +230,12 @@ export function SearchResultsPanel({ search, isLoading, isRunning, className, en
|
||||
)}
|
||||
>
|
||||
<p className="text-xs text-violet-300/85">{formatHost(result.url)}</p>
|
||||
<a href={result.url} target="_blank" rel="noreferrer" className="mt-1 block text-lg font-medium text-violet-300 hover:underline">
|
||||
<a
|
||||
href={result.url}
|
||||
target={openLinksInNewTab ? "_blank" : undefined}
|
||||
rel={openLinksInNewTab ? "noreferrer" : undefined}
|
||||
className="mt-1 block text-lg font-medium text-violet-300 hover:underline"
|
||||
>
|
||||
{result.title || result.url}
|
||||
</a>
|
||||
{(result.publishedDate || result.author) && (
|
||||
|
||||
@@ -238,7 +238,14 @@ export default function SearchRoutePage() {
|
||||
|
||||
{error ? <p className="text-sm text-red-600">{error}</p> : null}
|
||||
|
||||
<SearchResultsPanel search={search} isLoading={false} isRunning={isRunning} className="w-full" enableKeyboardNavigation />
|
||||
<SearchResultsPanel
|
||||
search={search}
|
||||
isLoading={false}
|
||||
isRunning={isRunning}
|
||||
className="w-full"
|
||||
enableKeyboardNavigation
|
||||
openLinksInNewTab={false}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user