source: chapterx-frontend/src/components/writer/StoryCreationAIPanel.tsx@ 73b69b2

main
Last change on this file since 73b69b2 was acf690c, checked in by kikisrbinoska <srbinoskakristina07@…>, 4 months ago

Added fixes for the login,stories management and reading lists

  • Property mode set to 100644
File size: 5.9 KB
RevLine 
[acf690c]1import React, { useMemo, useImperativeHandle, forwardRef } from 'react'
2import { Sparkles, Lightbulb } from 'lucide-react'
3
4interface StoryCreationAIPanelProps {
5 title: string
6 description: string
7 content: string
8 genres: string[]
9}
10
11export interface StoryCreationAIPanelRef {
12 getSuggestions: () => Array<{ originalText: string; suggestedText: string }>
13}
14
15interface Tip {
16 type: 'plot' | 'style' | 'character' | 'grammar' | 'pacing'
17 label: string
18 original: string
19 suggested: string
20}
21
22const typeColors: Record<Tip['type'], string> = {
23 plot: 'bg-amber-500/20 text-amber-300 border-amber-500/30',
24 style: 'bg-violet-500/20 text-violet-300 border-violet-500/30',
25 character: 'bg-emerald-500/20 text-emerald-300 border-emerald-500/30',
26 grammar: 'bg-blue-500/20 text-blue-300 border-blue-500/30',
27 pacing: 'bg-pink-500/20 text-pink-300 border-pink-500/30',
28}
29
30function buildTips(title: string, description: string, content: string, genres: string[]): Tip[] {
31 const tips: Tip[] = []
32 const wordCount = content.trim().split(/\s+/).filter(Boolean).length
33
34 if (!title.trim()) {
35 tips.push({ type: 'style', label: 'Title', original: '(no title)', suggested: 'Add a title that hints at the core conflict or world without giving it away.' })
36 } else if (title.length < 5) {
37 tips.push({ type: 'style', label: 'Title', original: title, suggested: 'Consider a more evocative title — even 3–4 punchy words can create intrigue.' })
38 }
39
40 if (!description.trim()) {
41 tips.push({ type: 'plot', label: 'Description', original: '(no description)', suggested: 'Introduce the protagonist, hint at the conflict, and end with a hook that makes readers want more.' })
42 } else if (description.length < 60) {
43 tips.push({ type: 'plot', label: 'Description', original: description, suggested: 'Expand your description — give readers a taste of the stakes and what your protagonist stands to lose.' })
44 }
45
46 if (!content.trim()) {
47 tips.push({ type: 'character', label: 'Opening', original: '(no content)', suggested: 'Start in the middle of action or a compelling character moment. Avoid opening with backstory dumps.' })
48 } else if (wordCount < 50) {
49 tips.push({ type: 'pacing', label: 'Content length', original: `${wordCount} words`, suggested: 'Give readers more to engage with — the opening sets tone and world before the story begins.' })
50 } else if (wordCount > 200) {
51 tips.push({ type: 'pacing', label: 'Pacing', original: content.slice(0, 80) + '...', suggested: 'Great start! Keep momentum — each paragraph should make the reader want to continue.' })
52 }
53
54 if (genres.length === 0) {
55 tips.push({ type: 'plot', label: 'Genres', original: '(none selected)', suggested: 'Select genres to help readers discover your story. Pick the ones that best match tone and setting.' })
56 }
57
58 if (genres.includes('Fantasy') || genres.includes('Sci-Fi')) {
59 tips.push({ type: 'character', label: 'World-building', original: content.slice(0, 60) || '(content)', suggested: 'Weave world-building into scenes naturally — show the world through your character\'s eyes, not info-dumps.' })
60 }
61
62 if (genres.includes('Romance')) {
63 tips.push({ type: 'character', label: 'Chemistry', original: description || '(description)', suggested: 'Establish your characters\' desires and flaws early so their connection feels earned.' })
64 }
65
66 if (genres.includes('Thriller') || genres.includes('Mystery')) {
67 tips.push({ type: 'plot', label: 'Tension', original: content.slice(0, 60) || '(opening)', suggested: 'Plant an unanswered question in your opening. Thriller/mystery readers stay for the unresolved "why".' })
68 }
69
70 if (genres.includes('Horror')) {
71 tips.push({ type: 'pacing', label: 'Atmosphere', original: content.slice(0, 60) || '(opening)', suggested: 'Build dread gradually — horror works best when the reader senses something is wrong before the characters do.' })
72 }
73
74 return tips.slice(0, 5)
75}
76
77export const StoryCreationAIPanel = forwardRef<StoryCreationAIPanelRef, StoryCreationAIPanelProps>(
78 ({ title, description, content, genres }, ref) => {
79 const tips = useMemo(
80 () => buildTips(title, description, content, genres),
81 [title, description, content, genres.join(',')]
82 )
83
84 useImperativeHandle(ref, () => ({
85 getSuggestions: () => tips.map(t => ({ originalText: t.original, suggestedText: t.suggested })),
86 }))
87
88 return (
89 <div className="bg-slate-900 border border-slate-700 rounded-2xl p-5 sticky top-6">
90 <div className="flex items-center gap-2 mb-4">
91 <Sparkles size={16} className="text-violet-400" />
92 <h3 className="text-white font-semibold text-sm">AI Writing Tips</h3>
93 <span className="ml-auto text-xs text-slate-500">{tips.length} suggestions</span>
94 </div>
95
96 {tips.length === 0 ? (
97 <div className="text-center py-6 text-slate-500 text-sm">
98 <Sparkles size={28} className="mx-auto mb-2 opacity-30" />
99 <p>Looking great! No suggestions right now.</p>
100 </div>
101 ) : (
102 <div className="space-y-3">
103 {tips.map((tip, i) => (
104 <div key={i} className="flex gap-3 p-3 bg-slate-800 rounded-xl border border-slate-700">
105 <Lightbulb size={15} className="text-violet-400 flex-shrink-0 mt-0.5" />
106 <div className="min-w-0">
107 <div className="flex items-center gap-1.5 mb-1">
108 <span className={`px-2 py-0.5 text-xs font-medium rounded-full border ${typeColors[tip.type]}`}>
109 {tip.type}
110 </span>
111 <span className="text-xs text-slate-400 font-medium">{tip.label}</span>
112 </div>
113 <p className="text-xs text-slate-500 italic mb-1 truncate">"{tip.original}"</p>
114 <p className="text-xs text-slate-300 leading-relaxed">{tip.suggested}</p>
115 </div>
116 </div>
117 ))}
118 </div>
119 )}
120 </div>
121 )
122 }
123)
Note: See TracBrowser for help on using the repository browser.