Skip to content

Commit

Permalink
update improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
seveibar committed Oct 12, 2024
1 parent ba979af commit ab234e2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/components/CodeAndPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,13 @@ export function CodeAndPreview({ snippet }: Props) {
/>
)}
</div>
<ImportSnippetDialog />
<ImportSnippetDialog
onSnippetSelected={(snippet) => {
setCode(
`import {} from "@tsci/${snippet.owner_name}.${snippet.unscoped_name}"\n${snippet.code}`,
)
}}
/>
</div>
)
}
7 changes: 6 additions & 1 deletion src/components/dialogs/import-snippet-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ export const ImportSnippetDialog = ({
<ul>
{snippets?.map((snippet: Snippet) => (
<li key={snippet.snippet_id}>
<Button onClick={() => onSnippetSelected(snippet)}>
<Button
onClick={() => {
onSnippetSelected(snippet)
onOpenChange(false)
}}
>
{snippet.name}
</Button>
</li>
Expand Down

0 comments on commit ab234e2

Please sign in to comment.