Skip to content
This repository was archived by the owner on May 4, 2023. It is now read-only.

Commit 556e343

Browse files
chore: refine currentSnippet logic
1 parent 17cbeb2 commit 556e343

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/renderer/components/SnippetResults/SnippetResults.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,15 @@ export default function SnippetResults({ results }: SnippetResultsProps) {
1313
const query = useUrlQuery();
1414
const currentSnippetId = query.get('currentSnippetId');
1515

16-
const currentSnippet = currentSnippetId
16+
// if we have a snippet id in the url, search for that first
17+
let currentSnippet = currentSnippetId
1718
? results.find((recipe) => String(recipe.id) === currentSnippetId)
18-
: results[0] || {};
19+
: undefined;
20+
21+
// if we can't find the snippet from the url or it wasn't given, use the first result
22+
if (!currentSnippet) {
23+
currentSnippet = results[0] || {};
24+
}
1925

2026
return (
2127
<Flex h="full" overflow="hidden">

0 commit comments

Comments
 (0)