Skip to content

Commit 98d7446

Browse files
committed
feeling lucky fix
1 parent 6b9b155 commit 98d7446

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

‎frontend/src/App.tsx‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,15 @@ export const App: React.FC = () => {
183183
const data = await res.json();
184184
const nextResults: SearchResult[] = data.results ?? [];
185185
setResults(nextResults);
186-
if (nextResults.length === 0 || !nextResults[0].relevant_url) {
186+
if (nextResults.length === 0) {
187187
throw new Error("No results found for this query.");
188188
}
189-
window.open(nextResults[0].relevant_url, "_blank", "noopener,noreferrer");
189+
const randomIdx = Math.floor(Math.random() * nextResults.length);
190+
const lucky = nextResults[randomIdx];
191+
if (!lucky?.relevant_url) {
192+
throw new Error("No valid URL found in search results.");
193+
}
194+
window.open(lucky.relevant_url, "_blank", "noopener,noreferrer");
190195
} catch (e: any) {
191196
setError(e.message ?? String(e));
192197
}

0 commit comments

Comments
 (0)