SmartySmile commited on
Commit
e5aa763
·
verified ·
1 Parent(s): 66cc158

Update src/App.js

Browse files
Files changed (1) hide show
  1. src/App.js +181 -0
src/App.js CHANGED
@@ -0,0 +1,181 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import React, { useState, useRef, useEffect } from 'react';
2
+ import './App.css';
3
+
4
+ const COPYRIGHT = 'Copyright © nanoSOFT TECH 2023. Powered by nCONNECT OS.';
5
+
6
+ function App() {
7
+ const [scans, setScans] = useState({
8
+ aural: { active: false, data: 0 }, // 0-255 intensity from taps
9
+ neural: { active: false, data: 0 }, // -100 to 100 Hz from swipes
10
+ mental: { active: false, data: 0 } // 0-100% from hold duration
11
+ });
12
+ const [error, setError] = useState('');
13
+ const [isScanning, setIsScanning] = useState(false);
14
+ const scanAreaRef = useRef(null);
15
+ const touchStartTime = useRef(0);
16
+ const touchHistory = useRef([]); // For gesture tracking
17
+
18
+ // Start touch scanning mode
19
+ const startScanning = () => {
20
+ setError('');
21
+ setIsScanning(true);
22
+ setScans({
23
+ aural: { active: true, data: 0 },
24
+ neural: { active: true, data: 0 },
25
+ mental: { active: true, data: 0 }
26
+ });
27
+ setupTouchListeners();
28
+ };
29
+
30
+ // Stop scanning
31
+ const stopScanning = () => {
32
+ setIsScanning(false);
33
+ setScans({
34
+ aural: { active: false, data: 0 },
35
+ neural: { active: false, data: 0 },
36
+ mental: { active: false, data: 0 }
37
+ });
38
+ removeTouchListeners();
39
+ };
40
+
41
+ // Setup touch/pointer event listeners
42
+ const setupTouchListeners = () => {
43
+ const area = scanAreaRef.current;
44
+ if (!area) return;
45
+
46
+ const handleStart = (e) => {
47
+ e.preventDefault();
48
+ touchStartTime.current = Date.now();
49
+ touchHistory.current = [{ x: e.touches ? e.touches[0].clientX : e.clientX, y: e.touches ? e.touches[0].clientY : e.clientY, time: touchStartTime.current }];
50
+ // Mental: Start hold timer
51
+ setTimeout(() => {
52
+ if (Date.now() - touchStartTime.current > 1000) { // Long press
53
+ updateMentalSense(50 + (Date.now() - touchStartTime.current) / 100); // Simulate focus build-up
54
+ }
55
+ }, 1000);
56
+ };
57
+
58
+ const handleMove = (e) => {
59
+ e.preventDefault();
60
+ if (touchHistory.current.length > 0) {
61
+ const currentTouch = e.touches ? e.touches[0] : e;
62
+ const lastTouch = touchHistory.current[touchHistory.current.length - 1];
63
+ const deltaX = currentTouch.clientX - lastTouch.x;
64
+ const deltaY = currentTouch.clientY - lastTouch.y;
65
+ const deltaTime = Date.now() - lastTouch.time;
66
+ const speed = Math.sqrt(deltaX * deltaX + deltaY * deltaY) / (deltaTime / 1000); // Pixels per second
67
+
68
+ // Neural: Swipe speed to frequency
69
+ const frequency = Math.max(-100, Math.min(100, (speed - 50) * 2)); // Map speed to Hz
70
+ setScans(prev => ({ ...prev, neural: { ...prev.neural, data: frequency } }));
71
+
72
+ touchHistory.current.push({ x: currentTouch.clientX, y: currentTouch.clientY, time: Date.now() });
73
+ }
74
+ };
75
+
76
+ const handleEnd = (e) => {
77
+ e.preventDefault();
78
+ const duration = Date.now() - touchStartTime.current;
79
+ const touchCount = e.changedTouches ? e.changedTouches.length : 1;
80
+
81
+ // Aural: Tap frequency/intensity from duration and count
82
+ const intensity = Math.min(255, touchCount * 50 + (duration < 200 ? 100 : 0)); // Short taps = high intensity
83
+ setScans(prev => ({ ...prev, aural: { ...prev.aural, data: intensity } }));
84
+
85
+ // Mental: Hold duration to focus %
86
+ const focus = Math.min(100, duration / 10); // 10s max for 100%
87
+ setScans(prev => ({ ...prev, mental: { ...prev.mental, data: focus } }));
88
+
89
+ // Reset history
90
+ touchHistory.current = [];
91
+ };
92
+
93
+ // Touch events (mobile)
94
+ area.addEventListener('touchstart', handleStart, { passive: false });
95
+ area.addEventListener('touchmove', handleMove, { passive: false });
96
+ area.addEventListener('touchend', handleEnd, { passive: false });
97
+
98
+ // Pointer events (desktop/mouse fallback)
99
+ area.addEventListener('pointerdown', handleStart);
100
+ area.addEventListener('pointermove', handleMove);
101
+ area.addEventListener('pointerup', handleEnd);
102
+
103
+ // Store refs for cleanup
104
+ area._listeners = { touchstart: handleStart, touchmove: handleMove, touchend: handleEnd, pointerdown: handleStart, pointermove: handleMove, pointerup: handleEnd };
105
+ };
106
+
107
+ // Remove listeners
108
+ const removeTouchListeners = () => {
109
+ const area = scanAreaRef.current;
110
+ if (!area || !area._listeners) return;
111
+
112
+ Object.entries(area._listeners).forEach(([event, handler]) => {
113
+ area.removeEventListener(event, handler);
114
+ });
115
+ delete area._listeners;
116
+ };
117
+
118
+ // Cleanup on unmount
119
+ useEffect(() => {
120
+ return () => {
121
+ if (isScanning) {
122
+ stopScanning();
123
+ }
124
+ };
125
+ }, []);
126
+
127
+ return (
128
+ <div className="App">
129
+ <header className="App-header">
130
+ <h1>nCONNECT OS Touch Sensory Scanner</h1>
131
+ <p>Scan aural, neural, and mental senses using touch screen interactions.</p>
132
+ <p><em>Interact in the Scan Area: Tap for aural, swipe for neural, hold for mental.</em></p>
133
+
134
+ {!isScanning ? (
135
+ <button onClick={startScanning} disabled={!('ontouchstart' in window || 'onpointerdown' in window)}>
136
+ Start Touch Scan
137
+ </button>
138
+ ) : (
139
+ <div>
140
+ <p>Scanning Active - Touch the area below!</p>
141
+ <button onClick={stopScanning}>Stop Scan</button>
142
+ </div>
143
+ )}
144
+
145
+ {error && <p className="error">{error}</p>}
146
+
147
+ <div className="scans">
148
+ <div className="scan-card">
149
+ <h2>Aural Sense Scan</h2>
150
+ <p>Status: {scans.aural.active ? 'Active' : 'Inactive'}</p>
151
+ <p>Data: {scans.aural.data} (Tap Intensity)</p>
152
+ </div>
153
+
154
+ <div className="scan-card">
155
+ <h2>Neural Sense Scan</h2>
156
+ <p>Status: {scans.neural.active ? 'Active' : 'Inactive'}</p>
157
+ <p>Data: {scans.neural.data.toFixed(2)} Hz (Swipe Frequency)</p>
158
+ </div>
159
+
160
+ <div className="scan-card">
161
+ <h2>Mental Sense Scan</h2>
162
+ <p>Status: {scans.mental.active ? 'Active' : 'Inactive'}</p>
163
+ <p>Data: {scans.mental.data.toFixed(0)}% (Hold Focus)</p>
164
+ </div>
165
+ </div>
166
+
167
+ <div
168
+ ref={scanAreaRef}
169
+ className={`scan-area ${isScanning ? 'active' : ''}`}
170
+ >
171
+ <p>Touch Here to Scan</p>
172
+ {isScanning && <p>🖐️ Tap, Swipe, or Hold</p>}
173
+ </div>
174
+
175
+ <footer>{COPYRIGHT}</footer>
176
+ </header>
177
+ </div>
178
+ );
179
+ }
180
+
181
+ export default App;