refactor: chat state
This commit is contained in:
parent
1e0d5d0b95
commit
b9428658b5
|
@ -8,7 +8,6 @@ export default function Chat({
|
||||||
chatHistoryCaret,
|
chatHistoryCaret,
|
||||||
chatInputRef,
|
chatInputRef,
|
||||||
chatMessages,
|
chatMessages,
|
||||||
onClose,
|
|
||||||
message,
|
message,
|
||||||
pendingMessage,
|
pendingMessage,
|
||||||
setChatHistoryCaret,
|
setChatHistoryCaret,
|
||||||
|
@ -33,7 +32,6 @@ export default function Chat({
|
||||||
<Input
|
<Input
|
||||||
chatHistory={chatHistory}
|
chatHistory={chatHistory}
|
||||||
chatHistoryCaret={chatHistoryCaret}
|
chatHistoryCaret={chatHistoryCaret}
|
||||||
onClose={onClose}
|
|
||||||
message={message}
|
message={message}
|
||||||
chatInputRef={chatInputRef}
|
chatInputRef={chatInputRef}
|
||||||
pendingMessage={pendingMessage}
|
pendingMessage={pendingMessage}
|
||||||
|
|
|
@ -99,8 +99,6 @@ function Ui({disconnected}) {
|
||||||
return addKeyListener(document.body, ({type, payload}) => {
|
return addKeyListener(document.body, ({type, payload}) => {
|
||||||
if (chatInputRef.current) {
|
if (chatInputRef.current) {
|
||||||
chatInputRef.current.focus();
|
chatInputRef.current.focus();
|
||||||
}
|
|
||||||
if (chatIsOpen) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let actionPayload;
|
let actionPayload;
|
||||||
|
@ -130,7 +128,6 @@ function Ui({disconnected}) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, [
|
}, [
|
||||||
chatIsOpen,
|
|
||||||
client,
|
client,
|
||||||
]);
|
]);
|
||||||
const keepHotbarOpen = useCallback(() => {
|
const keepHotbarOpen = useCallback(() => {
|
||||||
|
@ -146,14 +143,12 @@ function Ui({disconnected}) {
|
||||||
}, [hotbarHideHandle, isInventoryOpen]);
|
}, [hotbarHideHandle, isInventoryOpen]);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
return addKeyListener(document.body, ({event, type, payload}) => {
|
return addKeyListener(document.body, ({event, type, payload}) => {
|
||||||
if ('Escape' === payload && 'keyDown' === type && chatIsOpen) {
|
if ('Escape' === payload && 'keyDown' === type && chatInputRef.current) {
|
||||||
setChatIsOpen(false);
|
setChatIsOpen(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (chatInputRef.current) {
|
if (chatInputRef.current) {
|
||||||
chatInputRef.current.focus();
|
chatInputRef.current.focus();
|
||||||
}
|
|
||||||
if (chatIsOpen) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let actionPayload;
|
let actionPayload;
|
||||||
|
@ -300,7 +295,6 @@ function Ui({disconnected}) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, [
|
}, [
|
||||||
chatIsOpen,
|
|
||||||
client,
|
client,
|
||||||
devtoolsIsOpen,
|
devtoolsIsOpen,
|
||||||
hotbarHideHandle,
|
hotbarHideHandle,
|
||||||
|
@ -477,7 +471,7 @@ function Ui({disconnected}) {
|
||||||
<div
|
<div
|
||||||
className={[styles.game, devtoolsIsOpen && styles.devtoolsIsOpen].filter(Boolean).join(' ')}
|
className={[styles.game, devtoolsIsOpen && styles.devtoolsIsOpen].filter(Boolean).join(' ')}
|
||||||
onMouseDown={(event) => {
|
onMouseDown={(event) => {
|
||||||
if (chatIsOpen) {
|
if (chatInputRef.current) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -510,7 +504,7 @@ function Ui({disconnected}) {
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
onMouseUp={(event) => {
|
onMouseUp={(event) => {
|
||||||
if (chatIsOpen) {
|
if (chatInputRef.current) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -532,7 +526,7 @@ function Ui({disconnected}) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}}
|
}}
|
||||||
onWheel={(event) => {
|
onWheel={(event) => {
|
||||||
if (chatIsOpen) {
|
if (chatInputRef.current) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -619,9 +613,6 @@ function Ui({disconnected}) {
|
||||||
setChatHistoryCaret={setChatHistoryCaret}
|
setChatHistoryCaret={setChatHistoryCaret}
|
||||||
setMessage={setMessage}
|
setMessage={setMessage}
|
||||||
setPendingMessage={setPendingMessage}
|
setPendingMessage={setPendingMessage}
|
||||||
onClose={() => {
|
|
||||||
setChatIsOpen(false);
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{showDisconnected && (
|
{showDisconnected && (
|
||||||
|
|
Loading…
Reference in New Issue
Block a user