-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
404 페이지, 존재하지 않는 스페이스 페이지 핸들링 #166
Changes from all commits
f956286
f2033ff
2850a63
5600361
b399f33
884e453
e78cd83
fcf1c6c
00131d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { ReactNode } from "react"; | ||
|
||
import buzzyLogo from "@/assets/error-logo.svg"; | ||
|
||
type ErrorSectionProps = { | ||
description: string; | ||
RestoreActions?: () => ReactNode; | ||
}; | ||
|
||
export default function ErrorSection({ | ||
description, | ||
RestoreActions, | ||
}: ErrorSectionProps) { | ||
return ( | ||
<div className="container mx-auto px-6 h-full text-center"> | ||
<div className="flex flex-col w-full h-full justify-center items-center"> | ||
<img src={buzzyLogo} className="w-36" /> | ||
<div className="mt-8 text-base"> | ||
<p>{description}</p> | ||
</div> | ||
{RestoreActions && ( | ||
<div className="mt-12"> | ||
<RestoreActions /> | ||
</div> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,16 @@ import * as Y from "yjs"; | |
import { generateUserColor } from "@/lib/utils"; | ||
|
||
export default function useYjsConnection(docName: string) { | ||
const [status, setStatus] = useState< | ||
"connecting" | "connected" | "disconnected" | ||
>("connecting"); | ||
const [error, setError] = useState<Error>(); | ||
const [yDoc, setYDoc] = useState<Y.Doc>(); | ||
const [yProvider, setYProvider] = useState<Y.AbstractConnector>(); | ||
|
||
useEffect(() => { | ||
setStatus("connecting"); | ||
|
||
const doc = new Y.Doc(); | ||
const provider = new WebsocketProvider( | ||
`ws://${import.meta.env.DEV ? "localhost" : "www.honeyflow.life"}/ws/space`, | ||
|
@@ -28,9 +34,17 @@ export default function useYjsConnection(docName: string) { | |
if (event.status === "connected") { | ||
awareness.setLocalStateField("color", generateUserColor()); | ||
} | ||
setStatus(event.status); | ||
}, | ||
); | ||
|
||
provider.once("connection-close", (event: CloseEvent) => { | ||
if (event.code === 1008) { | ||
provider.shouldConnect = false; | ||
setError(new Error("찾을 수 없거나 접근할 수 없는 스페이스예요.")); | ||
} | ||
}); | ||
|
||
Comment on lines
+41
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (0.3점) 1008 코드 이외의 코드가 발생할 시의 대응을 추가해볼 수도 있을 것 같습니다! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 넵! 현재 백엔드에서 존재하지 않는 스페이스는 1008 코드 주면서 연결을 끊고 있는데, 다른 경우엔 "알 수 없는 오류"처럼 처리해야 할 것 같아요. 대신 이렇게 shouldConnect = false를 해줘도 될지 모르겠네요. 기본적으로 계속 연결 재시도를 하더라고요. 1008번의 경우 확실히 재연결이 필요가 없어서 이렇게 했습니다 |
||
return () => { | ||
if (provider.bcconnected || provider.wsconnected) { | ||
provider.disconnect(); | ||
|
@@ -41,5 +55,5 @@ export default function useYjsConnection(docName: string) { | |
}; | ||
}, [docName]); | ||
|
||
return { yProvider, yDoc, setYProvider, setYDoc }; | ||
return { status, error, yProvider, yDoc, setYProvider, setYDoc }; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Link } from "react-router-dom"; | ||
|
||
import { MoveLeftIcon } from "lucide-react"; | ||
|
||
import ErrorSection from "@/components/ErrorSection"; | ||
import { Button } from "@/components/ui/button"; | ||
|
||
export default function NotFoundPage() { | ||
return ( | ||
<ErrorSection | ||
description="찾을 수 없는 페이지예요" | ||
RestoreActions={() => ( | ||
<Button asChild> | ||
<Link to="/"> | ||
<MoveLeftIcon /> | ||
처음으로 돌아가기 | ||
</Link> | ||
</Button> | ||
)} | ||
/> | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RestoreAction을 따로 받아서 더욱 재사용성이 높아진 것 같습니다 !