fixed closing drawer + reconnect
This commit is contained in:
parent
59ec036380
commit
118ae220ee
|
|
@ -40,6 +40,6 @@ export const removeGems = async (
|
|||
if (count - gems < 0) throw new Error("Not enough gems");
|
||||
await db
|
||||
.update(Gems)
|
||||
.set({ count: count - gems, totalCount: totalCount - gems })
|
||||
.set({ count: count - gems, totalCount: totalCount })
|
||||
.where(eq(Gems.user, user));
|
||||
};
|
||||
|
|
|
|||
|
|
@ -57,7 +57,14 @@ const Shell: React.FC<PropsWithChildren> = ({ children }) => {
|
|||
animate={{ x }}
|
||||
transition={{ type: "tween" }}
|
||||
>
|
||||
<div className="w-full p-2 flex flex-col gap-6">
|
||||
<div
|
||||
className="w-full p-2 flex flex-col gap-6"
|
||||
onClick={() => {
|
||||
if (isMobile) {
|
||||
setIsOpen(false);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<h2 className="[background:var(--bg-brand)] [-webkit-text-fill-color:transparent] font-black [-webkit-background-clip:text!important] font-mono text-3xl">
|
||||
Business
|
||||
<br />
|
||||
|
|
@ -101,7 +108,10 @@ const Shell: React.FC<PropsWithChildren> = ({ children }) => {
|
|||
<Button
|
||||
className="absolute left-4 bg-black border-white/10 border-y-1 border-r-1 rounded-l-none"
|
||||
variant="ghost"
|
||||
onClick={() => setIsOpen((isOpen) => !isOpen)}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
setIsOpen((isOpen) => !isOpen);
|
||||
}}
|
||||
aria-label="Menu"
|
||||
>
|
||||
<Menu />
|
||||
|
|
|
|||
|
|
@ -25,6 +25,17 @@ const createWSClient = () => {
|
|||
let reconnectAttempts = 0;
|
||||
const maxReconnectAttempts = 5;
|
||||
|
||||
const tryReconnect = () => {
|
||||
if (reconnectAttempts < maxReconnectAttempts) {
|
||||
setTimeout(() => {
|
||||
reconnectAttempts++;
|
||||
connect();
|
||||
}, 1000 * reconnectAttempts);
|
||||
} else {
|
||||
console.error("Max reconnect attempts reached");
|
||||
}
|
||||
};
|
||||
|
||||
const connect = () => {
|
||||
ws = new WebSocket(connectionString);
|
||||
|
||||
|
|
@ -42,16 +53,7 @@ const createWSClient = () => {
|
|||
|
||||
ws.onmessage = emitMessage;
|
||||
|
||||
ws.onclose = () => {
|
||||
if (reconnectAttempts < maxReconnectAttempts) {
|
||||
setTimeout(() => {
|
||||
reconnectAttempts++;
|
||||
connect();
|
||||
}, 1000 * reconnectAttempts);
|
||||
} else {
|
||||
console.error("Max reconnect attempts reached");
|
||||
}
|
||||
};
|
||||
ws.onclose = tryReconnect;
|
||||
|
||||
ws.onerror = (err) => {
|
||||
console.error("WebSocket error", err);
|
||||
|
|
@ -60,6 +62,11 @@ const createWSClient = () => {
|
|||
};
|
||||
|
||||
connect();
|
||||
document.addEventListener("focus", () => {
|
||||
if (ws.readyState != ws.OPEN) {
|
||||
tryReconnect();
|
||||
}
|
||||
});
|
||||
|
||||
addMessageListener((event: MessageEvent) => {
|
||||
const data = JSON.parse(event.data) as Events;
|
||||
|
|
|
|||
Loading…
Reference in New Issue