source: chapterx-frontend/src/pages/reading-list/ReadingListPage.tsx@ b62cefc

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

Added frontend and imporoved AI Suggestions service

  • Property mode set to 100644
File size: 9.0 KB
RevLine 
[b62cefc]1import React, { useState } from 'react'
2import { useNavigate } from 'react-router-dom'
3import { Plus, BookOpen, Lock, Globe, Trash2, X } from 'lucide-react'
4import { useAuthStore } from '../../store/authStore'
5import { useStoryStore } from '../../store/storyStore'
6import { useUIStore } from '../../store/uiStore'
7import { Button } from '../../components/ui/Button'
8import { Modal } from '../../components/ui/Modal'
9import { GenreBadge } from '../../components/ui/Badge'
10
11export const ReadingListPage: React.FC = () => {
12 const navigate = useNavigate()
13 const { currentUser } = useAuthStore()
14 const { readingLists, createReadingList, deleteReadingList, removeStoryFromList } = useStoryStore()
15 const { addToast } = useUIStore()
16 const [createOpen, setCreateOpen] = useState(false)
17 const [newListName, setNewListName] = useState('')
18 const [newListDesc, setNewListDesc] = useState('')
19 const [isPublic, setIsPublic] = useState(false)
20
21 if (!currentUser) {
22 return (
23 <div className="max-w-4xl mx-auto px-4 py-20 text-center">
24 <BookOpen size={48} className="mx-auto mb-4 text-slate-600" />
25 <h2 className="text-2xl text-white mb-2">Sign in to view your reading lists</h2>
26 <Button onClick={() => navigate('/login')} className="mt-4">Sign In</Button>
27 </div>
28 )
29 }
30
31 const myLists = readingLists.filter(l => l.user_id === currentUser.user_id)
32
33 const handleCreate = () => {
34 if (!newListName.trim()) return
35 createReadingList({
36 list_id: Date.now(),
37 user_id: currentUser.user_id,
38 username: currentUser.username,
39 name: newListName.trim(),
40 description: newListDesc.trim() || undefined,
41 is_public: isPublic,
42 created_at: new Date().toISOString(),
43 stories: [],
44 })
45 addToast(`"${newListName}" created!`)
46 setNewListName('')
47 setNewListDesc('')
48 setIsPublic(false)
49 setCreateOpen(false)
50 }
51
52 return (
53 <div className="max-w-6xl mx-auto px-4 py-8">
54 {/* Header */}
55 <div className="flex items-center justify-between mb-8">
56 <div>
57 <h1 className="font-serif text-3xl font-bold text-white">My Reading Lists</h1>
58 <p className="text-slate-400 mt-1">{myLists.length} list{myLists.length !== 1 ? 's' : ''}</p>
59 </div>
60 <Button onClick={() => setCreateOpen(true)}>
61 <Plus size={16} />
62 New List
63 </Button>
64 </div>
65
66 {myLists.length === 0 ? (
67 <div className="flex flex-col items-center py-20 text-slate-500">
68 <BookOpen size={48} className="mb-4 opacity-40" />
69 <h3 className="text-lg font-medium text-white mb-2">No reading lists yet</h3>
70 <p className="text-sm mb-4">Create your first list to save stories you love.</p>
71 <Button onClick={() => setCreateOpen(true)}>
72 <Plus size={14} />
73 Create Reading List
74 </Button>
75 </div>
76 ) : (
77 <div className="grid grid-cols-1 md:grid-cols-2 gap-6">
78 {myLists.map(list => (
79 <div key={list.list_id} className="bg-slate-800 border border-slate-700 rounded-2xl overflow-hidden hover:border-indigo-500/30 transition-all">
80 {/* Header */}
81 <div className="p-5 border-b border-slate-700">
82 <div className="flex items-start justify-between gap-3">
83 <div>
84 <div className="flex items-center gap-2 mb-1">
85 <h3 className="text-white font-semibold">{list.name}</h3>
86 {list.is_public ? (
87 <span className="flex items-center gap-1 text-xs text-emerald-400">
88 <Globe size={11} /> Public
89 </span>
90 ) : (
91 <span className="flex items-center gap-1 text-xs text-slate-500">
92 <Lock size={11} /> Private
93 </span>
94 )}
95 </div>
96 {list.description && (
97 <p className="text-slate-400 text-sm">{list.description}</p>
98 )}
99 <p className="text-slate-500 text-xs mt-1">{list.stories.length} stories</p>
100 </div>
101 <button
102 onClick={() => { deleteReadingList(list.list_id); addToast('List deleted', 'info') }}
103 className="text-slate-500 hover:text-rose-400 transition-colors p-1"
104 >
105 <Trash2 size={14} />
106 </button>
107 </div>
108 </div>
109
110 {/* Stories */}
111 <div className="p-4">
112 {list.stories.length === 0 ? (
113 <p className="text-slate-600 text-sm text-center py-4">No stories yet.</p>
114 ) : (
115 <div className="space-y-2">
116 {list.stories.slice(0, 4).map(item => (
117 <div key={item.item_id} className="flex items-center gap-3 p-2 rounded-lg hover:bg-slate-700/50 group">
118 <div className="flex-1 min-w-0">
119 <button
120 onClick={() => navigate(`/story/${item.story_id}`)}
121 className="text-white text-sm font-medium hover:text-indigo-300 transition-colors truncate block text-left"
122 >
123 {item.story_title}
124 </button>
125 <div className="flex items-center gap-2 mt-0.5">
126 <span className="text-slate-500 text-xs">by {item.author_username}</span>
127 {item.genres.slice(0, 1).map(g => <GenreBadge key={g} genre={g} />)}
128 </div>
129 </div>
130 <button
131 onClick={() => removeStoryFromList(list.list_id, item.story_id)}
132 className="opacity-0 group-hover:opacity-100 text-slate-500 hover:text-rose-400 transition-all"
133 >
134 <X size={14} />
135 </button>
136 </div>
137 ))}
138 {list.stories.length > 4 && (
139 <p className="text-slate-500 text-xs text-center pt-1">
140 +{list.stories.length - 4} more stories
141 </p>
142 )}
143 </div>
144 )}
145 <button
146 onClick={() => navigate('/browse')}
147 className="w-full mt-3 py-2 text-xs text-indigo-400 hover:text-indigo-300 flex items-center justify-center gap-1 transition-colors border border-dashed border-slate-700 rounded-lg hover:border-indigo-500/50"
148 >
149 <Plus size={12} />
150 Add stories
151 </button>
152 </div>
153 </div>
154 ))}
155 </div>
156 )}
157
158 {/* Create modal */}
159 <Modal isOpen={createOpen} onClose={() => setCreateOpen(false)} title="Create Reading List">
160 <div className="space-y-4">
161 <div>
162 <label className="block text-sm text-slate-400 mb-1.5">List Name *</label>
163 <input
164 value={newListName}
165 onChange={e => setNewListName(e.target.value)}
166 placeholder="My Fantasy Favorites..."
167 className="w-full px-4 py-3 bg-slate-800 border border-slate-700 rounded-xl text-white placeholder-slate-500 focus:outline-none focus:border-indigo-500"
168 />
169 </div>
170 <div>
171 <label className="block text-sm text-slate-400 mb-1.5">Description <span className="text-slate-600">(optional)</span></label>
172 <textarea
173 value={newListDesc}
174 onChange={e => setNewListDesc(e.target.value)}
175 placeholder="What's this list about?"
176 rows={2}
177 className="w-full px-4 py-3 bg-slate-800 border border-slate-700 rounded-xl text-white placeholder-slate-500 focus:outline-none focus:border-indigo-500 resize-none"
178 />
179 </div>
180 <div className="flex items-center gap-3">
181 <button
182 onClick={() => setIsPublic(!isPublic)}
183 className={`w-10 h-6 rounded-full transition-colors ${isPublic ? 'bg-indigo-600' : 'bg-slate-600'} relative`}
184 >
185 <div className={`absolute top-1 w-4 h-4 bg-white rounded-full transition-transform ${isPublic ? 'translate-x-5' : 'translate-x-1'}`} />
186 </button>
187 <div>
188 <p className="text-white text-sm">{isPublic ? 'Public' : 'Private'}</p>
189 <p className="text-slate-500 text-xs">{isPublic ? 'Anyone can see this list' : 'Only you can see this list'}</p>
190 </div>
191 </div>
192 <div className="flex gap-3 pt-2">
193 <Button variant="secondary" className="flex-1" onClick={() => setCreateOpen(false)}>Cancel</Button>
194 <Button className="flex-1" onClick={handleCreate} disabled={!newListName.trim()}>Create List</Button>
195 </div>
196 </div>
197 </Modal>
198 </div>
199 )
200}
Note: See TracBrowser for help on using the repository browser.