File size: 12,336 Bytes
921d377 | 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 405 406 | import React, { useState, useEffect, useCallback } from "react";
import { useTVModeStore } from "../../stores/tvModeStore";
export const TVModeChapterTransition = ({ onContinue, onCancel, nextChapterTitle, countdown: initialCountdown = 5, }) => {
const { storyTitle, chapterNumber, isLoadingNextChapter } = useTVModeStore();
const [countdown, setCountdown] = useState(initialCountdown);
const [isPaused, setIsPaused] = useState(false);
const [isStarting, setIsStarting] = useState(false);
const handleContinue = useCallback(async () => {
if (isLoadingNextChapter || isStarting)
return;
setIsStarting(true);
try {
await onContinue();
}
catch (error) {
setIsStarting(false);
}
}, [onContinue, isLoadingNextChapter, isStarting]);
// Countdown timer
useEffect(() => {
if (isPaused || isLoadingNextChapter || isStarting)
return;
if (countdown <= 0) {
handleContinue();
return;
}
const timer = setTimeout(() => {
setCountdown((prev) => prev - 1);
}, 1000);
return () => clearTimeout(timer);
}, [countdown, isPaused, isLoadingNextChapter, isStarting, handleContinue]);
const handlePauseToggle = () => {
setIsPaused((prev) => !prev);
};
const handleSkip = () => {
handleContinue();
};
return (<div className="chapter-transition-overlay">
<div className="chapter-transition-content">
{/* Chapter Complete Badge */}
<div className="chapter-complete-badge">
<div className="badge-icon">
<svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
<path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/>
<polyline points="22 4 12 14.01 9 11.01"/>
</svg>
</div>
<span>Chapter {chapterNumber} Complete</span>
</div>
{/* Story Title */}
<h2 className="story-title">{storyTitle}</h2>
{/* Divider with decoration */}
<div className="divider">
<span className="divider-line"></span>
<span className="divider-icon">
<svg width="24" height="24" viewBox="0 0 24 24" fill="currentColor">
<path d="M12 2L15.09 8.26L22 9.27L17 14.14L18.18 21.02L12 17.77L5.82 21.02L7 14.14L2 9.27L8.91 8.26L12 2Z"/>
</svg>
</span>
<span className="divider-line"></span>
</div>
{/* Next Episode Announcement */}
<div className="next-episode">
<span className="next-label">Next Episode</span>
<h3 className="next-title">
{nextChapterTitle || `Chapter ${chapterNumber + 1}`}
</h3>
</div>
{/* Loading or Countdown */}
{isLoadingNextChapter || isStarting ? (<div className="loading-section">
<div className="loading-spinner-large"/>
<p className="loading-text">Generating next chapter...</p>
</div>) : (<>
{/* Countdown Ring */}
<div className="countdown-container">
<svg className="countdown-ring" viewBox="0 0 100 100">
<circle className="countdown-bg" cx="50" cy="50" r="45" fill="none" stroke="rgba(255,255,255,0.1)" strokeWidth="4"/>
<circle className="countdown-progress" cx="50" cy="50" r="45" fill="none" stroke="url(#gradient)" strokeWidth="4" strokeLinecap="round" strokeDasharray={`${(countdown / initialCountdown) * 283} 283`} transform="rotate(-90 50 50)" style={{
transition: isPaused ? "none" : "stroke-dasharray 1s linear",
}}/>
<defs>
<linearGradient id="gradient" x1="0%" y1="0%" x2="100%" y2="0%">
<stop offset="0%" stopColor="#8B5CF6"/>
<stop offset="100%" stopColor="#6366F1"/>
</linearGradient>
</defs>
</svg>
<div className="countdown-text">
<span className="countdown-number">{countdown}</span>
<span className="countdown-label">
{isPaused ? "Paused" : "seconds"}
</span>
</div>
</div>
{/* Action Buttons */}
<div className="transition-actions">
<button className="action-btn skip" onClick={handleSkip} title="Start now">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
<polygon points="5 4 15 12 5 20 5 4" fill="currentColor"/>
<line x1="19" y1="5" x2="19" y2="19"/>
</svg>
Start Now
</button>
<button className="action-btn pause" onClick={handlePauseToggle} title={isPaused ? "Resume" : "Pause"}>
{isPaused ? (<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor">
<polygon points="5 3 19 12 5 21 5 3"/>
</svg>) : (<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor">
<rect x="6" y="4" width="4" height="16"/>
<rect x="14" y="4" width="4" height="16"/>
</svg>)}
{isPaused ? "Resume" : "Pause"}
</button>
<button className="action-btn cancel" onClick={onCancel} title="Stop and exit">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
<rect x="3" y="3" width="18" height="18" rx="2"/>
</svg>
Stop
</button>
</div>
</>)}
</div>
<style>{`
.chapter-transition-overlay {
position: absolute;
inset: 0;
background: linear-gradient(135deg, rgba(0, 0, 0, 0.95), rgba(20, 10, 40, 0.95));
display: flex;
align-items: center;
justify-content: center;
z-index: 100;
animation: fadeIn 500ms ease;
}
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
.chapter-transition-content {
text-align: center;
padding: 40px;
max-width: 500px;
animation: slideUp 600ms ease;
}
@keyframes slideUp {
from {
opacity: 0;
transform: translateY(30px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.chapter-complete-badge {
display: inline-flex;
align-items: center;
gap: 12px;
background: linear-gradient(135deg, rgba(34, 197, 94, 0.2), rgba(34, 197, 94, 0.1));
border: 1px solid rgba(34, 197, 94, 0.3);
padding: 12px 24px;
border-radius: 50px;
margin-bottom: 24px;
animation: badgePop 500ms ease 200ms both;
}
@keyframes badgePop {
0% {
opacity: 0;
transform: scale(0.8);
}
50% {
transform: scale(1.05);
}
100% {
opacity: 1;
transform: scale(1);
}
}
.badge-icon {
color: #22C55E;
display: flex;
}
.chapter-complete-badge span {
color: #22C55E;
font-size: 16px;
font-weight: 600;
letter-spacing: 0.5px;
}
.story-title {
font-size: 28px;
font-weight: 300;
color: rgba(255, 255, 255, 0.7);
margin: 0 0 24px;
letter-spacing: 1px;
}
.divider {
display: flex;
align-items: center;
gap: 16px;
margin-bottom: 24px;
}
.divider-line {
flex: 1;
height: 1px;
background: linear-gradient(90deg, transparent, rgba(139, 92, 246, 0.5), transparent);
}
.divider-icon {
color: #8B5CF6;
animation: starPulse 2s ease-in-out infinite;
}
@keyframes starPulse {
0%, 100% {
transform: scale(1);
filter: drop-shadow(0 0 4px rgba(139, 92, 246, 0.5));
}
50% {
transform: scale(1.1);
filter: drop-shadow(0 0 12px rgba(139, 92, 246, 0.8));
}
}
.next-episode {
margin-bottom: 32px;
}
.next-label {
display: block;
font-size: 14px;
text-transform: uppercase;
letter-spacing: 3px;
color: rgba(255, 255, 255, 0.5);
margin-bottom: 8px;
}
.next-title {
font-size: 36px;
font-weight: 600;
color: #fff;
margin: 0;
text-shadow: 0 2px 20px rgba(139, 92, 246, 0.5);
}
.loading-section {
padding: 40px 0;
}
.loading-spinner-large {
width: 60px;
height: 60px;
border: 4px solid rgba(139, 92, 246, 0.2);
border-top-color: #8B5CF6;
border-radius: 50%;
margin: 0 auto 20px;
animation: spin 1s linear infinite;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
.loading-text {
color: rgba(255, 255, 255, 0.7);
font-size: 16px;
margin: 0;
}
.countdown-container {
position: relative;
width: 120px;
height: 120px;
margin: 0 auto 32px;
}
.countdown-ring {
width: 100%;
height: 100%;
}
.countdown-text {
position: absolute;
inset: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.countdown-number {
font-size: 42px;
font-weight: 700;
color: #fff;
line-height: 1;
}
.countdown-label {
font-size: 12px;
color: rgba(255, 255, 255, 0.5);
text-transform: uppercase;
letter-spacing: 1px;
}
.transition-actions {
display: flex;
justify-content: center;
gap: 12px;
flex-wrap: wrap;
}
.action-btn {
display: flex;
align-items: center;
gap: 8px;
padding: 12px 20px;
border-radius: 12px;
font-size: 14px;
font-weight: 500;
cursor: pointer;
transition: all 0.2s ease;
}
.action-btn.skip {
background: linear-gradient(135deg, #8B5CF6, #6366F1);
border: none;
color: #fff;
}
.action-btn.skip:hover {
transform: translateY(-2px);
box-shadow: 0 8px 24px rgba(139, 92, 246, 0.4);
}
.action-btn.pause {
background: rgba(255, 255, 255, 0.1);
border: 1px solid rgba(255, 255, 255, 0.2);
color: #fff;
}
.action-btn.pause:hover {
background: rgba(255, 255, 255, 0.15);
border-color: rgba(255, 255, 255, 0.3);
}
.action-btn.cancel {
background: transparent;
border: 1px solid rgba(255, 255, 255, 0.2);
color: rgba(255, 255, 255, 0.7);
}
.action-btn.cancel:hover {
border-color: rgba(239, 68, 68, 0.5);
color: #EF4444;
}
@media (max-width: 768px) {
.chapter-transition-content {
padding: 24px;
}
.story-title {
font-size: 22px;
}
.next-title {
font-size: 28px;
}
.countdown-container {
width: 100px;
height: 100px;
}
.countdown-number {
font-size: 36px;
}
.transition-actions {
flex-direction: column;
}
.action-btn {
justify-content: center;
}
}
`}</style>
</div>);
};
export default TVModeChapterTransition;
|