diff --git a/src/components/EmptyState.tsx b/src/components/EmptyState.tsx index 6342188..f7e98d7 100644 --- a/src/components/EmptyState.tsx +++ b/src/components/EmptyState.tsx @@ -87,6 +87,51 @@ export function EmptyState({ onCreateClick, onCreateFromTemplate }: EmptyStatePr ))} + + Python - Project Euler + {templates.filter((t) => t.category === 'euler').map((template) => ( + onCreateFromTemplate?.(template.id)} + > +
+ {template.title} + + {template.description} + +
+
+ ))} + + Python - Algorithms + {templates.filter((t) => t.category === 'algorithms' && t.language === 'Python').map((template) => ( + onCreateFromTemplate?.(template.id)} + > +
+ {template.title} + + {template.description} + +
+
+ ))} + + Python - Interactive Programs + {templates.filter((t) => t.category === 'interactive').map((template) => ( + onCreateFromTemplate?.(template.id)} + > +
+ {template.title} + + {template.description} + +
+
+ ))} diff --git a/src/components/SnippetManager.tsx b/src/components/SnippetManager.tsx index 74c2efa..6c58bdf 100644 --- a/src/components/SnippetManager.tsx +++ b/src/components/SnippetManager.tsx @@ -23,7 +23,8 @@ import { createSnippet, updateSnippet, deleteSnippet as deleteSnippetDB, - seedDatabase + seedDatabase, + syncTemplatesFromJSON } from '@/lib/db' const templates = templatesData as SnippetTemplate[] @@ -42,6 +43,7 @@ export function SnippetManager() { setLoading(true) try { await seedDatabase() + await syncTemplatesFromJSON(templates) const loadedSnippets = await getAllSnippets() setSnippets(loadedSnippets) } catch (error) { @@ -253,6 +255,51 @@ export function SnippetManager() { ))} + + Python - Project Euler + {templates.filter((t) => t.category === 'euler').map((template) => ( + handleCreateFromTemplate(template.id)} + > +
+ {template.title} + + {template.description} + +
+
+ ))} + + Python - Algorithms + {templates.filter((t) => t.category === 'algorithms' && t.language === 'Python').map((template) => ( + handleCreateFromTemplate(template.id)} + > +
+ {template.title} + + {template.description} + +
+
+ ))} + + Python - Interactive Programs + {templates.filter((t) => t.category === 'interactive').map((template) => ( + handleCreateFromTemplate(template.id)} + > +
+ {template.title} + + {template.description} + +
+
+ ))} diff --git a/src/lib/db.ts b/src/lib/db.ts index e559a71..1e61573 100644 --- a/src/lib/db.ts +++ b/src/lib/db.ts @@ -836,3 +836,22 @@ export async function clearDatabase(): Promise { dbInstance = null await initDB() } + +export async function syncTemplatesFromJSON(templates: SnippetTemplate[]): Promise { + const db = await initDB() + + const existingTemplates = db.exec('SELECT id FROM snippet_templates') + const existingIds = new Set( + existingTemplates[0]?.values.map(row => row[0] as string) || [] + ) + + let addedCount = 0 + for (const template of templates) { + if (!existingIds.has(template.id)) { + await createTemplate(template) + addedCount++ + } + } + + console.log(`Synced ${templates.length} templates from JSON, added ${addedCount} new templates`) +}