refactor: chat state

This commit is contained in:
cha0s 2024-09-12 14:31:05 -05:00
parent 1e0d5d0b95
commit b9428658b5
2 changed files with 4 additions and 15 deletions

View File

@ -8,7 +8,6 @@ export default function Chat({
chatHistoryCaret,
chatInputRef,
chatMessages,
onClose,
message,
pendingMessage,
setChatHistoryCaret,
@ -33,7 +32,6 @@ export default function Chat({
<Input
chatHistory={chatHistory}
chatHistoryCaret={chatHistoryCaret}
onClose={onClose}
message={message}
chatInputRef={chatInputRef}
pendingMessage={pendingMessage}

View File

@ -99,8 +99,6 @@ function Ui({disconnected}) {
return addKeyListener(document.body, ({type, payload}) => {
if (chatInputRef.current) {
chatInputRef.current.focus();
}
if (chatIsOpen) {
return;
}
let actionPayload;
@ -130,7 +128,6 @@ function Ui({disconnected}) {
}
});
}, [
chatIsOpen,
client,
]);
const keepHotbarOpen = useCallback(() => {
@ -146,14 +143,12 @@ function Ui({disconnected}) {
}, [hotbarHideHandle, isInventoryOpen]);
useEffect(() => {
return addKeyListener(document.body, ({event, type, payload}) => {
if ('Escape' === payload && 'keyDown' === type && chatIsOpen) {
if ('Escape' === payload && 'keyDown' === type && chatInputRef.current) {
setChatIsOpen(false);
return;
}
if (chatInputRef.current) {
chatInputRef.current.focus();
}
if (chatIsOpen) {
return;
}
let actionPayload;
@ -300,7 +295,6 @@ function Ui({disconnected}) {
}
});
}, [
chatIsOpen,
client,
devtoolsIsOpen,
hotbarHideHandle,
@ -477,7 +471,7 @@ function Ui({disconnected}) {
<div
className={[styles.game, devtoolsIsOpen && styles.devtoolsIsOpen].filter(Boolean).join(' ')}
onMouseDown={(event) => {
if (chatIsOpen) {
if (chatInputRef.current) {
event.preventDefault();
return;
}
@ -510,7 +504,7 @@ function Ui({disconnected}) {
}
}}
onMouseUp={(event) => {
if (chatIsOpen) {
if (chatInputRef.current) {
event.preventDefault();
return;
}
@ -532,7 +526,7 @@ function Ui({disconnected}) {
event.preventDefault();
}}
onWheel={(event) => {
if (chatIsOpen) {
if (chatInputRef.current) {
event.preventDefault();
return;
}
@ -619,9 +613,6 @@ function Ui({disconnected}) {
setChatHistoryCaret={setChatHistoryCaret}
setMessage={setMessage}
setPendingMessage={setPendingMessage}
onClose={() => {
setChatIsOpen(false);
}}
/>
)}
{showDisconnected && (