From fb5a063276f18e3238b13577358e811aa5f9ee31 Mon Sep 17 00:00:00 2001
From: Silas Bartha <silas@exvacuum.dev>
Date: Tue, 11 Feb 2025 19:28:40 -0500
Subject: functionality implemented

---
 src/components/player.jsx | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

(limited to 'src/components/player.jsx')

diff --git a/src/components/player.jsx b/src/components/player.jsx
index a9ddad0..f0c1e3e 100644
--- a/src/components/player.jsx
+++ b/src/components/player.jsx
@@ -11,7 +11,7 @@ const _movespeed = 3.0;
 
 export default function Player() {
     const controlsRef = useRef();
-    const { keys, setMessages } = useContext(AppContext);
+    const { keys, setMessages, apiToken } = useContext(AppContext);
     const rapier = useRapier();
     const controller = useRef();
     const collider = useRef();
@@ -31,7 +31,19 @@ export default function Player() {
         if (intersect && intersect.object.name === 'ground' && intersect.distance < 10 && controlsRef.current.isLocked) {
             const message = prompt();
             if (message) {
-                setMessages(messages => [...messages, { position: intersect.point, message: message}]);
+                let data = new FormData();
+                data.append("position", JSON.stringify(intersect.point.toArray()));
+                data.append("message", message);
+                data.append("token", apiToken.current);
+                fetch('/api/new_message', {
+                    method: "POST",
+                    body: data,
+                }).then(() => {
+                    fetch('/api/message').then((res) => res.json()).then((data) => {
+                        console.log(data);
+                        setMessages(data);
+                    });
+                });
             }
             controlsRef.current.lock();
         }
@@ -47,7 +59,7 @@ export default function Player() {
         c.setApplyImpulsesToDynamicBodies(true);
         c.setCharacterMass(0.2);
         controller.current = c;
-    }, [rapier]);
+    }, []);
 
     useFrame((_, delta) => {
         const fov_axis = +(keys.current.includes('Minus')) - +(keys.current.includes('Equal'));
@@ -95,7 +107,7 @@ export default function Player() {
 
     return (
         <RigidBody type="kinematicPosition" colliders={false} ref={rigidbody} position={[0, 2, 0]}>
-            <PerspectiveCamera makeDefault position={[0, .9, 0]} ref={camera} fov={80}/>
+            <PerspectiveCamera makeDefault position={[0, .9, 0]} ref={camera} fov={80} />
             <PointerLockControls ref={controlsRef} />
             <CapsuleCollider ref={collider} args={[1, 0.5]} />
         </RigidBody>
-- 
cgit v1.2.3

