OhMyDitzzy commited on
Commit ·
407ba4e
1
Parent(s): ce31208
anything
Browse files
src/modules/comic/ComicReader.tsx
CHANGED
|
@@ -35,14 +35,60 @@ export function ComicReader() {
|
|
| 35 |
const [showControls, setShowControls] = useState(true);
|
| 36 |
const [showPageJump, setShowPageJump] = useState(false);
|
| 37 |
const [jumpPage, setJumpPage] = useState('');
|
|
|
|
| 38 |
|
| 39 |
const imageRefs = useRef<{ [key: number]: HTMLImageElement | null }>({});
|
| 40 |
const controlsTimeout = useRef<number | null>(null);
|
| 41 |
const scrollContainerRef = useRef<HTMLDivElement | null>(null);
|
|
|
|
| 42 |
|
| 43 |
const chapterData = location.state?.chapterData;
|
| 44 |
const password = location.state?.password;
|
| 45 |
const originalSessionId = location.state?.sessionId;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
useEffect(() => {
|
| 48 |
if (chapterData) {
|
|
@@ -152,9 +198,26 @@ export function ComicReader() {
|
|
| 152 |
}
|
| 153 |
};
|
| 154 |
|
| 155 |
-
// @ts-ignore
|
| 156 |
const handleChapterNavigation = (chapterSlug: string) => {
|
| 157 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
};
|
| 159 |
|
| 160 |
if (loading) {
|
|
@@ -166,6 +229,15 @@ export function ComicReader() {
|
|
| 166 |
);
|
| 167 |
}
|
| 168 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
if (error || !data) {
|
| 170 |
return (
|
| 171 |
<div className="reader-error">
|
|
@@ -198,6 +270,7 @@ export function ComicReader() {
|
|
| 198 |
☰
|
| 199 |
</button>
|
| 200 |
</div>
|
|
|
|
| 201 |
{showMenu && (
|
| 202 |
<div className="hamburger-menu" onClick={() => setShowMenu(false)}>
|
| 203 |
<div className="menu-content" onClick={(e) => e.stopPropagation()}>
|
|
@@ -242,6 +315,7 @@ export function ComicReader() {
|
|
| 242 |
</div>
|
| 243 |
</div>
|
| 244 |
)}
|
|
|
|
| 245 |
{showPageJump && (
|
| 246 |
<div className="page-jump-modal" onClick={() => setShowPageJump(false)}>
|
| 247 |
<div className="page-jump-content" onClick={(e) => e.stopPropagation()}>
|
|
@@ -263,6 +337,7 @@ export function ComicReader() {
|
|
| 263 |
</div>
|
| 264 |
</div>
|
| 265 |
)}
|
|
|
|
| 266 |
<div className="reader-content" ref={scrollContainerRef}>
|
| 267 |
<div className="scroll-container">
|
| 268 |
{data.images.map((img) => (
|
|
@@ -280,6 +355,7 @@ export function ComicReader() {
|
|
| 280 |
))}
|
| 281 |
</div>
|
| 282 |
</div>
|
|
|
|
| 283 |
<div className="reader-footer">
|
| 284 |
<div className="page-controls">
|
| 285 |
<button
|
|
@@ -310,6 +386,7 @@ export function ComicReader() {
|
|
| 310 |
Next →
|
| 311 |
</button>
|
| 312 |
</div>
|
|
|
|
| 313 |
{(data.prevChapter || data.nextChapter) && (
|
| 314 |
<div className="chapter-navigation">
|
| 315 |
{data.prevChapter && (
|
|
|
|
| 35 |
const [showControls, setShowControls] = useState(true);
|
| 36 |
const [showPageJump, setShowPageJump] = useState(false);
|
| 37 |
const [jumpPage, setJumpPage] = useState('');
|
| 38 |
+
const [loadingChapter, setLoadingChapter] = useState(false);
|
| 39 |
|
| 40 |
const imageRefs = useRef<{ [key: number]: HTMLImageElement | null }>({});
|
| 41 |
const controlsTimeout = useRef<number | null>(null);
|
| 42 |
const scrollContainerRef = useRef<HTMLDivElement | null>(null);
|
| 43 |
+
const wsRef = useRef<WebSocket | null>(null);
|
| 44 |
|
| 45 |
const chapterData = location.state?.chapterData;
|
| 46 |
const password = location.state?.password;
|
| 47 |
const originalSessionId = location.state?.sessionId;
|
| 48 |
+
useEffect(() => {
|
| 49 |
+
if (!password || !originalSessionId) return;
|
| 50 |
+
|
| 51 |
+
const wsUrl = import.meta.env.VITE_WS_URL || 'wss://ditzzy-yuki.hf.space/ws';
|
| 52 |
+
const ws = new WebSocket(wsUrl);
|
| 53 |
+
wsRef.current = ws;
|
| 54 |
+
|
| 55 |
+
ws.onopen = () => {
|
| 56 |
+
console.log('[Reader WS] Connected');
|
| 57 |
+
};
|
| 58 |
+
|
| 59 |
+
ws.onmessage = (event) => {
|
| 60 |
+
try {
|
| 61 |
+
const message = JSON.parse(event.data);
|
| 62 |
+
|
| 63 |
+
if (message.type === 'chapter_data_response') {
|
| 64 |
+
setLoadingChapter(false);
|
| 65 |
+
|
| 66 |
+
if (message.success && message.data) {
|
| 67 |
+
setData(message.data);
|
| 68 |
+
setCurrentPage(1);
|
| 69 |
+
scrollContainerRef.current?.scrollTo({ top: 0 });
|
| 70 |
+
} else {
|
| 71 |
+
setError(message.error || 'Failed to load chapter');
|
| 72 |
+
}
|
| 73 |
+
}
|
| 74 |
+
} catch (err) {
|
| 75 |
+
console.error('[Reader WS] Parse error:', err);
|
| 76 |
+
}
|
| 77 |
+
};
|
| 78 |
+
|
| 79 |
+
ws.onerror = (err) => {
|
| 80 |
+
console.error('[Reader WS] Error:', err);
|
| 81 |
+
setLoadingChapter(false);
|
| 82 |
+
};
|
| 83 |
+
|
| 84 |
+
ws.onclose = () => {
|
| 85 |
+
console.log('[Reader WS] Disconnected');
|
| 86 |
+
};
|
| 87 |
+
|
| 88 |
+
return () => {
|
| 89 |
+
ws.close();
|
| 90 |
+
};
|
| 91 |
+
}, [password, originalSessionId]);
|
| 92 |
|
| 93 |
useEffect(() => {
|
| 94 |
if (chapterData) {
|
|
|
|
| 198 |
}
|
| 199 |
};
|
| 200 |
|
|
|
|
| 201 |
const handleChapterNavigation = (chapterSlug: string) => {
|
| 202 |
+
if (!wsRef.current || wsRef.current.readyState !== WebSocket.OPEN) {
|
| 203 |
+
setError('Connection lost. Please refresh the page.');
|
| 204 |
+
return;
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
if (!password || !originalSessionId) {
|
| 208 |
+
setError('Missing authentication data');
|
| 209 |
+
return;
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
setLoadingChapter(true);
|
| 213 |
+
setShowMenu(false);
|
| 214 |
+
|
| 215 |
+
wsRef.current.send(JSON.stringify({
|
| 216 |
+
type: 'request_chapter_data',
|
| 217 |
+
sessionId: originalSessionId,
|
| 218 |
+
password: password,
|
| 219 |
+
chapterSlug: chapterSlug
|
| 220 |
+
}));
|
| 221 |
};
|
| 222 |
|
| 223 |
if (loading) {
|
|
|
|
| 229 |
);
|
| 230 |
}
|
| 231 |
|
| 232 |
+
if (loadingChapter) {
|
| 233 |
+
return (
|
| 234 |
+
<div className="reader-loading">
|
| 235 |
+
<div className="spinner"></div>
|
| 236 |
+
<p>Loading next chapter...</p>
|
| 237 |
+
</div>
|
| 238 |
+
);
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
if (error || !data) {
|
| 242 |
return (
|
| 243 |
<div className="reader-error">
|
|
|
|
| 270 |
☰
|
| 271 |
</button>
|
| 272 |
</div>
|
| 273 |
+
|
| 274 |
{showMenu && (
|
| 275 |
<div className="hamburger-menu" onClick={() => setShowMenu(false)}>
|
| 276 |
<div className="menu-content" onClick={(e) => e.stopPropagation()}>
|
|
|
|
| 315 |
</div>
|
| 316 |
</div>
|
| 317 |
)}
|
| 318 |
+
|
| 319 |
{showPageJump && (
|
| 320 |
<div className="page-jump-modal" onClick={() => setShowPageJump(false)}>
|
| 321 |
<div className="page-jump-content" onClick={(e) => e.stopPropagation()}>
|
|
|
|
| 337 |
</div>
|
| 338 |
</div>
|
| 339 |
)}
|
| 340 |
+
|
| 341 |
<div className="reader-content" ref={scrollContainerRef}>
|
| 342 |
<div className="scroll-container">
|
| 343 |
{data.images.map((img) => (
|
|
|
|
| 355 |
))}
|
| 356 |
</div>
|
| 357 |
</div>
|
| 358 |
+
|
| 359 |
<div className="reader-footer">
|
| 360 |
<div className="page-controls">
|
| 361 |
<button
|
|
|
|
| 386 |
Next →
|
| 387 |
</button>
|
| 388 |
</div>
|
| 389 |
+
|
| 390 |
{(data.prevChapter || data.nextChapter) && (
|
| 391 |
<div className="chapter-navigation">
|
| 392 |
{data.prevChapter && (
|