OhMyDitzzy
commited on
Commit
·
ec4e9ef
1
Parent(s):
6a24e14
Anything
Browse files
src/modules/comic/ComicReader.tsx
CHANGED
|
@@ -72,10 +72,12 @@ export function ComicReader() {
|
|
| 72 |
console.log('[Reader WS] Connecting to:', wsUrl);
|
| 73 |
|
| 74 |
const ws = new WebSocket(wsUrl);
|
|
|
|
| 75 |
wsRef.current = ws;
|
| 76 |
|
| 77 |
ws.onopen = () => {
|
| 78 |
-
console.log('[Reader WS] Connected');
|
|
|
|
| 79 |
};
|
| 80 |
|
| 81 |
ws.onmessage = (event) => {
|
|
@@ -91,13 +93,23 @@ export function ComicReader() {
|
|
| 91 |
hasPrev: !!message.data.prevChapter,
|
| 92 |
hasNext: !!message.data.nextChapter,
|
| 93 |
prevChapter: message.data.prevChapter,
|
| 94 |
-
nextChapter: message.data.nextChapter
|
|
|
|
|
|
|
| 95 |
});
|
| 96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
setCurrentPage(1);
|
| 98 |
scrollContainerRef.current?.scrollTo({ top: 0 });
|
| 99 |
} else {
|
| 100 |
setError(message.error || 'Failed to load chapter');
|
|
|
|
| 101 |
}
|
| 102 |
}
|
| 103 |
} catch (err) {
|
|
@@ -108,6 +120,9 @@ export function ComicReader() {
|
|
| 108 |
ws.onerror = (err) => {
|
| 109 |
console.error('[Reader WS] Error:', err);
|
| 110 |
setLoadingChapter(false);
|
|
|
|
|
|
|
|
|
|
| 111 |
};
|
| 112 |
|
| 113 |
ws.onclose = () => {
|
|
|
|
| 72 |
console.log('[Reader WS] Connecting to:', wsUrl);
|
| 73 |
|
| 74 |
const ws = new WebSocket(wsUrl);
|
| 75 |
+
let isConnected = false;
|
| 76 |
wsRef.current = ws;
|
| 77 |
|
| 78 |
ws.onopen = () => {
|
| 79 |
+
console.log('[Reader WS] Connected and ready');
|
| 80 |
+
isConnected = true;
|
| 81 |
};
|
| 82 |
|
| 83 |
ws.onmessage = (event) => {
|
|
|
|
| 93 |
hasPrev: !!message.data.prevChapter,
|
| 94 |
hasNext: !!message.data.nextChapter,
|
| 95 |
prevChapter: message.data.prevChapter,
|
| 96 |
+
nextChapter: message.data.nextChapter,
|
| 97 |
+
hasAllChapters: !!message.data.allChapters,
|
| 98 |
+
allChaptersCount: message.data.allChapters?.length || 0
|
| 99 |
});
|
| 100 |
+
|
| 101 |
+
// Preserve allChapters if not in response
|
| 102 |
+
const newData = {
|
| 103 |
+
...message.data,
|
| 104 |
+
allChapters: message.data.allChapters || data?.allChapters || []
|
| 105 |
+
};
|
| 106 |
+
|
| 107 |
+
setData(newData);
|
| 108 |
setCurrentPage(1);
|
| 109 |
scrollContainerRef.current?.scrollTo({ top: 0 });
|
| 110 |
} else {
|
| 111 |
setError(message.error || 'Failed to load chapter');
|
| 112 |
+
setTimeout(() => setError(''), 3000);
|
| 113 |
}
|
| 114 |
}
|
| 115 |
} catch (err) {
|
|
|
|
| 120 |
ws.onerror = (err) => {
|
| 121 |
console.error('[Reader WS] Error:', err);
|
| 122 |
setLoadingChapter(false);
|
| 123 |
+
if (!isConnected) {
|
| 124 |
+
setError('Failed to connect to server');
|
| 125 |
+
}
|
| 126 |
};
|
| 127 |
|
| 128 |
ws.onclose = () => {
|