diff --git a/src/data/seed-snippets.json b/src/data/seed-snippets.json index 0637a08..9f8ffb1 100644 --- a/src/data/seed-snippets.json +++ b/src/data/seed-snippets.json @@ -1 +1,65 @@ -[] \ No newline at end of file +[ + { + "id": "seed-1", + "title": "React Counter Hook", + "description": "Basic state management with useState", + "code": "import { useState } from 'react'\n\nfunction Counter() {\n const [count, setCount] = useState(0)\n \n return (\n
\n

Count: {count}

\n
\n \n \n
\n
\n )\n}\n\nexport default Counter", + "language": "tsx", + "category": "React Hooks", + "hasPreview": true, + "functionName": "Counter", + "inputParameters": [], + "createdAt": 0, + "updatedAt": 0 + }, + { + "id": "seed-2", + "title": "Todo List Component", + "description": "Complete todo list with add, toggle, and delete", + "code": "import { useState } from 'react'\nimport { Button } from '@/components/ui/button'\nimport { Input } from '@/components/ui/input'\nimport { Card } from '@/components/ui/card'\nimport { Checkbox } from '@/components/ui/checkbox'\nimport { Trash2 } from '@phosphor-icons/react'\n\nfunction TodoList() {\n const [todos, setTodos] = useState([\n { id: 1, text: 'Learn React', completed: false },\n { id: 2, text: 'Build a project', completed: false }\n ])\n const [input, setInput] = useState('')\n\n const addTodo = () => {\n if (input.trim()) {\n setTodos([...todos, { id: Date.now(), text: input, completed: false }])\n setInput('')\n }\n }\n\n const toggleTodo = (id) => {\n setTodos(todos.map(todo => \n todo.id === id ? { ...todo, completed: !todo.completed } : todo\n ))\n }\n\n const deleteTodo = (id) => {\n setTodos(todos.filter(todo => todo.id !== id))\n }\n\n return (\n \n

My Todos

\n
\n setInput(e.target.value)}\n onKeyPress={(e) => e.key === 'Enter' && addTodo()}\n placeholder=\"Add a new todo...\"\n />\n \n
\n
\n {todos.map(todo => (\n
\n toggleTodo(todo.id)}\n />\n \n {todo.text}\n \n deleteTodo(todo.id)}\n >\n \n \n
\n ))}\n
\n
\n )\n}\n\nexport default TodoList", + "language": "tsx", + "category": "Components", + "hasPreview": true, + "functionName": "TodoList", + "inputParameters": [], + "createdAt": 0, + "updatedAt": 0 + }, + { + "id": "seed-3", + "title": "Fetch Data Hook", + "description": "Custom hook for API data fetching", + "code": "import { useState, useEffect } from 'react'\n\nfunction useFetch(url) {\n const [data, setData] = useState(null)\n const [loading, setLoading] = useState(true)\n const [error, setError] = useState(null)\n\n useEffect(() => {\n const fetchData = async () => {\n try {\n setLoading(true)\n const response = await fetch(url)\n if (!response.ok) throw new Error('Network response was not ok')\n const json = await response.json()\n setData(json)\n setError(null)\n } catch (err) {\n setError(err.message)\n } finally {\n setLoading(false)\n }\n }\n\n fetchData()\n }, [url])\n\n return { data, loading, error }\n}", + "language": "tsx", + "category": "React Hooks", + "hasPreview": false, + "createdAt": 0, + "updatedAt": 0 + }, + { + "id": "seed-4", + "title": "Animated Card", + "description": "Card with hover animation using Framer Motion", + "code": "import { motion } from 'framer-motion'\nimport { Card, CardHeader, CardTitle, CardDescription, CardContent } from '@/components/ui/card'\n\nfunction AnimatedCard({ title = 'Animated Card', description = 'Hover to see the effect' }) {\n return (\n \n \n \n {title}\n {description}\n \n \n

This card has smooth animations on hover and tap!

\n
\n
\n \n )\n}\n\nexport default AnimatedCard", + "language": "tsx", + "category": "Components", + "hasPreview": true, + "functionName": "AnimatedCard", + "inputParameters": [], + "createdAt": 0, + "updatedAt": 0 + }, + { + "id": "seed-5", + "title": "Form Validation", + "description": "Form with react-hook-form validation", + "code": "import { useForm } from 'react-hook-form'\nimport { Button } from '@/components/ui/button'\nimport { Input } from '@/components/ui/input'\nimport { Label } from '@/components/ui/label'\nimport { Card } from '@/components/ui/card'\n\nfunction ContactForm() {\n const { register, handleSubmit, formState: { errors } } = useForm()\n\n const onSubmit = (data) => {\n console.log('Form data:', data)\n alert('Form submitted successfully!')\n }\n\n return (\n \n

Contact Form

\n
\n
\n \n \n {errors.name && (\n

{errors.name.message}

\n )}\n
\n\n
\n \n \n {errors.email && (\n

{errors.email.message}

\n )}\n
\n\n \n
\n
\n )\n}\n\nexport default ContactForm", + "language": "tsx", + "category": "Forms", + "hasPreview": true, + "functionName": "ContactForm", + "inputParameters": [], + "createdAt": 0, + "updatedAt": 0 + } +] \ No newline at end of file diff --git a/src/data/seed-templates.json b/src/data/seed-templates.json index 0637a08..445e0d8 100644 --- a/src/data/seed-templates.json +++ b/src/data/seed-templates.json @@ -1 +1,35 @@ -[] \ No newline at end of file +[ + { + "id": "template-1", + "title": "Basic React Component", + "description": "Simple functional component template", + "code": "function MyComponent() {\n return (\n
\n

Hello World

\n

This is a basic component.

\n
\n )\n}\n\nexport default MyComponent", + "language": "tsx", + "category": "Templates", + "hasPreview": true, + "functionName": "MyComponent", + "inputParameters": [] + }, + { + "id": "template-2", + "title": "Component with Props", + "description": "Component template with configurable props", + "code": "function Greeting({ name = 'World', message = 'Hello' }) {\n return (\n
\n

{message}, {name}!

\n
\n )\n}\n\nexport default Greeting", + "language": "tsx", + "category": "Templates", + "hasPreview": true, + "functionName": "Greeting", + "inputParameters": [] + }, + { + "id": "template-3", + "title": "useState Hook Template", + "description": "Component with state management", + "code": "import { useState } from 'react'\nimport { Button } from '@/components/ui/button'\n\nfunction StatefulComponent() {\n const [value, setValue] = useState(0)\n\n return (\n
\n

Value: {value}

\n \n
\n )\n}\n\nexport default StatefulComponent", + "language": "tsx", + "category": "Templates", + "hasPreview": true, + "functionName": "StatefulComponent", + "inputParameters": [] + } +] \ No newline at end of file diff --git a/src/lib/db-snippets.ts b/src/lib/db-snippets.ts index c3707d7..a28d8a4 100644 --- a/src/lib/db-snippets.ts +++ b/src/lib/db-snippets.ts @@ -6,6 +6,8 @@ import type { Snippet, SnippetTemplate } from './types' import { initDB, saveDB, getFlaskAdapter } from './db-core' import { mapRowToObject, mapRowsToObjects } from './db-mapper' import { ensureDefaultNamespace } from './db-namespaces' +import seedSnippetsData from '@/data/seed-snippets.json' +import seedTemplatesData from '@/data/seed-templates.json' export async function getAllSnippets(): Promise { const adapter = getFlaskAdapter()