Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 | 29x 29x 29x 29x 29x 29x 29x 29x 4x 1x 1x 3x 3x 3x 3x 3x 2x 2x 2x 29x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 29x 1x 1x 1x 1x 1x 1x 1x 1x 29x 1x 1x 1x 1x 1x 1x 3x 3x 1x 1x 29x 6x 29x 1x 1x 29x 3x 1x 1x | import { useState } from "react";
import {
X,
Sparkles,
RefreshCw,
FileText,
Lightbulb,
Type,
} from "lucide-react";
import { Button } from "../../ui/button";
import { Card, CardContent, CardHeader, CardTitle } from "../../ui/card";
import { cn } from "../../../lib/utils";
interface AIWritingPanelProps {
onClose: () => void;
onInsertContent: (content: string) => void;
className?: string;
}
type AIAction =
| "generate-draft"
| "rewrite-section"
| "generate-seo"
| "suggest-headlines";
export function AIWritingPanel({
onClose,
onInsertContent,
className,
}: AIWritingPanelProps) {
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
const [generatedContent, setGeneratedContent] = useState("");
const [activeAction, setActiveAction] = useState<AIAction | null>(null);
// Input fields for different actions
const [outlineInput, setOutlineInput] = useState("");
const [sectionInput, setSectionInput] = useState("");
const [headlineCount, setHeadlineCount] = useState(5);
const handleGenerateDraft = async () => {
if (!outlineInput.trim()) {
setError("Please provide an outline or topic description");
return;
}
try {
setLoading(true);
setError(null);
setActiveAction("generate-draft");
// Placeholder for AI API call
// In production, this would call an AI service like OpenAI, Anthropic, etc.
await simulateAICall();
const mockContent = `
# Generated Draft
Based on your outline: "${outlineInput}"
## Introduction
This blog post explores the key concepts outlined above. Our research and experience show that these principles are fundamental to success in this area.
## Main Points
1. **First Key Point**: Detailed explanation of the first concept
2. **Second Key Point**: In-depth analysis of the second topic
3. **Third Key Point**: Comprehensive coverage of the final aspect
## Conclusion
By following these guidelines, you can achieve excellent results. Remember to adapt these principles to your specific situation.
[Note: This is a generated draft. Please review and customize with your expertise.]
`;
setGeneratedContent(mockContent);
} catch (error: unknown) {
setError((error as Error).message || "Failed to generate draft");
} finally {
setLoading(false);
}
};
const handleRewriteSection = async () => {
if (!sectionInput.trim()) {
setError("Please provide the section you want to rewrite");
return;
}
try {
setLoading(true);
setError(null);
setActiveAction("rewrite-section");
await simulateAICall();
const mockRewrite = `
## Rewritten Section
${sectionInput.split(" ").reverse().join(" ")}
[Note: This is a simulated rewrite. In production, AI would improve clarity, tone, and engagement.]
`;
setGeneratedContent(mockRewrite);
} catch (error: unknown) {
setError((error as Error).message || "Failed to rewrite section");
} finally {
setLoading(false);
}
};
const handleGenerateSEO = async () => {
try {
setLoading(true);
setError(null);
setActiveAction("generate-seo");
await simulateAICall();
const mockSEO = `
**Title Suggestion:**
"Transform Your Space: Expert Interior Design Tips for Modern Homes"
**Meta Description:**
Discover professional interior design strategies to create stunning living spaces. Learn color coordination, furniture placement, and style tips from industry experts.
**Primary Keyword:**
interior design tips
**Secondary Keywords:**
- home decoration ideas
- modern interior design
- room styling guide
- furniture arrangement tips
- color scheme selection
[Note: Review and adjust based on your target audience and SEO strategy.]
`;
setGeneratedContent(mockSEO);
} catch (error: unknown) {
setError((error as Error).message || "Failed to generate SEO metadata");
} finally {
setLoading(false);
}
};
const handleSuggestHeadlines = async () => {
try {
setLoading(true);
setError(null);
setActiveAction("suggest-headlines");
await simulateAICall();
const mockHeadlines = Array.from({ length: headlineCount }, (_, i) => {
const options = [
`${i + 1}. Transform Your Living Room: ${10 + i} Expert Design Tips`,
`${i + 1}. The Ultimate Guide to Modern Interior Design Trends`,
`${i + 1}. How to Create a Stunning Home on Any Budget`,
`${i + 1}. Interior Design Secrets Professionals Don't Want You to Know`,
`${i + 1}. From Bland to Beautiful: Your Home Transformation Journey`,
];
return (
options[i] ||
`${i + 1}. Creative Interior Design Ideas for ${2024 + i}`
);
}).join("\n");
setGeneratedContent(mockHeadlines);
} catch (error: unknown) {
setError((error as Error).message || "Failed to generate headlines");
} finally {
setLoading(false);
}
};
const simulateAICall = () => {
// Simulate API delay
return new Promise((resolve) => setTimeout(resolve, 1500));
};
const handleInsert = () => {
Eif (generatedContent) {
onInsertContent(generatedContent);
}
};
return (
<div
className={cn(
"fixed right-0 top-0 h-full w-full md:w-96 bg-background-elevated border-l border-border-default shadow-2xl z-50 overflow-y-auto",
className,
)}
>
<div className="sticky top-0 bg-background-elevated border-b border-border-default p-4 flex items-center justify-between">
<div className="flex items-center gap-2">
<Sparkles className="h-5 w-5 text-primary-600" />
<h2 className="font-semibold">AI Writing Assistant</h2>
</div>
<button
type="button"
onClick={onClose}
className="p-2 hover:bg-background-muted rounded-md"
>
<X className="h-5 w-5" />
</button>
</div>
<div className="p-4 space-y-4">
{/* Error Message */}
{error && (
<div className="bg-error-light border border-error text-error-dark rounded-lg p-3 text-sm">
{error}
</div>
)}
{/* AI Actions */}
<div className="space-y-3">
{/* Generate Draft */}
<Card>
<CardContent className="p-4">
<div className="flex items-start gap-3 mb-3">
<FileText className="h-5 w-5 text-primary-600 flex-shrink-0 mt-0.5" />
<div className="flex-1">
<h3 className="font-medium text-sm mb-1">Generate Draft</h3>
<p className="text-xs text-foreground-subtle">
Create a blog draft from an outline or topic
</p>
</div>
</div>
<textarea
value={outlineInput}
onChange={(e) => setOutlineInput(e.target.value)}
placeholder="Enter your outline or topic description..."
rows={3}
className="w-full text-sm rounded-md border border-border-default bg-background-elevated px-3 py-2 mb-3"
/>
<Button
onClick={handleGenerateDraft}
disabled={loading}
size="sm"
className="w-full"
>
{loading && activeAction === "generate-draft" ? (
<RefreshCw className="h-4 w-4 animate-spin" />
) : (
<Sparkles className="h-4 w-4" />
)}
Generate
</Button>
</CardContent>
</Card>
{/* Rewrite Section */}
<Card>
<CardContent className="p-4">
<div className="flex items-start gap-3 mb-3">
<RefreshCw className="h-5 w-5 text-primary-600 flex-shrink-0 mt-0.5" />
<div className="flex-1">
<h3 className="font-medium text-sm mb-1">Rewrite Section</h3>
<p className="text-xs text-foreground-subtle">
Improve clarity and engagement
</p>
</div>
</div>
<textarea
value={sectionInput}
onChange={(e) => setSectionInput(e.target.value)}
placeholder="Paste the section you want to rewrite..."
rows={4}
className="w-full text-sm rounded-md border border-border-default bg-background-elevated px-3 py-2 mb-3"
/>
<Button
onClick={handleRewriteSection}
disabled={loading}
size="sm"
variant="outline"
className="w-full"
>
{loading && activeAction === "rewrite-section" ? (
<RefreshCw className="h-4 w-4 animate-spin" />
) : (
<RefreshCw className="h-4 w-4" />
)}
Rewrite
</Button>
</CardContent>
</Card>
{/* Generate SEO Metadata */}
<Card>
<CardContent className="p-4">
<div className="flex items-start gap-3 mb-3">
<Lightbulb className="h-5 w-5 text-primary-600 flex-shrink-0 mt-0.5" />
<div className="flex-1">
<h3 className="font-medium text-sm mb-1">
Generate SEO Metadata
</h3>
<p className="text-xs text-foreground-subtle">
Create optimized title, description, and keywords
</p>
</div>
</div>
<Button
onClick={handleGenerateSEO}
disabled={loading}
size="sm"
variant="outline"
className="w-full"
>
{loading && activeAction === "generate-seo" ? (
<RefreshCw className="h-4 w-4 animate-spin" />
) : (
<Lightbulb className="h-4 w-4" />
)}
Generate
</Button>
</CardContent>
</Card>
{/* Suggest Headlines */}
<Card>
<CardContent className="p-4">
<div className="flex items-start gap-3 mb-3">
<Type className="h-5 w-5 text-primary-600 flex-shrink-0 mt-0.5" />
<div className="flex-1">
<h3 className="font-medium text-sm mb-1">
Suggest Headlines
</h3>
<p className="text-xs text-foreground-subtle">
Generate catchy title options
</p>
</div>
</div>
<div className="mb-3">
<label
htmlFor="topic-count"
className="text-xs text-foreground-subtle mb-1 block"
>
Number of suggestions
</label>
<input
id="topic-count"
type="number"
value={headlineCount}
onChange={(e) =>
setHeadlineCount(Number.parseInt(e.target.value, 10))
}
min={1}
max={10}
className="w-full text-sm rounded-md border border-border-default bg-background-elevated px-3 py-2"
/>
</div>
<Button
onClick={handleSuggestHeadlines}
disabled={loading}
size="sm"
variant="outline"
className="w-full"
>
{loading && activeAction === "suggest-headlines" ? (
<RefreshCw className="h-4 w-4 animate-spin" />
) : (
<Type className="h-4 w-4" />
)}
Suggest
</Button>
</CardContent>
</Card>
</div>
{/* Generated Content Preview */}
{generatedContent && (
<Card className="bg-info-light border-info">
<CardHeader className="pb-3">
<CardTitle className="text-sm flex items-center justify-between">
<span>Generated Content</span>
<Button onClick={handleInsert} size="sm">
Insert
</Button>
</CardTitle>
</CardHeader>
<CardContent className="pt-0">
<div className="bg-background-elevated rounded-md p-3 text-sm whitespace-pre-wrap max-h-96 overflow-y-auto">
{generatedContent}
</div>
</CardContent>
</Card>
)}
{/* Disclaimer */}
<div className="text-xs text-foreground-subtle bg-background-muted rounded-lg p-3">
<p className="font-medium mb-1">Note:</p>
<p>
AI-generated content is a starting point. Always review, fact-check,
and customize with your expertise before publishing.
</p>
</div>
</div>
</div>
);
}
|