From 3d34259e13be3ee3bc66561696e932deb7fb66bc Mon Sep 17 00:00:00 2001 From: Shotaro Nakamura <79000684+nakasyou@users.noreply.github.com> Date: Sun, 18 Jun 2023 13:22:46 +0900 Subject: [PATCH 1/7] onleydown --- islands/Room.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/islands/Room.tsx b/islands/Room.tsx index 13bf05a..13b0a85 100644 --- a/islands/Room.tsx +++ b/islands/Room.tsx @@ -91,6 +91,9 @@ export default class extends Component { { + alert(0) + }} class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" /> Date: Sun, 18 Jun 2023 13:23:55 +0900 Subject: [PATCH 2/7] e.ley --- islands/Room.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/islands/Room.tsx b/islands/Room.tsx index 13b0a85..2245dfd 100644 --- a/islands/Room.tsx +++ b/islands/Room.tsx @@ -92,7 +92,7 @@ export default class extends Component { ref={inp} placeholder="message" onKeyDown={(e)=>{ - alert(0) + alert(e.key) }} class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" /> From ccfc0e04160a081fb5d7eb728d005dd185b62103 Mon Sep 17 00:00:00 2001 From: Shotaro Nakamura <79000684+nakasyou@users.noreply.github.com> Date: Sun, 18 Jun 2023 13:28:02 +0900 Subject: [PATCH 3/7] =?UTF-8?q?=E3=82=A8=E3=83=B3=E3=82=BF=E3=83=BC?= =?UTF-8?q?=E3=81=A7=E9=80=81=E4=BF=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- islands/Room.tsx | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/islands/Room.tsx b/islands/Room.tsx index 2245dfd..014f941 100644 --- a/islands/Room.tsx +++ b/islands/Room.tsx @@ -79,7 +79,23 @@ export default class extends Component { inp.current.value += " >>" + msg + " "; } } - + const sendMessage = (): void => { + if (inp.current?.value === "") { + alert( + "送信できませんでした。 送信内容が空の可能性が有ります。" + ); + return; + } + this.state.socket.emit("message", { + body: inp.current?.value, + room: this.byProps.roomId, + uuid: crypto.randomUUID(), + }) + if (inp.current) { + // 文字の消去 + inp.current.value = "" + } + } const [isOpenMenu, setIsOpenMenu] = useState(false) return ( <> @@ -92,27 +108,16 @@ export default class extends Component { ref={inp} placeholder="message" onKeyDown={(e)=>{ - alert(e.key) + if(e.key.toLowerCase() === "enter"){ + // Enter + sendMessage() + } }} class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" /> { - if (inp.current?.value === "") { - alert( - "送信できませんでした。 送信内容が空の可能性が有ります。" - ); - return; - } - this.state.socket.emit("message", { - body: inp.current?.value, - room: this.byProps.roomId, - uuid: crypto.randomUUID(), - }) - if (inp.current) { - // 文字の消去 - inp.current.value = "" - } + sendMessage() }} class="mx-5 bg-gray-300 hover:bg-gray-400 text-gray-800 font-bold py-2 px-4 rounded inline-flex items-center" > From b2724a1300d14486a379ced876571faf1e71db6b Mon Sep 17 00:00:00 2001 From: Shotaro Nakamura <79000684+nakasyou@users.noreply.github.com> Date: Sun, 18 Jun 2023 13:30:31 +0900 Subject: [PATCH 4/7] disabled --- islands/Room.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/islands/Room.tsx b/islands/Room.tsx index 014f941..4906b4d 100644 --- a/islands/Room.tsx +++ b/islands/Room.tsx @@ -120,6 +120,7 @@ export default class extends Component { sendMessage() }} class="mx-5 bg-gray-300 hover:bg-gray-400 text-gray-800 font-bold py-2 px-4 rounded inline-flex items-center" + disabled={inp.current?.value === ""} > From eddd3523c7f06dcd7b13857866dc328c0f5bd2f2 Mon Sep 17 00:00:00 2001 From: Shotaro Nakamura <79000684+nakasyou@users.noreply.github.com> Date: Sun, 18 Jun 2023 13:33:07 +0900 Subject: [PATCH 5/7] cansubmit --- islands/Room.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/islands/Room.tsx b/islands/Room.tsx index 4906b4d..22a7547 100644 --- a/islands/Room.tsx +++ b/islands/Room.tsx @@ -96,7 +96,9 @@ export default class extends Component { inp.current.value = "" } } - const [isOpenMenu, setIsOpenMenu] = useState(false) + const [isOpenMenu, setIsOpenMenu] = useState(false) // メニューがオンか + const [canSubmit, setCanSubmit] = useState(false) // 送信可能か + return ( <> @@ -113,6 +115,9 @@ export default class extends Component { sendMessage() } }} + onInput={(e)=>{ + setCanSubmit(e.target.value !== "") + }} class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" /> From c6c3558ecffa486a57f89093d0db0083ad045538 Mon Sep 17 00:00:00 2001 From: Shotaro Nakamura <79000684+nakasyou@users.noreply.github.com> Date: Sun, 18 Jun 2023 13:38:38 +0900 Subject: [PATCH 6/7] opacity --- islands/Room.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/islands/Room.tsx b/islands/Room.tsx index 22a7547..125726d 100644 --- a/islands/Room.tsx +++ b/islands/Room.tsx @@ -79,6 +79,7 @@ export default class extends Component { inp.current.value += " >>" + msg + " "; } } + const [canSubmit, setCanSubmit] = useState(false) // 送信可能か const sendMessage = (): void => { if (inp.current?.value === "") { alert( @@ -95,9 +96,9 @@ export default class extends Component { // 文字の消去 inp.current.value = "" } + setCanSubmit(false) } const [isOpenMenu, setIsOpenMenu] = useState(false) // メニューがオンか - const [canSubmit, setCanSubmit] = useState(false) // 送信可能か return ( <> @@ -126,6 +127,9 @@ export default class extends Component { }} class="mx-5 bg-gray-300 hover:bg-gray-400 text-gray-800 font-bold py-2 px-4 rounded inline-flex items-center" disabled={!canSubmit} + style={{ + opacity: canSubmit ? 1 : 0.5 + }} > From 5f10b74ee0e18db4c715996ccf8175e7fd96d125 Mon Sep 17 00:00:00 2001 From: Shotaro Nakamura <79000684+nakasyou@users.noreply.github.com> Date: Sun, 18 Jun 2023 13:40:58 +0900 Subject: [PATCH 7/7] fix --- islands/Room.tsx | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/islands/Room.tsx b/islands/Room.tsx index 125726d..cc4b950 100644 --- a/islands/Room.tsx +++ b/islands/Room.tsx @@ -81,11 +81,8 @@ export default class extends Component { } const [canSubmit, setCanSubmit] = useState(false) // 送信可能か const sendMessage = (): void => { - if (inp.current?.value === "") { - alert( - "送信できませんでした。 送信内容が空の可能性が有ります。" - ); - return; + if(!(inp.current?.value)){ + return } this.state.socket.emit("message", { body: inp.current?.value,