Skip to content

Commit 749b6fb

Browse files
authored
Frontend cursor movement (#187)
* restyled most components for better visuals * added light and dark mode functionality for some components * added mobile responsive layout for smaller screens and removed redundant props * added ScrollView in replacement of regular div to remove unecessary horizontal bar * added animations for smoother light and dark mode transitions * removed border from buttons and added shadow instead * made score display on mobile reponsive with horizontal scrolling and removed the scroll bar indicators * adjusted header and footer styles to stick on top / bottom when scrolling happens * cleaned up code structure and removed themestyles * adjusted small screen breakpoint to include landscape mode devices * added function to generate and store session token on load within the frontend alone * replaced logic used to display score sheet from app.py to score.ts * added basic cursor movement logic based on step and speed input * removed node modules from being tracked * updated comments and formatted code
1 parent f42bc44 commit 749b6fb

File tree

5 files changed

+7509
-139
lines changed

5 files changed

+7509
-139
lines changed

frontend/companion-app/App.tsx

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,19 @@ export default function App() {
4646
scores: [] // the list of scores to choose from
4747
},
4848
);
49+
50+
// State used to store session token
51+
const [sessionToken, setSessionToken] = useState<string>("")
52+
53+
// Function used to generate session token using crypto API
54+
const generateSecureSessionToken = (): string => {
55+
return window.crypto.randomUUID();
56+
};
4957

50-
// Sync sessionToken with useReducer state
51-
// Fetch the session token and dispatch it to the reducer
58+
// On load, call generateSecureSessionToken function to generate and store new session token
5259
useEffect(() => {
53-
const fetchSessionToken = async () => {
54-
try {
55-
const data = await startSession();
56-
const token = data.session_token;
57-
console.log("Fetched session token:", token);
58-
dispatch({ type: "new_session", token: token });
59-
} catch (error) {
60-
console.error("Error fetching session token:", error);
61-
}
62-
};
63-
64-
fetchSessionToken();
60+
const newToken: string = generateSecureSessionToken();
61+
setSessionToken(newToken)
6562
}, []);
6663

6764
////////////////////////////////////////////////////////////////////////////////
@@ -229,12 +226,6 @@ export default function App() {
229226
inputRange: [0, 1],
230227
outputRange: ["#2C3E50", "#FFFFFF"], // Light to dark transition
231228
});
232-
// Interpolate border bottom color based on light or dark mode
233-
// const borderColor = borderColorAnim.interpolate({
234-
// inputRange: [0, 1],
235-
// outputRange: ["#FFFFFF", "#2C3E50"], // Light to dark transition
236-
// })
237-
238229

239230
// Toggles between light and dark mode by animating background, text, and border properties smoothly
240231
const toggleTheme = () => {
@@ -255,19 +246,14 @@ export default function App() {
255246
duration: 500,
256247
useNativeDriver: false, // Can't use native driver for border properties
257248
}),
258-
// Animated.timing(borderColorAnim, {
259-
// toValue,
260-
// duration: 500,
261-
// useNativeDriver: false, // Can't use native driver for border properties
262-
// }),
263249
]).start(() => {
264250
setTheme(theme === "light" ? "dark" : "light");
265251
});
266252
};
267253
// Get device's width
268254
const { width } = useWindowDimensions()
269255
// Boolean used for dynmaic display (row or column)
270-
const isSmallScreen = width < 768;
256+
const isSmallScreen = width < 960;
271257

272258

273259
////////////////////////////////////////////////////////////////////////////////
@@ -276,10 +262,10 @@ export default function App() {
276262
return (
277263
<SafeAreaView style={[styles.container]}>
278264
{/* Header with image */}
279-
<Animated.View style={[styles.menu_bar, {backgroundColor: menubarBackgroundColor}]}>
280-
<Image source={{ uri: './assets/companion.png' }} style={styles.logo}/>
265+
<Animated.View style={[styles.menu_bar, {backgroundColor: menubarBackgroundColor, height: isSmallScreen? 40: 80}]}>
266+
<Image source={require('./assets/companion.png')} style={[styles.logo, {height: isSmallScreen? 30: 100, width: isSmallScreen? 100: 200}]}/>
281267
<TouchableOpacity onPress={toggleTheme}>
282-
<Icon name={theme === 'light' ? 'sun' : 'moon'} size={30} color="white" />
268+
<Icon name={theme === 'light' ? 'sun' : 'moon'} size={isSmallScreen? 15: 30} color="white" />
283269
</TouchableOpacity>
284270

285271
</Animated.View>
@@ -392,15 +378,14 @@ const styles = StyleSheet.create({
392378
padding: 10,
393379
borderBottomWidth: 2,
394380
borderBottomColor: "#1A252F",
395-
height: 80,
381+
height: 80,
396382
position: "absolute", // make header stick on top even after scroll
397383
top: 0,
398384
width: "100%",
399385
zIndex: 99
400386
},
401387
// Image for header
402388
logo: {
403-
height: 200,
404389
width: 200,
405390
resizeMode: "contain",
406391
},
@@ -481,4 +466,4 @@ const styles = StyleSheet.create({
481466
color: "#FFFFFF",
482467
fontWeight: "bold",
483468
},
484-
});
469+
});

0 commit comments

Comments
 (0)