Skip to content

Commit

Permalink
fix: 修正
Browse files Browse the repository at this point in the history
  • Loading branch information
narirou committed Dec 4, 2024
1 parent c7cdf6d commit 56a1692
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions frontend/app/contexts/client-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,21 @@ export const useNotification = ():
const notification = await fetch(`${apiBaseURL}/app/notification`);
if (notification.status === 401) {
navigate("/client/register");
return;
}

const sse = notification?.headers
const isEventStream = notification?.headers
.get("Content-type")
?.split(";")[0]
.includes("text/event-stream");
setIsSse(!!sse);

if (sse) {
setIsSse(!!isEventStream);
if (isEventStream) {
const reader = notification.body?.getReader();
const decoder = new TextDecoder();
const readed = (await reader?.read())?.value;
const decoded = decoder.decode(readed);
const json =
jsonFromSSEResponse<AppGetNotificationResponse["data"]>(decoded);
setNotification(
json
? {
data: json,
}
: undefined,
);
setNotification(json ? { data: json } : undefined);
return;
}
const json = (await notification.json()) as
Expand Down

0 comments on commit 56a1692

Please sign in to comment.