From 497ccaa10fca299d9b1d4dbd437448ca8ad64392 Mon Sep 17 00:00:00 2001 From: johndoe6345789 Date: Sat, 17 Jan 2026 23:53:46 +0000 Subject: [PATCH] Use JSON seed data for snippets --- src/data/seed-snippets.json | 17 +- src/data/seed-templates.json | 17 +- src/lib/db-snippets.ts | 362 +---------------------------------- 3 files changed, 38 insertions(+), 358 deletions(-) diff --git a/src/data/seed-snippets.json b/src/data/seed-snippets.json index 9f8ffb1..d303aab 100644 --- a/src/data/seed-snippets.json +++ b/src/data/seed-snippets.json @@ -45,7 +45,20 @@ "category": "Components", "hasPreview": true, "functionName": "AnimatedCard", - "inputParameters": [], + "inputParameters": [ + { + "name": "title", + "type": "string", + "defaultValue": "Animated Card", + "description": "Card title" + }, + { + "name": "description", + "type": "string", + "defaultValue": "Hover to see the effect", + "description": "Card description" + } + ], "createdAt": 0, "updatedAt": 0 }, @@ -62,4 +75,4 @@ "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 445e0d8..2a4e8bb 100644 --- a/src/data/seed-templates.json +++ b/src/data/seed-templates.json @@ -19,7 +19,20 @@ "category": "Templates", "hasPreview": true, "functionName": "Greeting", - "inputParameters": [] + "inputParameters": [ + { + "name": "name", + "type": "string", + "defaultValue": "World", + "description": "Name to greet" + }, + { + "name": "message", + "type": "string", + "defaultValue": "Hello", + "description": "Greeting message" + } + ] }, { "id": "template-3", @@ -32,4 +45,4 @@ "functionName": "StatefulComponent", "inputParameters": [] } -] \ No newline at end of file +] diff --git a/src/lib/db-snippets.ts b/src/lib/db-snippets.ts index a28d8a4..bf3c07f 100644 --- a/src/lib/db-snippets.ts +++ b/src/lib/db-snippets.ts @@ -220,366 +220,20 @@ export async function seedDatabase(): Promise { const now = Date.now() - const seedSnippets: Snippet[] = [ - { - id: 'seed-1', - title: 'React Counter Hook', - description: 'Basic state management with useState', - code: `import { useState } from 'react' - -function Counter() { - const [count, setCount] = useState(0) - - return ( -
-

Count: {count}

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

My Todos

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

This card has smooth animations on hover and tap!

-
-
-
- ) -} - -export default AnimatedCard`, - language: 'tsx', - category: 'Components', - hasPreview: true, - functionName: 'AnimatedCard', - inputParameters: [ - { - name: 'title', - type: 'string', - defaultValue: 'Animated Card', - description: 'Card title' - }, - { - name: 'description', - type: 'string', - defaultValue: 'Hover to see the effect', - description: 'Card description' - } - ], - createdAt: now - 3000, - updatedAt: now - 3000 - }, - { - id: 'seed-5', - title: 'Form Validation', - description: 'Form with react-hook-form validation', - code: `import { useForm } from 'react-hook-form' -import { Button } from '@/components/ui/button' -import { Input } from '@/components/ui/input' -import { Label } from '@/components/ui/label' -import { Card } from '@/components/ui/card' - -function ContactForm() { - const { register, handleSubmit, formState: { errors } } = useForm() - - const onSubmit = (data) => { - console.log('Form data:', data) - alert('Form submitted successfully!') - } - - return ( - -

Contact Form

-
-
- - - {errors.name && ( -

{errors.name.message}

- )} -
- -
- - - {errors.email && ( -

{errors.email.message}

- )} -
- - -
-
- ) -} - -export default ContactForm`, - language: 'tsx', - category: 'Forms', - hasPreview: true, - functionName: 'ContactForm', - inputParameters: [], - createdAt: now - 4000, - updatedAt: now - 4000 - } - ] + }) for (const snippet of seedSnippets) { await createSnippet(snippet) } - const seedTemplates: SnippetTemplate[] = [ - { - id: 'template-1', - title: 'Basic React Component', - description: 'Simple functional component template', - code: `function MyComponent() { - return ( -
-

Hello World

-

This is a basic component.

-
- ) -} - -export 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' }) { - return ( -
-

{message}, {name}!

-
- ) -} - -export default Greeting`, - language: 'tsx', - category: 'Templates', - hasPreview: true, - functionName: 'Greeting', - inputParameters: [ - { - name: 'name', - type: 'string', - defaultValue: 'World', - description: 'Name to greet' - }, - { - name: 'message', - type: 'string', - defaultValue: 'Hello', - description: 'Greeting message' - } - ] - }, - { - id: 'template-3', - title: 'useState Hook Template', - description: 'Component with state management', - code: `import { useState } from 'react' -import { Button } from '@/components/ui/button' - -function StatefulComponent() { - const [value, setValue] = useState(0) - - return ( -
-

Value: {value}

- -
- ) -} - -export default StatefulComponent`, - language: 'tsx', - category: 'Templates', - hasPreview: true, - functionName: 'StatefulComponent', - inputParameters: [] - } - ] + const seedTemplates: SnippetTemplate[] = seedTemplatesData for (const template of seedTemplates) { await createTemplate(template)