Skip to content

Commit

Permalink
fix: rr
Browse files Browse the repository at this point in the history
  • Loading branch information
minsgy committed Sep 7, 2024
1 parent a75669f commit 75cf4b1
Showing 1 changed file with 42 additions and 42 deletions.
84 changes: 42 additions & 42 deletions src/app.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { EventSourcePolyfill } from "event-source-polyfill";
import Cookies from "js-cookie";
import { useEffect } from "react";
// import { EventSourcePolyfill } from "event-source-polyfill";
// import Cookies from "js-cookie";
// import { useEffect } from "react";
import { Toaster } from "sonner";
import { Toast } from "./components/common/Toast";
import { useMe } from "./generated/member/member";
import { useMyFlow } from "./stackflow/useMyFlow";
// import { Toast } from "./components/common/Toast";
// import { useMe } from "./generated/member/member";
// import { useMyFlow } from "./stackflow/useMyFlow";

export function App({ children }: { children: React.ReactNode }) {
return (
<>
<SSEAlert />
{/* <SSEAlert /> */}
{children}
<Toaster
position="top-center"
Expand All @@ -22,44 +22,44 @@ export function App({ children }: { children: React.ReactNode }) {
);
}

function SSEAlert() {
const { push } = useMyFlow();
const { data } = useMe();
// function SSEAlert() {
// const { push } = useMyFlow();
// const { data } = useMe();

useEffect(() => {
const token = Cookies.get("token");
if (!token) {
return;
}
// useEffect(() => {
// const token = Cookies.get("token");
// if (!token) {
// return;
// }

const src = new EventSourcePolyfill(
"https://docker-ecs.net/notification-stream",
{
headers: {
Authorization: `Bearer ${token}`,
},
heartbeatTimeout: 180000,
},
);
// const src = new EventSourcePolyfill(
// "https://docker-ecs.net/notification-stream",
// {
// headers: {
// Authorization: `Bearer ${token}`,
// },
// heartbeatTimeout: 180000,
// },
// );

src.addEventListener("picked", (v) => {
const pick = JSON.parse((v as MessageEvent).data);
const myname = data?.data?.memberName
? `${data?.data?.memberName}님을`
: "나를";
Toast.alert(`방금 누군가가 ${myname} Pick 했어요!`, () => {
push("MyPickDetailPage", { questionId: pick?.questionId ?? "" });
});
});
// src.addEventListener("picked", (v) => {
// const pick = JSON.parse((v as MessageEvent).data);
// const myname = data?.data?.memberName
// ? `${data?.data?.memberName}님을`
// : "나를";
// Toast.alert(`방금 누군가가 ${myname} Pick 했어요!`, () => {
// push("MyPickDetailPage", { questionId: pick?.questionId ?? "" });
// });
// });

src.onopen = () => {
console.log("open");
};
// src.onopen = () => {
// console.log("open");
// };

return () => {
src.close();
};
}, [data?.data?.memberName, push]);
// return () => {
// src.close();
// };
// }, [data?.data?.memberName, push]);

return <></>;
}
// return <></>;
// }

0 comments on commit 75cf4b1

Please sign in to comment.