OhMyDitzzy commited on
Commit
6a24e14
·
1 Parent(s): b438982
Files changed (1) hide show
  1. src/modules/comic/ComicLanding.tsx +59 -47
src/modules/comic/ComicLanding.tsx CHANGED
@@ -80,11 +80,13 @@ export function ComicLanding() {
80
  if (message.success) {
81
  setComicData(message.data);
82
  setIsAuth(true);
83
-
84
- sessionStorage.setItem(`comic_${sessionId}`, JSON.stringify({
85
- password,
86
- expiresAt: message.expiresAt
87
- }));
 
 
88
 
89
  setLoadingChapter(false);
90
  } else {
@@ -94,27 +96,31 @@ export function ComicLanding() {
94
  }
95
 
96
  if (message.type === 'chapter_data_response') {
97
- setLoadingChapter(false);
98
- if (message.success) {
99
- console.log('[ComicLanding] Navigating to reader with:', {
100
- hasData: !!message.data,
101
- hasPassword: !!password,
102
- password: password,
103
- sessionId: sessionId
104
- });
105
-
106
- navigate(`/read/${sessionId}_chapter`, {
107
- state: {
108
- chapterData: message.data,
109
- password: password, // Make sure password is passed
110
- sessionId: sessionId // Make sure sessionId is passed
111
- }
112
- });
113
- } else {
114
- setError(message.error || 'Gagal memuat chapter');
115
- setTimeout(() => setError(''), 3000);
116
- }
117
- }
 
 
 
 
118
  };
119
 
120
  websocket.onerror = () => {
@@ -127,10 +133,10 @@ export function ComicLanding() {
127
  return () => {
128
  websocket.close();
129
  };
130
- }, [sessionId]);
131
 
132
  useEffect(() => {
133
- if (isAuth && ws && !comicData) {
134
  ws.send(JSON.stringify({
135
  type: 'request_comic_data',
136
  sessionId,
@@ -157,27 +163,32 @@ export function ComicLanding() {
157
  };
158
 
159
  const handleReadChapter = (chapterSlug: string) => {
160
- if (!ws) {
161
- setError('WebSocket tidak terhubung');
162
- return;
163
- }
164
 
165
- console.log('[ComicLanding] Reading chapter with:', {
166
- chapterSlug,
167
- sessionId,
168
- hasPassword: !!password,
169
- password: password
170
- });
171
 
172
- setLoadingChapter(true);
173
-
174
- ws.send(JSON.stringify({
175
- type: 'request_chapter_data',
176
- sessionId,
177
- password,
178
- chapterSlug
179
- }));
180
- };
 
 
 
 
 
 
 
181
 
182
  const filteredChapters = comicData?.chapters.filter(ch =>
183
  ch.chapter.toLowerCase().includes(searchQuery.toLowerCase())
@@ -324,6 +335,7 @@ export function ComicLanding() {
324
  </div>
325
  </div>
326
  </div>
 
327
  <div className="chapters-section">
328
  <div className="chapters-header">
329
  <h2>Chapters</h2>
 
80
  if (message.success) {
81
  setComicData(message.data);
82
  setIsAuth(true);
83
+ setPassword((currentPassword) => {
84
+ sessionStorage.setItem(`comic_${sessionId}`, JSON.stringify({
85
+ password: currentPassword,
86
+ expiresAt: message.expiresAt
87
+ }));
88
+ return currentPassword;
89
+ });
90
 
91
  setLoadingChapter(false);
92
  } else {
 
96
  }
97
 
98
  if (message.type === 'chapter_data_response') {
99
+ setLoadingChapter(false);
100
+ if (message.success) {
101
+ setPassword((currentPassword) => {
102
+ console.log('[ComicLanding] Navigating to reader with:', {
103
+ hasData: !!message.data,
104
+ hasPassword: !!currentPassword,
105
+ password: currentPassword,
106
+ sessionId: sessionId
107
+ });
108
+
109
+ navigate(`/read/${sessionId}_chapter`, {
110
+ state: {
111
+ chapterData: message.data,
112
+ password: currentPassword,
113
+ sessionId: sessionId
114
+ }
115
+ });
116
+
117
+ return currentPassword;
118
+ });
119
+ } else {
120
+ setError(message.error || 'Gagal memuat chapter');
121
+ setTimeout(() => setError(''), 3000);
122
+ }
123
+ }
124
  };
125
 
126
  websocket.onerror = () => {
 
133
  return () => {
134
  websocket.close();
135
  };
136
+ }, [sessionId, navigate]);
137
 
138
  useEffect(() => {
139
+ if (isAuth && ws && !comicData && password) {
140
  ws.send(JSON.stringify({
141
  type: 'request_comic_data',
142
  sessionId,
 
163
  };
164
 
165
  const handleReadChapter = (chapterSlug: string) => {
166
+ if (!ws) {
167
+ setError('WebSocket tidak terhubung');
168
+ return;
169
+ }
170
 
171
+ if (!password) {
172
+ setError('Password tidak tersedia');
173
+ return;
174
+ }
 
 
175
 
176
+ console.log('[ComicLanding] Reading chapter with:', {
177
+ chapterSlug,
178
+ sessionId,
179
+ hasPassword: !!password,
180
+ password: password
181
+ });
182
+
183
+ setLoadingChapter(true);
184
+
185
+ ws.send(JSON.stringify({
186
+ type: 'request_chapter_data',
187
+ sessionId,
188
+ password,
189
+ chapterSlug
190
+ }));
191
+ };
192
 
193
  const filteredChapters = comicData?.chapters.filter(ch =>
194
  ch.chapter.toLowerCase().includes(searchQuery.toLowerCase())
 
335
  </div>
336
  </div>
337
  </div>
338
+
339
  <div className="chapters-section">
340
  <div className="chapters-header">
341
  <h2>Chapters</h2>