From 1b43b3213618ff6866183e97566de9f81bb0f95a Mon Sep 17 00:00:00 2001 From: Rokoucha Date: Tue, 5 Oct 2021 20:23:49 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=E3=82=B9=E3=83=88=E3=83=AA=E3=83=BC?= =?UTF-8?q?=E3=83=A0=E3=81=AE=E5=86=8D=E6=8E=A5=E7=B6=9A=E3=82=92=E8=AA=BF?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit めちゃくちゃ繋ぎなおそうとするのでアカンわ… --- src/components/futabaComemntProvider.tsx | 23 +++++++++++++++-------- src/components/futabaCommentStreamer.tsx | 10 +++++----- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/components/futabaComemntProvider.tsx b/src/components/futabaComemntProvider.tsx index 5c00c2a..c724274 100644 --- a/src/components/futabaComemntProvider.tsx +++ b/src/components/futabaComemntProvider.tsx @@ -1,4 +1,4 @@ -import { FutabaClient, Response } from '../lib/futaba' +import { FutabaClient, Response, Threads } from '../lib/futaba' import { FutabaCommentStreamer } from './futabaCommentStreamer' import { useReturnAsync } from '../utils' import React, { useEffect, useRef, useState } from 'react' @@ -43,6 +43,10 @@ export const FutabaCommentProvider: React.VFC = ({ } }, [settings]) + useEffect(() => { + streamsRef.current = [] + }, [restart]) + useEffect(() => { if (!futabaRef.current) return @@ -75,11 +79,14 @@ export const FutabaCommentProvider: React.VFC = ({ ;(async () => { let threads - try { - threads = await futaba.threads() - } catch (e) { - console.error(loggingName, e) - return + while (threads === undefined) { + console.log(loggingName, 'trying to fetch threads...') + try { + threads = await futaba.threads() + break + } catch (e) { + console.error(loggingName, e) + } } streams = threads.res @@ -98,7 +105,7 @@ export const FutabaCommentProvider: React.VFC = ({ ) }) - console.info(loggingName, streams.length, 'streams') + console.info(loggingName, streams.length, 'streams ready') streamsRef.current = streams })() @@ -112,7 +119,7 @@ export const FutabaCommentProvider: React.VFC = ({ key={index} result={result} setDplayerComment={setDplayerComment} - setRestart={setRestart} + restart={() => setRestart((restart) => !restart)} setZenzaComment={setZenzaComment} stream={stream} /> diff --git a/src/components/futabaCommentStreamer.tsx b/src/components/futabaCommentStreamer.tsx index c141a35..3502dba 100644 --- a/src/components/futabaCommentStreamer.tsx +++ b/src/components/futabaCommentStreamer.tsx @@ -8,18 +8,18 @@ const loggingName = 'Futaba Comment Streamer' as const type FutabaCommentStreamerProps = { id: number + restart: () => any result: () => string | undefined setDplayerComment: SetterOrUpdater | null - setRestart: React.Dispatch> setZenzaComment: SetterOrUpdater | null stream: AsyncGenerator } export const FutabaCommentStreamer: React.VFC = ({ id, + restart, result, setDplayerComment, - setRestart, setZenzaComment, stream, }) => { @@ -63,15 +63,15 @@ export const FutabaCommentStreamer: React.VFC = ({ } finally { console.info(loggingName, id, 'closed by remote', result()) - setRestart(true) + restart() } })() return () => { - console.info(loggingName, id, 'closed by provider') + console.info(loggingName, id, 'closed by provider', result()) stream.return() - setRestart(true) + restart() } })