Generated by Spark: There seems to be a templates.json syncing issue. I am not seeing them in UI. Maybe a syncing algo needs to be written to sync with database.

This commit is contained in:
2026-01-17 19:36:57 +00:00
committed by GitHub
parent 7e1f705fe4
commit 6203a7ce56
3 changed files with 112 additions and 1 deletions

View File

@@ -87,6 +87,51 @@ export function EmptyState({ onCreateClick, onCreateFromTemplate }: EmptyStatePr
</div>
</DropdownMenuItem>
))}
<DropdownMenuSeparator />
<DropdownMenuLabel>Python - Project Euler</DropdownMenuLabel>
{templates.filter((t) => t.category === 'euler').map((template) => (
<DropdownMenuItem
key={template.id}
onClick={() => onCreateFromTemplate?.(template.id)}
>
<div className="flex flex-col gap-1 py-1">
<span className="font-medium">{template.title}</span>
<span className="text-xs text-muted-foreground line-clamp-1">
{template.description}
</span>
</div>
</DropdownMenuItem>
))}
<DropdownMenuSeparator />
<DropdownMenuLabel>Python - Algorithms</DropdownMenuLabel>
{templates.filter((t) => t.category === 'algorithms' && t.language === 'Python').map((template) => (
<DropdownMenuItem
key={template.id}
onClick={() => onCreateFromTemplate?.(template.id)}
>
<div className="flex flex-col gap-1 py-1">
<span className="font-medium">{template.title}</span>
<span className="text-xs text-muted-foreground line-clamp-1">
{template.description}
</span>
</div>
</DropdownMenuItem>
))}
<DropdownMenuSeparator />
<DropdownMenuLabel>Python - Interactive Programs</DropdownMenuLabel>
{templates.filter((t) => t.category === 'interactive').map((template) => (
<DropdownMenuItem
key={template.id}
onClick={() => onCreateFromTemplate?.(template.id)}
>
<div className="flex flex-col gap-1 py-1">
<span className="font-medium">{template.title}</span>
<span className="text-xs text-muted-foreground line-clamp-1">
{template.description}
</span>
</div>
</DropdownMenuItem>
))}
</DropdownMenuContent>
</DropdownMenu>
</div>

View File

@@ -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() {
</div>
</DropdownMenuItem>
))}
<DropdownMenuSeparator />
<DropdownMenuLabel>Python - Project Euler</DropdownMenuLabel>
{templates.filter((t) => t.category === 'euler').map((template) => (
<DropdownMenuItem
key={template.id}
onClick={() => handleCreateFromTemplate(template.id)}
>
<div className="flex flex-col gap-1 py-1">
<span className="font-medium">{template.title}</span>
<span className="text-xs text-muted-foreground line-clamp-1">
{template.description}
</span>
</div>
</DropdownMenuItem>
))}
<DropdownMenuSeparator />
<DropdownMenuLabel>Python - Algorithms</DropdownMenuLabel>
{templates.filter((t) => t.category === 'algorithms' && t.language === 'Python').map((template) => (
<DropdownMenuItem
key={template.id}
onClick={() => handleCreateFromTemplate(template.id)}
>
<div className="flex flex-col gap-1 py-1">
<span className="font-medium">{template.title}</span>
<span className="text-xs text-muted-foreground line-clamp-1">
{template.description}
</span>
</div>
</DropdownMenuItem>
))}
<DropdownMenuSeparator />
<DropdownMenuLabel>Python - Interactive Programs</DropdownMenuLabel>
{templates.filter((t) => t.category === 'interactive').map((template) => (
<DropdownMenuItem
key={template.id}
onClick={() => handleCreateFromTemplate(template.id)}
>
<div className="flex flex-col gap-1 py-1">
<span className="font-medium">{template.title}</span>
<span className="text-xs text-muted-foreground line-clamp-1">
{template.description}
</span>
</div>
</DropdownMenuItem>
))}
</DropdownMenuContent>
</DropdownMenu>
</div>

View File

@@ -836,3 +836,22 @@ export async function clearDatabase(): Promise<void> {
dbInstance = null
await initDB()
}
export async function syncTemplatesFromJSON(templates: SnippetTemplate[]): Promise<void> {
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`)
}