misc: init
This commit is contained in:
@@ -1,35 +1,45 @@
|
||||
import { Tabs } from 'expo-router';
|
||||
import React from 'react';
|
||||
import React from "react";
|
||||
import { Ionicons } from "@expo/vector-icons";
|
||||
import { useRouter } from "expo-router";
|
||||
import { View, TouchableOpacity, StyleSheet } from "react-native";
|
||||
import { NativeTabs, Icon, Label } from "expo-router/unstable-native-tabs";
|
||||
|
||||
import { HapticTab } from '@/components/haptic-tab';
|
||||
import { IconSymbol } from '@/components/ui/icon-symbol';
|
||||
import { Colors } from '@/constants/theme';
|
||||
import { useColorScheme } from '@/hooks/use-color-scheme';
|
||||
export function DevicesHeader() {
|
||||
const router = useRouter();
|
||||
|
||||
export default function TabLayout() {
|
||||
const colorScheme = useColorScheme();
|
||||
|
||||
return (
|
||||
<Tabs
|
||||
screenOptions={{
|
||||
tabBarActiveTintColor: Colors[colorScheme ?? 'light'].tint,
|
||||
headerShown: false,
|
||||
tabBarButton: HapticTab,
|
||||
}}>
|
||||
<Tabs.Screen
|
||||
name="index"
|
||||
options={{
|
||||
title: 'Home',
|
||||
tabBarIcon: ({ color }) => <IconSymbol size={28} name="house.fill" color={color} />,
|
||||
}}
|
||||
/>
|
||||
<Tabs.Screen
|
||||
name="explore"
|
||||
options={{
|
||||
title: 'Explore',
|
||||
tabBarIcon: ({ color }) => <IconSymbol size={28} name="paperplane.fill" color={color} />,
|
||||
}}
|
||||
/>
|
||||
</Tabs>
|
||||
);
|
||||
return (
|
||||
<View style={styles.headerRight}>
|
||||
<TouchableOpacity
|
||||
onPress={() => router.push("/scan-devices")}
|
||||
style={styles.headerButton}
|
||||
>
|
||||
<Ionicons name="add-circle-outline" size={24} color="#007AFF" />
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
export default function TabsLayout() {
|
||||
return (
|
||||
<NativeTabs>
|
||||
<NativeTabs.Trigger name="index">
|
||||
<Icon sf="desktopcomputer"/>
|
||||
<Label>Devices</Label>
|
||||
</NativeTabs.Trigger>
|
||||
<NativeTabs.Trigger name="settings">
|
||||
<Icon sf="gear"/>
|
||||
<Label>Settings</Label>
|
||||
</NativeTabs.Trigger>
|
||||
</NativeTabs>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
headerRight: {
|
||||
flexDirection: "row",
|
||||
gap: 16,
|
||||
},
|
||||
headerButton: {
|
||||
paddingHorizontal: 8,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,112 +0,0 @@
|
||||
import { Image } from 'expo-image';
|
||||
import { Platform, StyleSheet } from 'react-native';
|
||||
|
||||
import { Collapsible } from '@/components/ui/collapsible';
|
||||
import { ExternalLink } from '@/components/external-link';
|
||||
import ParallaxScrollView from '@/components/parallax-scroll-view';
|
||||
import { ThemedText } from '@/components/themed-text';
|
||||
import { ThemedView } from '@/components/themed-view';
|
||||
import { IconSymbol } from '@/components/ui/icon-symbol';
|
||||
import { Fonts } from '@/constants/theme';
|
||||
|
||||
export default function TabTwoScreen() {
|
||||
return (
|
||||
<ParallaxScrollView
|
||||
headerBackgroundColor={{ light: '#D0D0D0', dark: '#353636' }}
|
||||
headerImage={
|
||||
<IconSymbol
|
||||
size={310}
|
||||
color="#808080"
|
||||
name="chevron.left.forwardslash.chevron.right"
|
||||
style={styles.headerImage}
|
||||
/>
|
||||
}>
|
||||
<ThemedView style={styles.titleContainer}>
|
||||
<ThemedText
|
||||
type="title"
|
||||
style={{
|
||||
fontFamily: Fonts.rounded,
|
||||
}}>
|
||||
Explore
|
||||
</ThemedText>
|
||||
</ThemedView>
|
||||
<ThemedText>This app includes example code to help you get started.</ThemedText>
|
||||
<Collapsible title="File-based routing">
|
||||
<ThemedText>
|
||||
This app has two screens:{' '}
|
||||
<ThemedText type="defaultSemiBold">app/(tabs)/index.tsx</ThemedText> and{' '}
|
||||
<ThemedText type="defaultSemiBold">app/(tabs)/explore.tsx</ThemedText>
|
||||
</ThemedText>
|
||||
<ThemedText>
|
||||
The layout file in <ThemedText type="defaultSemiBold">app/(tabs)/_layout.tsx</ThemedText>{' '}
|
||||
sets up the tab navigator.
|
||||
</ThemedText>
|
||||
<ExternalLink href="https://docs.expo.dev/router/introduction">
|
||||
<ThemedText type="link">Learn more</ThemedText>
|
||||
</ExternalLink>
|
||||
</Collapsible>
|
||||
<Collapsible title="Android, iOS, and web support">
|
||||
<ThemedText>
|
||||
You can open this project on Android, iOS, and the web. To open the web version, press{' '}
|
||||
<ThemedText type="defaultSemiBold">w</ThemedText> in the terminal running this project.
|
||||
</ThemedText>
|
||||
</Collapsible>
|
||||
<Collapsible title="Images">
|
||||
<ThemedText>
|
||||
For static images, you can use the <ThemedText type="defaultSemiBold">@2x</ThemedText> and{' '}
|
||||
<ThemedText type="defaultSemiBold">@3x</ThemedText> suffixes to provide files for
|
||||
different screen densities
|
||||
</ThemedText>
|
||||
<Image
|
||||
source={require('@/assets/images/react-logo.png')}
|
||||
style={{ width: 100, height: 100, alignSelf: 'center' }}
|
||||
/>
|
||||
<ExternalLink href="https://reactnative.dev/docs/images">
|
||||
<ThemedText type="link">Learn more</ThemedText>
|
||||
</ExternalLink>
|
||||
</Collapsible>
|
||||
<Collapsible title="Light and dark mode components">
|
||||
<ThemedText>
|
||||
This template has light and dark mode support. The{' '}
|
||||
<ThemedText type="defaultSemiBold">useColorScheme()</ThemedText> hook lets you inspect
|
||||
what the user's current color scheme is, and so you can adjust UI colors accordingly.
|
||||
</ThemedText>
|
||||
<ExternalLink href="https://docs.expo.dev/develop/user-interface/color-themes/">
|
||||
<ThemedText type="link">Learn more</ThemedText>
|
||||
</ExternalLink>
|
||||
</Collapsible>
|
||||
<Collapsible title="Animations">
|
||||
<ThemedText>
|
||||
This template includes an example of an animated component. The{' '}
|
||||
<ThemedText type="defaultSemiBold">components/HelloWave.tsx</ThemedText> component uses
|
||||
the powerful{' '}
|
||||
<ThemedText type="defaultSemiBold" style={{ fontFamily: Fonts.mono }}>
|
||||
react-native-reanimated
|
||||
</ThemedText>{' '}
|
||||
library to create a waving hand animation.
|
||||
</ThemedText>
|
||||
{Platform.select({
|
||||
ios: (
|
||||
<ThemedText>
|
||||
The <ThemedText type="defaultSemiBold">components/ParallaxScrollView.tsx</ThemedText>{' '}
|
||||
component provides a parallax effect for the header image.
|
||||
</ThemedText>
|
||||
),
|
||||
})}
|
||||
</Collapsible>
|
||||
</ParallaxScrollView>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
headerImage: {
|
||||
color: '#808080',
|
||||
bottom: -90,
|
||||
left: -35,
|
||||
position: 'absolute',
|
||||
},
|
||||
titleContainer: {
|
||||
flexDirection: 'row',
|
||||
gap: 8,
|
||||
},
|
||||
});
|
||||
@@ -1,98 +1,346 @@
|
||||
import { Image } from 'expo-image';
|
||||
import { Platform, StyleSheet } from 'react-native';
|
||||
import React, { useState, useEffect } from "react";
|
||||
import {
|
||||
View,
|
||||
Text,
|
||||
FlatList,
|
||||
TouchableOpacity,
|
||||
StyleSheet,
|
||||
RefreshControl,
|
||||
Alert,
|
||||
ActivityIndicator,
|
||||
} from "react-native";
|
||||
import { ContextMenu, Button as SwiftUIButton, Host } from "@expo/ui/swift-ui";
|
||||
import { useRouter, useLocalSearchParams, Stack } from "expo-router";
|
||||
import { Ionicons } from "@expo/vector-icons";
|
||||
import api from "../../src/services/api";
|
||||
import { Device } from "../../src/types";
|
||||
|
||||
import { HelloWave } from '@/components/hello-wave';
|
||||
import ParallaxScrollView from '@/components/parallax-scroll-view';
|
||||
import { ThemedText } from '@/components/themed-text';
|
||||
import { ThemedView } from '@/components/themed-view';
|
||||
import { Link } from 'expo-router';
|
||||
function DevicesHeader() {
|
||||
const router = useRouter();
|
||||
|
||||
export default function HomeScreen() {
|
||||
return (
|
||||
<ParallaxScrollView
|
||||
headerBackgroundColor={{ light: '#A1CEDC', dark: '#1D3D47' }}
|
||||
headerImage={
|
||||
<Image
|
||||
source={require('@/assets/images/partial-react-logo.png')}
|
||||
style={styles.reactLogo}
|
||||
/>
|
||||
}>
|
||||
<ThemedView style={styles.titleContainer}>
|
||||
<ThemedText type="title">Welcome!</ThemedText>
|
||||
<HelloWave />
|
||||
</ThemedView>
|
||||
<ThemedView style={styles.stepContainer}>
|
||||
<ThemedText type="subtitle">Step 1: Try it</ThemedText>
|
||||
<ThemedText>
|
||||
Edit <ThemedText type="defaultSemiBold">app/(tabs)/index.tsx</ThemedText> to see changes.
|
||||
Press{' '}
|
||||
<ThemedText type="defaultSemiBold">
|
||||
{Platform.select({
|
||||
ios: 'cmd + d',
|
||||
android: 'cmd + m',
|
||||
web: 'F12',
|
||||
})}
|
||||
</ThemedText>{' '}
|
||||
to open developer tools.
|
||||
</ThemedText>
|
||||
</ThemedView>
|
||||
<ThemedView style={styles.stepContainer}>
|
||||
<Link href="/modal">
|
||||
<Link.Trigger>
|
||||
<ThemedText type="subtitle">Step 2: Explore</ThemedText>
|
||||
</Link.Trigger>
|
||||
<Link.Preview />
|
||||
<Link.Menu>
|
||||
<Link.MenuAction title="Action" icon="cube" onPress={() => alert('Action pressed')} />
|
||||
<Link.MenuAction
|
||||
title="Share"
|
||||
icon="square.and.arrow.up"
|
||||
onPress={() => alert('Share pressed')}
|
||||
/>
|
||||
<Link.Menu title="More" icon="ellipsis">
|
||||
<Link.MenuAction
|
||||
title="Delete"
|
||||
icon="trash"
|
||||
destructive
|
||||
onPress={() => alert('Delete pressed')}
|
||||
/>
|
||||
</Link.Menu>
|
||||
</Link.Menu>
|
||||
</Link>
|
||||
return (
|
||||
<View>
|
||||
<TouchableOpacity onPress={() => router.push("/scan-devices")}>
|
||||
<Ionicons name="add-circle-outline" size={24} color="#007AFF" />
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
<ThemedText>
|
||||
{`Tap the Explore tab to learn more about what's included in this starter app.`}
|
||||
</ThemedText>
|
||||
</ThemedView>
|
||||
<ThemedView style={styles.stepContainer}>
|
||||
<ThemedText type="subtitle">Step 3: Get a fresh start</ThemedText>
|
||||
<ThemedText>
|
||||
{`When you're ready, run `}
|
||||
<ThemedText type="defaultSemiBold">npm run reset-project</ThemedText> to get a fresh{' '}
|
||||
<ThemedText type="defaultSemiBold">app</ThemedText> directory. This will move the current{' '}
|
||||
<ThemedText type="defaultSemiBold">app</ThemedText> to{' '}
|
||||
<ThemedText type="defaultSemiBold">app-example</ThemedText>.
|
||||
</ThemedText>
|
||||
</ThemedView>
|
||||
</ParallaxScrollView>
|
||||
);
|
||||
export default function DeviceListScreen() {
|
||||
const router = useRouter();
|
||||
const [devices, setDevices] = useState<Device[]>([]);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [refreshing, setRefreshing] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
loadDevices();
|
||||
}, []);
|
||||
|
||||
const loadDevices = async () => {
|
||||
try {
|
||||
setIsLoading(true);
|
||||
const data = await api.getDevices();
|
||||
setDevices(data);
|
||||
} catch (error: any) {
|
||||
Alert.alert("Error", error.message || "Failed to load devices");
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const onRefresh = async () => {
|
||||
setRefreshing(true);
|
||||
await loadDevices();
|
||||
setRefreshing(false);
|
||||
};
|
||||
|
||||
const handleWake = async (device: Device) => {
|
||||
try {
|
||||
await api.wakeDevice(device.id);
|
||||
Alert.alert("Success", `Wake signal sent to ${device.name}`);
|
||||
} catch (error: any) {
|
||||
Alert.alert("Error", error.message || "Failed to wake device");
|
||||
}
|
||||
};
|
||||
|
||||
const handleSleep = async (device: Device) => {
|
||||
Alert.alert("Confirm", `Send ${device.name} to sleep?`, [
|
||||
{ text: "Cancel", style: "cancel" },
|
||||
{
|
||||
text: "Sleep",
|
||||
style: "destructive",
|
||||
onPress: async () => {
|
||||
try {
|
||||
await api.sleepDevice(device.id);
|
||||
Alert.alert("Success", `Sleep signal sent to ${device.name}`);
|
||||
} catch (error: any) {
|
||||
Alert.alert("Error", error.message || "Failed to sleep device");
|
||||
}
|
||||
},
|
||||
},
|
||||
]);
|
||||
};
|
||||
|
||||
const handleReboot = async (device: Device) => {
|
||||
Alert.alert("Confirm", `Reboot ${device.name}?`, [
|
||||
{ text: "Cancel", style: "cancel" },
|
||||
{
|
||||
text: "Reboot",
|
||||
style: "destructive",
|
||||
onPress: async () => {
|
||||
try {
|
||||
await api.rebootDevice(device.id);
|
||||
Alert.alert("Success", `Reboot signal sent to ${device.name}`);
|
||||
} catch (error: any) {
|
||||
Alert.alert("Error", error.message || "Failed to reboot device");
|
||||
}
|
||||
},
|
||||
},
|
||||
]);
|
||||
};
|
||||
|
||||
const handleShutdown = async (device: Device) => {
|
||||
Alert.alert(
|
||||
"Confirm Shutdown",
|
||||
`Shutdown ${device.name}? This cannot be undone.`,
|
||||
[
|
||||
{ text: "Cancel", style: "cancel" },
|
||||
{
|
||||
text: "Shutdown",
|
||||
style: "destructive",
|
||||
onPress: async () => {
|
||||
try {
|
||||
await api.shutdownDevice(device.id);
|
||||
Alert.alert("Success", `Shutdown signal sent to ${device.name}`);
|
||||
} catch (error: any) {
|
||||
Alert.alert(
|
||||
"Error",
|
||||
error.message || "Failed to shutdown device"
|
||||
);
|
||||
}
|
||||
},
|
||||
},
|
||||
]
|
||||
);
|
||||
};
|
||||
|
||||
const handleDelete = (device: Device) => {
|
||||
Alert.alert("Delete Device", `Delete "${device.name}"?`, [
|
||||
{
|
||||
text: "Delete",
|
||||
style: "destructive",
|
||||
onPress: async () => {
|
||||
try {
|
||||
await api.deleteDevice(device.id);
|
||||
Alert.alert("Success", "Device deleted successfully");
|
||||
loadDevices();
|
||||
} catch (error: any) {
|
||||
Alert.alert("Error", error.message || "Failed to delete device");
|
||||
}
|
||||
},
|
||||
},
|
||||
]);
|
||||
};
|
||||
|
||||
const getStatusColor = (status: string) => {
|
||||
switch (status?.toLowerCase()) {
|
||||
case "online":
|
||||
return "#4CAF50";
|
||||
case "offline":
|
||||
return "#f44336";
|
||||
default:
|
||||
return "#ff9800";
|
||||
}
|
||||
};
|
||||
|
||||
const renderDevice = ({ item }: { item: Device }) => (
|
||||
<Host>
|
||||
<ContextMenu activationMethod="longPress">
|
||||
<ContextMenu.Items>
|
||||
<SwiftUIButton
|
||||
systemImage="trash"
|
||||
role="destructive"
|
||||
onPress={() => handleDelete(item)}
|
||||
>
|
||||
Delete Device
|
||||
</SwiftUIButton>
|
||||
</ContextMenu.Items>
|
||||
<ContextMenu.Trigger>
|
||||
<View style={styles.deviceCard}>
|
||||
<TouchableOpacity
|
||||
onPress={() => router.push(`/devices/${item.id}`)}
|
||||
activeOpacity={1}
|
||||
>
|
||||
<View style={styles.deviceHeader}>
|
||||
<View style={styles.deviceInfo}>
|
||||
<Text style={styles.deviceName}>{item.name}</Text>
|
||||
<Text style={styles.deviceIP}>{item.ip}</Text>
|
||||
</View>
|
||||
<View
|
||||
style={[
|
||||
styles.statusDot,
|
||||
{ backgroundColor: getStatusColor(item.status) },
|
||||
]}
|
||||
/>
|
||||
</View>
|
||||
|
||||
<View style={styles.deviceActions}>
|
||||
<TouchableOpacity
|
||||
style={[styles.actionButton, styles.wakeButton]}
|
||||
onPress={() => handleWake(item)}
|
||||
>
|
||||
<Text style={styles.actionButtonText}>Wake</Text>
|
||||
</TouchableOpacity>
|
||||
<TouchableOpacity
|
||||
style={[styles.actionButton, styles.sleepButton]}
|
||||
onPress={() => handleSleep(item)}
|
||||
>
|
||||
<Text style={styles.actionButtonText}>Sleep</Text>
|
||||
</TouchableOpacity>
|
||||
<TouchableOpacity
|
||||
style={[styles.actionButton, styles.rebootButton]}
|
||||
onPress={() => handleReboot(item)}
|
||||
>
|
||||
<Text style={styles.actionButtonText}>Reboot</Text>
|
||||
</TouchableOpacity>
|
||||
<TouchableOpacity
|
||||
style={[styles.actionButton, styles.shutdownButton]}
|
||||
onPress={() => handleShutdown(item)}
|
||||
>
|
||||
<Text style={styles.actionButtonText}>Shutdown</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
</ContextMenu.Trigger>
|
||||
</ContextMenu>
|
||||
</Host>
|
||||
);
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<View style={styles.loadingContainer}>
|
||||
<ActivityIndicator size="large" color="#007AFF" />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
<Stack.Screen
|
||||
options={{
|
||||
title: "Devices",
|
||||
headerRight: () => <DevicesHeader />,
|
||||
}}
|
||||
/>
|
||||
<FlatList
|
||||
data={devices}
|
||||
renderItem={renderDevice}
|
||||
keyExtractor={(item) => item.id}
|
||||
contentContainerStyle={styles.list}
|
||||
refreshControl={
|
||||
<RefreshControl refreshing={refreshing} onRefresh={onRefresh} />
|
||||
}
|
||||
ListEmptyComponent={
|
||||
<View style={styles.emptyContainer}>
|
||||
<Text style={styles.emptyText}>No devices found</Text>
|
||||
</View>
|
||||
}
|
||||
/>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
titleContainer: {
|
||||
flexDirection: 'row',
|
||||
alignItems: 'center',
|
||||
gap: 8,
|
||||
},
|
||||
stepContainer: {
|
||||
gap: 8,
|
||||
marginBottom: 8,
|
||||
},
|
||||
reactLogo: {
|
||||
height: 178,
|
||||
width: 290,
|
||||
bottom: 0,
|
||||
left: 0,
|
||||
position: 'absolute',
|
||||
},
|
||||
container: {
|
||||
flex: 1,
|
||||
backgroundColor: "#f5f5f5",
|
||||
},
|
||||
headerRight: {
|
||||
flexDirection: "row",
|
||||
gap: 16,
|
||||
},
|
||||
headerButton: {
|
||||
paddingHorizontal: 8,
|
||||
},
|
||||
loadingContainer: {
|
||||
flex: 1,
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
},
|
||||
list: {
|
||||
padding: 15,
|
||||
},
|
||||
deviceCard: {
|
||||
backgroundColor: "#fff",
|
||||
borderRadius: 12,
|
||||
padding: 15,
|
||||
marginBottom: 15,
|
||||
shadowColor: "#000",
|
||||
shadowOffset: { width: 0, height: 2 },
|
||||
shadowOpacity: 0.1,
|
||||
shadowRadius: 4,
|
||||
elevation: 3,
|
||||
},
|
||||
deviceHeader: {
|
||||
flexDirection: "row",
|
||||
justifyContent: "space-between",
|
||||
alignItems: "center",
|
||||
marginBottom: 12,
|
||||
},
|
||||
deviceInfo: {
|
||||
flex: 1,
|
||||
},
|
||||
deviceName: {
|
||||
fontSize: 18,
|
||||
fontWeight: "bold",
|
||||
color: "#333",
|
||||
marginBottom: 4,
|
||||
},
|
||||
deviceIP: {
|
||||
fontSize: 14,
|
||||
color: "#666",
|
||||
},
|
||||
statusDot: {
|
||||
width: 12,
|
||||
height: 12,
|
||||
borderRadius: 6,
|
||||
},
|
||||
deviceActions: {
|
||||
flexDirection: "row",
|
||||
justifyContent: "space-between",
|
||||
gap: 8,
|
||||
},
|
||||
actionButton: {
|
||||
flex: 1,
|
||||
paddingVertical: 10,
|
||||
borderRadius: 8,
|
||||
alignItems: "center",
|
||||
},
|
||||
wakeButton: {
|
||||
backgroundColor: "#4CAF50",
|
||||
},
|
||||
sleepButton: {
|
||||
backgroundColor: "#FF9800",
|
||||
},
|
||||
rebootButton: {
|
||||
backgroundColor: "#2196F3",
|
||||
},
|
||||
shutdownButton: {
|
||||
backgroundColor: "#f44336",
|
||||
},
|
||||
actionButtonText: {
|
||||
color: "#fff",
|
||||
fontWeight: "600",
|
||||
fontSize: 12,
|
||||
},
|
||||
emptyContainer: {
|
||||
alignItems: "center",
|
||||
paddingVertical: 50,
|
||||
},
|
||||
emptyText: {
|
||||
fontSize: 16,
|
||||
color: "#999",
|
||||
},
|
||||
});
|
||||
|
||||
231
app/(tabs)/settings.tsx
Normal file
231
app/(tabs)/settings.tsx
Normal file
@@ -0,0 +1,231 @@
|
||||
import React from 'react';
|
||||
import {
|
||||
View,
|
||||
Text,
|
||||
StyleSheet,
|
||||
ScrollView,
|
||||
TouchableOpacity,
|
||||
Alert,
|
||||
} from 'react-native';
|
||||
import { useAuth } from '../../src/context/AuthContext';
|
||||
import AsyncStorage from '@react-native-async-storage/async-storage';
|
||||
|
||||
export default function SettingsScreen() {
|
||||
const { user, logout } = useAuth();
|
||||
|
||||
const handleLogout = () => {
|
||||
Alert.alert(
|
||||
'Logout',
|
||||
'Are you sure you want to logout?',
|
||||
[
|
||||
{ text: 'Cancel', style: 'cancel' },
|
||||
{
|
||||
text: 'Logout',
|
||||
style: 'destructive',
|
||||
onPress: async () => {
|
||||
await logout();
|
||||
},
|
||||
},
|
||||
]
|
||||
);
|
||||
};
|
||||
|
||||
const handleClearData = () => {
|
||||
Alert.alert(
|
||||
'Clear Data',
|
||||
'This will clear all stored data. Are you sure?',
|
||||
[
|
||||
{ text: 'Cancel', style: 'cancel' },
|
||||
{
|
||||
text: 'Clear',
|
||||
style: 'destructive',
|
||||
onPress: async () => {
|
||||
try {
|
||||
await AsyncStorage.clear();
|
||||
Alert.alert('Success', 'All data cleared');
|
||||
} catch (error) {
|
||||
Alert.alert('Error', 'Failed to clear data');
|
||||
}
|
||||
},
|
||||
},
|
||||
]
|
||||
);
|
||||
};
|
||||
|
||||
const SettingItem = ({
|
||||
label,
|
||||
value,
|
||||
onPress
|
||||
}: {
|
||||
label: string;
|
||||
value?: string;
|
||||
onPress?: () => void;
|
||||
}) => (
|
||||
<TouchableOpacity
|
||||
style={styles.settingItem}
|
||||
onPress={onPress}
|
||||
disabled={!onPress}
|
||||
activeOpacity={onPress ? 0.7 : 1}
|
||||
>
|
||||
<Text style={styles.settingLabel}>{label}</Text>
|
||||
<View style={styles.settingValueContainer}>
|
||||
<Text style={styles.settingValue} numberOfLines={1}>
|
||||
{value || 'N/A'}
|
||||
</Text>
|
||||
</View>
|
||||
</TouchableOpacity>
|
||||
);
|
||||
|
||||
const ActionButton = ({
|
||||
title,
|
||||
onPress,
|
||||
destructive = false,
|
||||
}: {
|
||||
title: string;
|
||||
onPress: () => void;
|
||||
destructive?: boolean;
|
||||
}) => (
|
||||
<TouchableOpacity
|
||||
style={[styles.actionButton, destructive && styles.actionButtonDestructive]}
|
||||
onPress={onPress}
|
||||
>
|
||||
<Text
|
||||
style={[
|
||||
styles.actionButtonText,
|
||||
destructive && styles.actionButtonTextDestructive,
|
||||
]}
|
||||
>
|
||||
{title}
|
||||
</Text>
|
||||
</TouchableOpacity>
|
||||
);
|
||||
|
||||
return (
|
||||
<ScrollView style={styles.container}>
|
||||
<View style={styles.content}>
|
||||
<View style={styles.section}>
|
||||
<Text style={styles.sectionTitle}>User Information</Text>
|
||||
<SettingItem label="Username" value={user?.username || 'N/A'} />
|
||||
<SettingItem label="Email" value={user?.email || 'N/A'} />
|
||||
<SettingItem
|
||||
label="User ID"
|
||||
value={user?.id || 'N/A'}
|
||||
/>
|
||||
</View>
|
||||
|
||||
<View style={styles.section}>
|
||||
<Text style={styles.sectionTitle}>Server</Text>
|
||||
<SettingItem
|
||||
label="Server URL"
|
||||
value="https://wol.f6knight.duckdns.org"
|
||||
/>
|
||||
<SettingItem
|
||||
label="API Base"
|
||||
value="/api"
|
||||
/>
|
||||
</View>
|
||||
|
||||
<View style={styles.section}>
|
||||
<Text style={styles.sectionTitle}>App Info</Text>
|
||||
<SettingItem label="Version" value="1.0.0" />
|
||||
<SettingItem label="Build" value="Expo" />
|
||||
</View>
|
||||
|
||||
<View style={styles.section}>
|
||||
<Text style={styles.sectionTitle}>Actions</Text>
|
||||
<ActionButton title="Logout" onPress={handleLogout} destructive />
|
||||
<ActionButton title="Clear All Data" onPress={handleClearData} destructive />
|
||||
</View>
|
||||
|
||||
<View style={styles.footer}>
|
||||
<Text style={styles.footerText}>
|
||||
UpSnap Mobile App
|
||||
</Text>
|
||||
<Text style={styles.footerText}>
|
||||
Connect to your UpSnap server
|
||||
</Text>
|
||||
</View>
|
||||
</View>
|
||||
</ScrollView>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: {
|
||||
flex: 1,
|
||||
backgroundColor: '#f5f5f5',
|
||||
},
|
||||
content: {
|
||||
padding: 20,
|
||||
},
|
||||
section: {
|
||||
backgroundColor: '#fff',
|
||||
borderRadius: 12,
|
||||
marginBottom: 20,
|
||||
overflow: 'hidden',
|
||||
shadowColor: '#000',
|
||||
shadowOffset: { width: 0, height: 2 },
|
||||
shadowOpacity: 0.1,
|
||||
shadowRadius: 4,
|
||||
elevation: 3,
|
||||
},
|
||||
sectionTitle: {
|
||||
fontSize: 14,
|
||||
fontWeight: 'bold',
|
||||
color: '#666',
|
||||
paddingHorizontal: 15,
|
||||
paddingTop: 15,
|
||||
paddingBottom: 10,
|
||||
backgroundColor: '#f9f9f9',
|
||||
},
|
||||
settingItem: {
|
||||
flexDirection: 'row',
|
||||
justifyContent: 'space-between',
|
||||
alignItems: 'center',
|
||||
paddingHorizontal: 15,
|
||||
paddingVertical: 15,
|
||||
borderBottomWidth: 1,
|
||||
borderBottomColor: '#f0f0f0',
|
||||
},
|
||||
settingLabel: {
|
||||
fontSize: 16,
|
||||
color: '#333',
|
||||
flex: 1,
|
||||
},
|
||||
settingValueContainer: {
|
||||
flex: 1,
|
||||
alignItems: 'flex-end',
|
||||
},
|
||||
settingValue: {
|
||||
fontSize: 14,
|
||||
color: '#666',
|
||||
maxWidth: 200,
|
||||
},
|
||||
actionButton: {
|
||||
backgroundColor: '#007AFF',
|
||||
margin: 15,
|
||||
padding: 15,
|
||||
borderRadius: 8,
|
||||
alignItems: 'center',
|
||||
},
|
||||
actionButtonDestructive: {
|
||||
backgroundColor: '#f44336',
|
||||
},
|
||||
actionButtonText: {
|
||||
color: '#fff',
|
||||
fontSize: 16,
|
||||
fontWeight: 'bold',
|
||||
},
|
||||
actionButtonTextDestructive: {
|
||||
color: '#fff',
|
||||
},
|
||||
footer: {
|
||||
alignItems: 'center',
|
||||
paddingVertical: 30,
|
||||
},
|
||||
footerText: {
|
||||
fontSize: 14,
|
||||
color: '#999',
|
||||
marginBottom: 5,
|
||||
},
|
||||
});
|
||||
@@ -1,24 +1,41 @@
|
||||
import { DarkTheme, DefaultTheme, ThemeProvider } from '@react-navigation/native';
|
||||
import { Stack } from 'expo-router';
|
||||
import { StatusBar } from 'expo-status-bar';
|
||||
import 'react-native-reanimated';
|
||||
import { StatusBar } from "expo-status-bar";
|
||||
import { AuthProvider, useAuth } from "../src/context/AuthContext";
|
||||
import { useEffect } from "react";
|
||||
import { Stack, useRouter } from "expo-router";
|
||||
|
||||
import { useColorScheme } from '@/hooks/use-color-scheme';
|
||||
function RootStack() {
|
||||
const router = useRouter();
|
||||
const { isAuthenticated, isLoading } = useAuth();
|
||||
|
||||
export const unstable_settings = {
|
||||
anchor: '(tabs)',
|
||||
};
|
||||
useEffect(() => {
|
||||
if (!isLoading) {
|
||||
if (isAuthenticated) {
|
||||
router.replace('/(tabs)');
|
||||
} else {
|
||||
router.replace('/login');
|
||||
}
|
||||
}
|
||||
}, [isAuthenticated, isLoading, router]);
|
||||
|
||||
return (
|
||||
<Stack>
|
||||
{isAuthenticated ? (
|
||||
<Stack.Screen name="(tabs)" options={{ headerShown: false }} />
|
||||
) : (
|
||||
<Stack.Screen name="login" options={{ headerShown: false }} />
|
||||
)}
|
||||
<Stack.Screen name="add-device" options={{ headerShown: false }} />
|
||||
<Stack.Screen name="scan-devices" options={{ headerShown: false }} />
|
||||
<Stack.Screen name="devices/[id]" />
|
||||
</Stack>
|
||||
);
|
||||
}
|
||||
|
||||
export default function RootLayout() {
|
||||
const colorScheme = useColorScheme();
|
||||
|
||||
return (
|
||||
<ThemeProvider value={colorScheme === 'dark' ? DarkTheme : DefaultTheme}>
|
||||
<Stack>
|
||||
<Stack.Screen name="(tabs)" options={{ headerShown: false }} />
|
||||
<Stack.Screen name="modal" options={{ presentation: 'modal', title: 'Modal' }} />
|
||||
</Stack>
|
||||
<StatusBar style="auto" />
|
||||
</ThemeProvider>
|
||||
);
|
||||
return (
|
||||
<AuthProvider>
|
||||
<RootStack />
|
||||
<StatusBar style="auto" />
|
||||
</AuthProvider>
|
||||
);
|
||||
}
|
||||
|
||||
236
app/add-device.tsx
Normal file
236
app/add-device.tsx
Normal file
@@ -0,0 +1,236 @@
|
||||
import React, { useState } from 'react';
|
||||
import {
|
||||
View,
|
||||
Text,
|
||||
ScrollView,
|
||||
StyleSheet,
|
||||
TextInput,
|
||||
TouchableOpacity,
|
||||
Alert,
|
||||
ActivityIndicator,
|
||||
} from 'react-native';
|
||||
import { useRouter } from 'expo-router';
|
||||
import api from '../src/services/api';
|
||||
|
||||
export default function AddDeviceScreen() {
|
||||
const router = useRouter();
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
const [formData, setFormData] = useState({
|
||||
name: '',
|
||||
mac: '',
|
||||
ip: '',
|
||||
netmask: '255.255.255.0',
|
||||
broadcast: '',
|
||||
secureOnPassword: '',
|
||||
port: '9',
|
||||
});
|
||||
|
||||
const handleSave = async () => {
|
||||
if (!formData.name || !formData.mac || !formData.ip) {
|
||||
Alert.alert('Error', 'Please fill in all required fields');
|
||||
return;
|
||||
}
|
||||
|
||||
setIsLoading(true);
|
||||
try {
|
||||
await api.createDevice({
|
||||
name: formData.name,
|
||||
mac: formData.mac,
|
||||
ip: formData.ip,
|
||||
netmask: formData.netmask,
|
||||
broadcast: formData.broadcast,
|
||||
secureOnPassword: formData.secureOnPassword,
|
||||
port: parseInt(formData.port) || 9,
|
||||
groups: [],
|
||||
status: 'offline',
|
||||
});
|
||||
Alert.alert('Success', 'Device added successfully');
|
||||
router.back();
|
||||
} catch (error: any) {
|
||||
Alert.alert('Error', error.message || 'Failed to add device');
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<ScrollView style={styles.container}>
|
||||
<View style={styles.content}>
|
||||
<Text style={styles.header}>Add New Device</Text>
|
||||
|
||||
<View style={styles.form}>
|
||||
<View style={styles.inputGroup}>
|
||||
<Text style={styles.label}>Device Name *</Text>
|
||||
<TextInput
|
||||
style={styles.input}
|
||||
value={formData.name}
|
||||
onChangeText={(text) => setFormData({ ...formData, name: text })}
|
||||
placeholder="My PC"
|
||||
autoCapitalize="words"
|
||||
/>
|
||||
</View>
|
||||
|
||||
<View style={styles.inputGroup}>
|
||||
<Text style={styles.label}>MAC Address *</Text>
|
||||
<TextInput
|
||||
style={styles.input}
|
||||
value={formData.mac}
|
||||
onChangeText={(text) => setFormData({ ...formData, mac: text })}
|
||||
placeholder="00:11:22:33:44:55"
|
||||
autoCapitalize="characters"
|
||||
/>
|
||||
<Text style={styles.hint}>
|
||||
Format: XX:XX:XX:XX:XX:XX
|
||||
</Text>
|
||||
</View>
|
||||
|
||||
<View style={styles.inputGroup}>
|
||||
<Text style={styles.label}>IP Address *</Text>
|
||||
<TextInput
|
||||
style={styles.input}
|
||||
value={formData.ip}
|
||||
onChangeText={(text) => setFormData({ ...formData, ip: text })}
|
||||
placeholder="192.168.1.100"
|
||||
keyboardType="numeric"
|
||||
/>
|
||||
</View>
|
||||
|
||||
<View style={styles.inputGroup}>
|
||||
<Text style={styles.label}>Netmask</Text>
|
||||
<TextInput
|
||||
style={styles.input}
|
||||
value={formData.netmask}
|
||||
onChangeText={(text) => setFormData({ ...formData, netmask: text })}
|
||||
placeholder="255.255.255.0"
|
||||
keyboardType="numeric"
|
||||
/>
|
||||
</View>
|
||||
|
||||
<View style={styles.inputGroup}>
|
||||
<Text style={styles.label}>Broadcast Address</Text>
|
||||
<TextInput
|
||||
style={styles.input}
|
||||
value={formData.broadcast}
|
||||
onChangeText={(text) => setFormData({ ...formData, broadcast: text })}
|
||||
placeholder="192.168.1.255"
|
||||
keyboardType="numeric"
|
||||
/>
|
||||
<Text style={styles.hint}>
|
||||
Optional: Auto-calculated if left blank
|
||||
</Text>
|
||||
</View>
|
||||
|
||||
<View style={styles.inputGroup}>
|
||||
<Text style={styles.label}>SecureOn Password</Text>
|
||||
<TextInput
|
||||
style={styles.input}
|
||||
value={formData.secureOnPassword}
|
||||
onChangeText={(text) => setFormData({ ...formData, secureOnPassword: text })}
|
||||
placeholder="Optional password"
|
||||
secureTextEntry
|
||||
/>
|
||||
<Text style={styles.hint}>
|
||||
Optional: For SecureOn enabled NICs
|
||||
</Text>
|
||||
</View>
|
||||
|
||||
<View style={styles.inputGroup}>
|
||||
<Text style={styles.label}>Port</Text>
|
||||
<TextInput
|
||||
style={styles.input}
|
||||
value={formData.port}
|
||||
onChangeText={(text) => setFormData({ ...formData, port: text })}
|
||||
placeholder="9"
|
||||
keyboardType="numeric"
|
||||
/>
|
||||
<Text style={styles.hint}>
|
||||
Default: 9 (Standard Wake-on-LAN port)
|
||||
</Text>
|
||||
</View>
|
||||
|
||||
<View style={styles.buttonGroup}>
|
||||
<TouchableOpacity
|
||||
style={[styles.button, styles.cancelButton]}
|
||||
onPress={() => router.back()}
|
||||
disabled={isLoading}
|
||||
>
|
||||
<Text style={styles.buttonText}>Cancel</Text>
|
||||
</TouchableOpacity>
|
||||
<TouchableOpacity
|
||||
style={[styles.button, styles.saveButton]}
|
||||
onPress={handleSave}
|
||||
disabled={isLoading}
|
||||
>
|
||||
<Text style={styles.buttonText}>
|
||||
{isLoading ? 'Adding...' : 'Add Device'}
|
||||
</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
</ScrollView>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: {
|
||||
flex: 1,
|
||||
backgroundColor: '#f5f5f5',
|
||||
},
|
||||
content: {
|
||||
padding: 20,
|
||||
},
|
||||
header: {
|
||||
fontSize: 24,
|
||||
fontWeight: 'bold',
|
||||
color: '#333',
|
||||
marginBottom: 20,
|
||||
textAlign: 'center',
|
||||
},
|
||||
form: {
|
||||
gap: 20,
|
||||
},
|
||||
inputGroup: {
|
||||
gap: 8,
|
||||
},
|
||||
label: {
|
||||
fontSize: 14,
|
||||
fontWeight: '600',
|
||||
color: '#333',
|
||||
},
|
||||
input: {
|
||||
backgroundColor: '#fff',
|
||||
borderWidth: 1,
|
||||
borderColor: '#ddd',
|
||||
borderRadius: 8,
|
||||
padding: 12,
|
||||
fontSize: 16,
|
||||
},
|
||||
hint: {
|
||||
fontSize: 12,
|
||||
color: '#666',
|
||||
},
|
||||
buttonGroup: {
|
||||
flexDirection: 'row',
|
||||
gap: 10,
|
||||
marginTop: 10,
|
||||
},
|
||||
button: {
|
||||
flex: 1,
|
||||
paddingVertical: 15,
|
||||
borderRadius: 8,
|
||||
alignItems: 'center',
|
||||
},
|
||||
cancelButton: {
|
||||
backgroundColor: '#999',
|
||||
},
|
||||
saveButton: {
|
||||
backgroundColor: '#4CAF50',
|
||||
},
|
||||
buttonText: {
|
||||
color: '#fff',
|
||||
fontSize: 16,
|
||||
fontWeight: 'bold',
|
||||
},
|
||||
});
|
||||
350
app/devices/[id].tsx
Normal file
350
app/devices/[id].tsx
Normal file
@@ -0,0 +1,350 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import {
|
||||
View,
|
||||
Text,
|
||||
ScrollView,
|
||||
StyleSheet,
|
||||
TextInput,
|
||||
TouchableOpacity,
|
||||
Alert,
|
||||
ActivityIndicator,
|
||||
} from 'react-native';
|
||||
import { useLocalSearchParams, useRouter } from 'expo-router';
|
||||
import api from '../../src/services/api';
|
||||
import { Device } from '../../src/types';
|
||||
|
||||
export default function DeviceDetailsScreen() {
|
||||
const router = useRouter();
|
||||
const { id: deviceId } = useLocalSearchParams<{ id: string }>();
|
||||
|
||||
const [device, setDevice] = useState<Device | null>(null);
|
||||
const [isEditing, setIsEditing] = useState(false);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [isSaving, setIsSaving] = useState(false);
|
||||
|
||||
const [formData, setFormData] = useState({
|
||||
name: '',
|
||||
mac: '',
|
||||
ip: '',
|
||||
netmask: '',
|
||||
broadcast: '',
|
||||
secureOnPassword: '',
|
||||
port: '',
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
loadDevice();
|
||||
}, [deviceId]);
|
||||
|
||||
const loadDevice = async () => {
|
||||
try {
|
||||
setIsLoading(true);
|
||||
const data = await api.getDevice(deviceId);
|
||||
setDevice(data);
|
||||
setFormData({
|
||||
name: data.name,
|
||||
mac: data.mac,
|
||||
ip: data.ip,
|
||||
netmask: data.netmask || '',
|
||||
broadcast: data.broadcast || '',
|
||||
secureOnPassword: data.secureOnPassword || '',
|
||||
port: String(data.port),
|
||||
});
|
||||
} catch (error: any) {
|
||||
Alert.alert('Error', error.message || 'Failed to load device');
|
||||
router.back();
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleSave = async () => {
|
||||
if (!formData.name || !formData.mac || !formData.ip) {
|
||||
Alert.alert('Error', 'Please fill in all required fields');
|
||||
return;
|
||||
}
|
||||
|
||||
setIsSaving(true);
|
||||
try {
|
||||
await api.updateDevice(deviceId, {
|
||||
name: formData.name,
|
||||
mac: formData.mac,
|
||||
ip: formData.ip,
|
||||
netmask: formData.netmask,
|
||||
broadcast: formData.broadcast,
|
||||
secureOnPassword: formData.secureOnPassword,
|
||||
port: parseInt(formData.port) || 9,
|
||||
});
|
||||
setIsEditing(false);
|
||||
await loadDevice();
|
||||
Alert.alert('Success', 'Device updated successfully');
|
||||
} catch (error: any) {
|
||||
Alert.alert('Error', error.message || 'Failed to update device');
|
||||
} finally {
|
||||
setIsSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleDelete = () => {
|
||||
Alert.alert(
|
||||
'Delete Device',
|
||||
'Are you sure you want to delete this device?',
|
||||
[
|
||||
{ text: 'Cancel', style: 'cancel' },
|
||||
{
|
||||
text: 'Delete',
|
||||
style: 'destructive',
|
||||
onPress: async () => {
|
||||
try {
|
||||
await api.deleteDevice(deviceId);
|
||||
Alert.alert('Success', 'Device deleted successfully');
|
||||
router.back();
|
||||
} catch (error: any) {
|
||||
Alert.alert('Error', error.message || 'Failed to delete device');
|
||||
}
|
||||
},
|
||||
},
|
||||
]
|
||||
);
|
||||
};
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<View style={styles.loadingContainer}>
|
||||
<ActivityIndicator size="large" color="#007AFF" />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<ScrollView style={styles.container}>
|
||||
<View style={styles.content}>
|
||||
{isEditing ? (
|
||||
<View style={styles.form}>
|
||||
<Text style={styles.label}>Device Name *</Text>
|
||||
<TextInput
|
||||
style={styles.input}
|
||||
value={formData.name}
|
||||
onChangeText={(text) => setFormData({ ...formData, name: text })}
|
||||
placeholder="Device name"
|
||||
/>
|
||||
|
||||
<Text style={styles.label}>MAC Address *</Text>
|
||||
<TextInput
|
||||
style={styles.input}
|
||||
value={formData.mac}
|
||||
onChangeText={(text) => setFormData({ ...formData, mac: text })}
|
||||
placeholder="00:11:22:33:44:55"
|
||||
autoCapitalize="characters"
|
||||
/>
|
||||
|
||||
<Text style={styles.label}>IP Address *</Text>
|
||||
<TextInput
|
||||
style={styles.input}
|
||||
value={formData.ip}
|
||||
onChangeText={(text) => setFormData({ ...formData, ip: text })}
|
||||
placeholder="192.168.1.100"
|
||||
keyboardType="numeric"
|
||||
/>
|
||||
|
||||
<Text style={styles.label}>Netmask</Text>
|
||||
<TextInput
|
||||
style={styles.input}
|
||||
value={formData.netmask}
|
||||
onChangeText={(text) => setFormData({ ...formData, netmask: text })}
|
||||
placeholder="255.255.255.0"
|
||||
keyboardType="numeric"
|
||||
/>
|
||||
|
||||
<Text style={styles.label}>Broadcast Address</Text>
|
||||
<TextInput
|
||||
style={styles.input}
|
||||
value={formData.broadcast}
|
||||
onChangeText={(text) => setFormData({ ...formData, broadcast: text })}
|
||||
placeholder="192.168.1.255"
|
||||
keyboardType="numeric"
|
||||
/>
|
||||
|
||||
<Text style={styles.label}>SecureOn Password</Text>
|
||||
<TextInput
|
||||
style={styles.input}
|
||||
value={formData.secureOnPassword}
|
||||
onChangeText={(text) => setFormData({ ...formData, secureOnPassword: text })}
|
||||
placeholder="Optional password"
|
||||
/>
|
||||
|
||||
<Text style={styles.label}>Port</Text>
|
||||
<TextInput
|
||||
style={styles.input}
|
||||
value={formData.port}
|
||||
onChangeText={(text) => setFormData({ ...formData, port: text })}
|
||||
placeholder="9"
|
||||
keyboardType="numeric"
|
||||
/>
|
||||
|
||||
<View style={styles.buttonGroup}>
|
||||
<TouchableOpacity
|
||||
style={[styles.button, styles.saveButton]}
|
||||
onPress={handleSave}
|
||||
disabled={isSaving}
|
||||
>
|
||||
<Text style={styles.buttonText}>
|
||||
{isSaving ? 'Saving...' : 'Save'}
|
||||
</Text>
|
||||
</TouchableOpacity>
|
||||
<TouchableOpacity
|
||||
style={[styles.button, styles.cancelButton]}
|
||||
onPress={() => {
|
||||
setIsEditing(false);
|
||||
setFormData({
|
||||
name: device!.name,
|
||||
mac: device!.mac,
|
||||
ip: device!.ip,
|
||||
netmask: device!.netmask || '',
|
||||
broadcast: device!.broadcast || '',
|
||||
secureOnPassword: device!.secureOnPassword || '',
|
||||
port: String(device!.port),
|
||||
});
|
||||
}}
|
||||
>
|
||||
<Text style={styles.buttonText}>Cancel</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
</View>
|
||||
) : (
|
||||
<View style={styles.details}>
|
||||
<View style={styles.detailRow}>
|
||||
<Text style={styles.detailLabel}>Name</Text>
|
||||
<Text style={styles.detailValue}>{device?.name}</Text>
|
||||
</View>
|
||||
<View style={styles.detailRow}>
|
||||
<Text style={styles.detailLabel}>MAC Address</Text>
|
||||
<Text style={styles.detailValue}>{device?.mac}</Text>
|
||||
</View>
|
||||
<View style={styles.detailRow}>
|
||||
<Text style={styles.detailLabel}>IP Address</Text>
|
||||
<Text style={styles.detailValue}>{device?.ip}</Text>
|
||||
</View>
|
||||
<View style={styles.detailRow}>
|
||||
<Text style={styles.detailLabel}>Netmask</Text>
|
||||
<Text style={styles.detailValue}>{device?.netmask || 'N/A'}</Text>
|
||||
</View>
|
||||
<View style={styles.detailRow}>
|
||||
<Text style={styles.detailLabel}>Broadcast</Text>
|
||||
<Text style={styles.detailValue}>{device?.broadcast || 'N/A'}</Text>
|
||||
</View>
|
||||
<View style={styles.detailRow}>
|
||||
<Text style={styles.detailLabel}>Port</Text>
|
||||
<Text style={styles.detailValue}>{device?.port}</Text>
|
||||
</View>
|
||||
<View style={styles.detailRow}>
|
||||
<Text style={styles.detailLabel}>Status</Text>
|
||||
<Text style={styles.detailValue}>{device?.status}</Text>
|
||||
</View>
|
||||
<View style={styles.detailRow}>
|
||||
<Text style={styles.detailLabel}>Groups</Text>
|
||||
<Text style={styles.detailValue}>
|
||||
{device?.groups?.join(', ') || 'None'}
|
||||
</Text>
|
||||
</View>
|
||||
|
||||
<View style={styles.buttonGroup}>
|
||||
<TouchableOpacity
|
||||
style={[styles.button, styles.editButton]}
|
||||
onPress={() => setIsEditing(true)}
|
||||
>
|
||||
<Text style={styles.buttonText}>Edit</Text>
|
||||
</TouchableOpacity>
|
||||
<TouchableOpacity
|
||||
style={[styles.button, styles.deleteButton]}
|
||||
onPress={handleDelete}
|
||||
>
|
||||
<Text style={styles.buttonText}>Delete</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
</ScrollView>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: {
|
||||
flex: 1,
|
||||
backgroundColor: '#f5f5f5',
|
||||
},
|
||||
loadingContainer: {
|
||||
flex: 1,
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
},
|
||||
content: {
|
||||
padding: 20,
|
||||
},
|
||||
form: {
|
||||
gap: 15,
|
||||
},
|
||||
details: {
|
||||
gap: 20,
|
||||
},
|
||||
label: {
|
||||
fontSize: 14,
|
||||
fontWeight: '600',
|
||||
color: '#333',
|
||||
marginBottom: 5,
|
||||
},
|
||||
input: {
|
||||
backgroundColor: '#fff',
|
||||
borderWidth: 1,
|
||||
borderColor: '#ddd',
|
||||
borderRadius: 8,
|
||||
padding: 12,
|
||||
fontSize: 16,
|
||||
},
|
||||
detailRow: {
|
||||
backgroundColor: '#fff',
|
||||
borderRadius: 8,
|
||||
padding: 15,
|
||||
borderWidth: 1,
|
||||
borderColor: '#e0e0e0',
|
||||
},
|
||||
detailLabel: {
|
||||
fontSize: 14,
|
||||
color: '#666',
|
||||
marginBottom: 4,
|
||||
},
|
||||
detailValue: {
|
||||
fontSize: 16,
|
||||
color: '#333',
|
||||
fontWeight: '500',
|
||||
},
|
||||
buttonGroup: {
|
||||
flexDirection: 'row',
|
||||
gap: 10,
|
||||
marginTop: 20,
|
||||
},
|
||||
button: {
|
||||
flex: 1,
|
||||
paddingVertical: 15,
|
||||
borderRadius: 8,
|
||||
alignItems: 'center',
|
||||
},
|
||||
saveButton: {
|
||||
backgroundColor: '#4CAF50',
|
||||
},
|
||||
cancelButton: {
|
||||
backgroundColor: '#999',
|
||||
},
|
||||
editButton: {
|
||||
backgroundColor: '#007AFF',
|
||||
},
|
||||
deleteButton: {
|
||||
backgroundColor: '#f44336',
|
||||
},
|
||||
buttonText: {
|
||||
color: '#fff',
|
||||
fontSize: 16,
|
||||
fontWeight: 'bold',
|
||||
},
|
||||
});
|
||||
174
app/login.tsx
Normal file
174
app/login.tsx
Normal file
@@ -0,0 +1,174 @@
|
||||
import React, { useState } from 'react';
|
||||
import {
|
||||
View,
|
||||
Text,
|
||||
TextInput,
|
||||
TouchableOpacity,
|
||||
StyleSheet,
|
||||
Alert,
|
||||
KeyboardAvoidingView,
|
||||
Platform,
|
||||
ScrollView,
|
||||
} from 'react-native';
|
||||
import { useAuth } from '../src/context/AuthContext';
|
||||
import { useRouter } from 'expo-router';
|
||||
|
||||
export default function LoginScreen() {
|
||||
const router = useRouter();
|
||||
const [identity, setIdentity] = useState('');
|
||||
const [password, setPassword] = useState('');
|
||||
const [isSuperuser, setIsSuperuser] = useState(false);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const { login } = useAuth();
|
||||
|
||||
const handleLogin = async () => {
|
||||
if (!identity || !password) {
|
||||
Alert.alert('Error', 'Please enter both identity and password');
|
||||
return;
|
||||
}
|
||||
|
||||
setIsLoading(true);
|
||||
try {
|
||||
await login(identity, password, isSuperuser);
|
||||
router.replace('/');
|
||||
} catch (error: any) {
|
||||
Alert.alert('Login Failed', error.message || 'An error occurred');
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<KeyboardAvoidingView
|
||||
style={styles.container}
|
||||
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
|
||||
>
|
||||
<ScrollView contentContainerStyle={styles.scrollContent}>
|
||||
<View style={styles.header}>
|
||||
<Text style={styles.title}>UpSnap</Text>
|
||||
<Text style={styles.subtitle}>Wake on LAN Mobile</Text>
|
||||
</View>
|
||||
|
||||
<View style={styles.form}>
|
||||
<TextInput
|
||||
style={styles.input}
|
||||
placeholder="Username or Email"
|
||||
value={identity}
|
||||
onChangeText={setIdentity}
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
/>
|
||||
|
||||
<TextInput
|
||||
style={styles.input}
|
||||
placeholder="Password"
|
||||
value={password}
|
||||
onChangeText={setPassword}
|
||||
secureTextEntry
|
||||
autoCapitalize="none"
|
||||
/>
|
||||
|
||||
<TouchableOpacity
|
||||
style={styles.checkboxContainer}
|
||||
onPress={() => setIsSuperuser(!isSuperuser)}
|
||||
activeOpacity={0.7}
|
||||
>
|
||||
<View style={[styles.checkbox, isSuperuser && styles.checkboxChecked]}>
|
||||
{isSuperuser && <Text style={styles.checkmark}>✓</Text>}
|
||||
</View>
|
||||
<Text style={styles.checkboxLabel}>Login as Admin</Text>
|
||||
</TouchableOpacity>
|
||||
|
||||
<TouchableOpacity
|
||||
style={[styles.button, isLoading && styles.buttonDisabled]}
|
||||
onPress={handleLogin}
|
||||
disabled={isLoading}
|
||||
>
|
||||
<Text style={styles.buttonText}>
|
||||
{isLoading ? 'Logging in...' : 'Login'}
|
||||
</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
</ScrollView>
|
||||
</KeyboardAvoidingView>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: {
|
||||
flex: 1,
|
||||
backgroundColor: '#f5f5f5',
|
||||
},
|
||||
scrollContent: {
|
||||
flexGrow: 1,
|
||||
justifyContent: 'center',
|
||||
padding: 20,
|
||||
},
|
||||
header: {
|
||||
alignItems: 'center',
|
||||
marginBottom: 40,
|
||||
},
|
||||
title: {
|
||||
fontSize: 32,
|
||||
fontWeight: 'bold',
|
||||
color: '#333',
|
||||
marginBottom: 8,
|
||||
},
|
||||
subtitle: {
|
||||
fontSize: 16,
|
||||
color: '#666',
|
||||
},
|
||||
form: {
|
||||
width: '100%',
|
||||
},
|
||||
input: {
|
||||
backgroundColor: '#fff',
|
||||
borderWidth: 1,
|
||||
borderColor: '#ddd',
|
||||
borderRadius: 8,
|
||||
padding: 15,
|
||||
fontSize: 16,
|
||||
marginBottom: 15,
|
||||
},
|
||||
checkboxContainer: {
|
||||
flexDirection: 'row',
|
||||
alignItems: 'center',
|
||||
marginBottom: 20,
|
||||
},
|
||||
checkbox: {
|
||||
width: 24,
|
||||
height: 24,
|
||||
borderWidth: 2,
|
||||
borderColor: '#007AFF',
|
||||
borderRadius: 4,
|
||||
marginRight: 10,
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
},
|
||||
checkboxChecked: {
|
||||
backgroundColor: '#007AFF',
|
||||
},
|
||||
checkmark: {
|
||||
color: '#fff',
|
||||
fontSize: 16,
|
||||
fontWeight: 'bold',
|
||||
},
|
||||
checkboxLabel: {
|
||||
fontSize: 16,
|
||||
color: '#333',
|
||||
},
|
||||
button: {
|
||||
backgroundColor: '#007AFF',
|
||||
borderRadius: 8,
|
||||
padding: 15,
|
||||
alignItems: 'center',
|
||||
},
|
||||
buttonDisabled: {
|
||||
backgroundColor: '#ccc',
|
||||
},
|
||||
buttonText: {
|
||||
color: '#fff',
|
||||
fontSize: 16,
|
||||
fontWeight: 'bold',
|
||||
},
|
||||
});
|
||||
@@ -1,29 +0,0 @@
|
||||
import { Link } from 'expo-router';
|
||||
import { StyleSheet } from 'react-native';
|
||||
|
||||
import { ThemedText } from '@/components/themed-text';
|
||||
import { ThemedView } from '@/components/themed-view';
|
||||
|
||||
export default function ModalScreen() {
|
||||
return (
|
||||
<ThemedView style={styles.container}>
|
||||
<ThemedText type="title">This is a modal</ThemedText>
|
||||
<Link href="/" dismissTo style={styles.link}>
|
||||
<ThemedText type="link">Go to home screen</ThemedText>
|
||||
</Link>
|
||||
</ThemedView>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: {
|
||||
flex: 1,
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
padding: 20,
|
||||
},
|
||||
link: {
|
||||
marginTop: 15,
|
||||
paddingVertical: 15,
|
||||
},
|
||||
});
|
||||
433
app/scan-devices.tsx
Normal file
433
app/scan-devices.tsx
Normal file
@@ -0,0 +1,433 @@
|
||||
import React, { useState } from 'react';
|
||||
import {
|
||||
View,
|
||||
Text,
|
||||
FlatList,
|
||||
TouchableOpacity,
|
||||
StyleSheet,
|
||||
Alert,
|
||||
ActivityIndicator,
|
||||
Modal,
|
||||
TextInput,
|
||||
ScrollView,
|
||||
} from 'react-native';
|
||||
import { useRouter } from 'expo-router';
|
||||
import api from '../src/services/api';
|
||||
import { NetworkScanResult } from '../src/types';
|
||||
|
||||
export default function ScanDevicesScreen() {
|
||||
const router = useRouter();
|
||||
const [scanning, setScanning] = useState(false);
|
||||
const [devices, setDevices] = useState<NetworkScanResult[]>([]);
|
||||
const [selectedDevice, setSelectedDevice] = useState<NetworkScanResult | null>(null);
|
||||
const [showAddModal, setShowAddModal] = useState(false);
|
||||
|
||||
const [formData, setFormData] = useState({
|
||||
name: '',
|
||||
mac: '',
|
||||
ip: '',
|
||||
netmask: '255.255.255.0',
|
||||
broadcast: '',
|
||||
secureOnPassword: '',
|
||||
port: '9',
|
||||
});
|
||||
|
||||
const handleScan = async () => {
|
||||
setScanning(true);
|
||||
try {
|
||||
const results = await api.scanNetwork();
|
||||
setDevices(results);
|
||||
} catch (error: any) {
|
||||
Alert.alert('Error', error.message || 'Failed to scan network');
|
||||
} finally {
|
||||
setScanning(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleAddFromScan = (device: NetworkScanResult) => {
|
||||
const deviceName = device.name || device.hostname || `Device ${device.ip || device.ip_address}`;
|
||||
const deviceIP = device.ip || device.ip_address || '';
|
||||
const deviceMAC = device.mac || device.mac_address || '';
|
||||
const deviceVendor = device.mac_vendor || '';
|
||||
|
||||
setFormData({
|
||||
name: deviceName,
|
||||
mac: deviceMAC,
|
||||
ip: deviceIP,
|
||||
netmask: '255.255.255.0',
|
||||
broadcast: '',
|
||||
secureOnPassword: '',
|
||||
port: '9',
|
||||
});
|
||||
setSelectedDevice(device);
|
||||
setShowAddModal(true);
|
||||
};
|
||||
|
||||
const handleSaveDevice = async () => {
|
||||
if (!formData.name || !formData.mac || !formData.ip) {
|
||||
Alert.alert('Error', 'Please fill in all required fields');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await api.createDevice({
|
||||
name: formData.name,
|
||||
mac: formData.mac,
|
||||
ip: formData.ip,
|
||||
netmask: formData.netmask,
|
||||
broadcast: formData.broadcast,
|
||||
secureOnPassword: formData.secureOnPassword,
|
||||
port: parseInt(formData.port) || 9,
|
||||
groups: [],
|
||||
status: 'offline',
|
||||
});
|
||||
Alert.alert('Success', 'Device added successfully');
|
||||
setShowAddModal(false);
|
||||
router.back();
|
||||
} catch (error: any) {
|
||||
Alert.alert('Error', error.message || 'Failed to add device');
|
||||
}
|
||||
};
|
||||
|
||||
const renderDevice = ({ item }: { item: NetworkScanResult }) => {
|
||||
const displayName = item.name || item.hostname || 'Unknown Device';
|
||||
const displayIP = item.ip || item.ip_address || '';
|
||||
const displayMAC = item.mac || item.mac_address || '';
|
||||
const displayVendor = item.mac_vendor || '';
|
||||
|
||||
return (
|
||||
<TouchableOpacity
|
||||
style={styles.deviceCard}
|
||||
onPress={() => handleAddFromScan(item)}
|
||||
>
|
||||
<View style={styles.deviceInfo}>
|
||||
<Text style={styles.deviceName} numberOfLines={1}>{displayName}</Text>
|
||||
<Text style={styles.deviceDetail}>{displayIP}</Text>
|
||||
<Text style={styles.deviceDetail}>{displayMAC}</Text>
|
||||
{displayVendor && displayVendor !== 'Unknown' && (
|
||||
<Text style={styles.vendorText}>{displayVendor}</Text>
|
||||
)}
|
||||
</View>
|
||||
<View style={styles.addButton}>
|
||||
<Text style={styles.addButtonText}>+</Text>
|
||||
</View>
|
||||
</TouchableOpacity>
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
<View style={styles.header}>
|
||||
<Text style={styles.headerText}>Network Scan</Text>
|
||||
<Text style={styles.headerSubtext}>
|
||||
Discover devices on your local network
|
||||
</Text>
|
||||
</View>
|
||||
|
||||
<TouchableOpacity
|
||||
style={[styles.scanButton, scanning && styles.scanButtonDisabled]}
|
||||
onPress={handleScan}
|
||||
disabled={scanning}
|
||||
>
|
||||
{scanning ? (
|
||||
<ActivityIndicator color="#fff" />
|
||||
) : (
|
||||
<Text style={styles.scanButtonText}>Scan Network</Text>
|
||||
)}
|
||||
</TouchableOpacity>
|
||||
|
||||
<Text style={styles.infoText}>
|
||||
Note: This requires the server to have nmap installed and may take several minutes.
|
||||
</Text>
|
||||
|
||||
{devices.length > 0 && (
|
||||
<View style={styles.resultsContainer}>
|
||||
<Text style={styles.resultsHeader}>Discovered Devices ({devices.length})</Text>
|
||||
<FlatList
|
||||
data={devices}
|
||||
renderItem={renderDevice}
|
||||
keyExtractor={(item, index) => `${item.ip || item.ip_address || index}-${index}`}
|
||||
contentContainerStyle={styles.list}
|
||||
/>
|
||||
</View>
|
||||
)}
|
||||
|
||||
{devices.length === 0 && !scanning && (
|
||||
<View style={styles.emptyContainer}>
|
||||
<Text style={styles.emptyText}>Tap "Scan Network" to discover devices</Text>
|
||||
</View>
|
||||
)}
|
||||
|
||||
<Modal
|
||||
visible={showAddModal}
|
||||
animationType="slide"
|
||||
transparent
|
||||
onRequestClose={() => setShowAddModal(false)}
|
||||
>
|
||||
<View>
|
||||
<View style={styles.modalContent}>
|
||||
<View style={styles.modalHeader}>
|
||||
<Text style={styles.modalTitle}>Add Device</Text>
|
||||
<TouchableOpacity onPress={() => setShowAddModal(false)}>
|
||||
<Text style={styles.closeButton}>✕</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
|
||||
<ScrollView style={styles.modalBody}>
|
||||
<View style={styles.formGroup}>
|
||||
<Text style={styles.label}>Device Name *</Text>
|
||||
<TextInput
|
||||
style={styles.input}
|
||||
value={formData.name}
|
||||
onChangeText={(text) => setFormData({ ...formData, name: text })}
|
||||
placeholder="Device name"
|
||||
/>
|
||||
{selectedDevice?.mac_vendor && (
|
||||
<Text style={styles.hint}>
|
||||
Vendor: {selectedDevice.mac_vendor}
|
||||
</Text>
|
||||
)}
|
||||
</View>
|
||||
|
||||
<View style={styles.formGroup}>
|
||||
<Text style={styles.label}>MAC Address *</Text>
|
||||
<TextInput
|
||||
style={styles.input}
|
||||
value={formData.mac}
|
||||
onChangeText={(text) => setFormData({ ...formData, mac: text })}
|
||||
placeholder="00:11:22:33:44:55"
|
||||
autoCapitalize="characters"
|
||||
/>
|
||||
</View>
|
||||
|
||||
<View style={styles.formGroup}>
|
||||
<Text style={styles.label}>IP Address *</Text>
|
||||
<TextInput
|
||||
style={styles.input}
|
||||
value={formData.ip}
|
||||
onChangeText={(text) => setFormData({ ...formData, ip: text })}
|
||||
placeholder="192.168.1.100"
|
||||
keyboardType="numeric"
|
||||
/>
|
||||
</View>
|
||||
|
||||
<View style={styles.formGroup}>
|
||||
<Text style={styles.label}>Netmask</Text>
|
||||
<TextInput
|
||||
style={styles.input}
|
||||
value={formData.netmask}
|
||||
onChangeText={(text) => setFormData({ ...formData, netmask: text })}
|
||||
placeholder="255.255.255.0"
|
||||
keyboardType="numeric"
|
||||
/>
|
||||
</View>
|
||||
|
||||
<View style={styles.formGroup}>
|
||||
<Text style={styles.label}>Broadcast Address</Text>
|
||||
<TextInput
|
||||
style={styles.input}
|
||||
value={formData.broadcast}
|
||||
onChangeText={(text) => setFormData({ ...formData, broadcast: text })}
|
||||
placeholder="192.168.1.255"
|
||||
keyboardType="numeric"
|
||||
/>
|
||||
</View>
|
||||
|
||||
<View style={styles.formGroup}>
|
||||
<Text style={styles.label}>Port</Text>
|
||||
<TextInput
|
||||
style={styles.input}
|
||||
value={formData.port}
|
||||
onChangeText={(text) => setFormData({ ...formData, port: text })}
|
||||
placeholder="9"
|
||||
keyboardType="numeric"
|
||||
/>
|
||||
</View>
|
||||
|
||||
<TouchableOpacity
|
||||
style={styles.saveButton}
|
||||
onPress={handleSaveDevice}
|
||||
>
|
||||
<Text style={styles.saveButtonText}>Add Device</Text>
|
||||
</TouchableOpacity>
|
||||
</ScrollView>
|
||||
</View>
|
||||
</View>
|
||||
</Modal>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: {
|
||||
flex: 1,
|
||||
backgroundColor: '#f5f5f5',
|
||||
padding: 20,
|
||||
},
|
||||
header: {
|
||||
marginBottom: 20,
|
||||
},
|
||||
headerText: {
|
||||
fontSize: 24,
|
||||
fontWeight: 'bold',
|
||||
color: '#333',
|
||||
marginBottom: 5,
|
||||
},
|
||||
headerSubtext: {
|
||||
fontSize: 14,
|
||||
color: '#666',
|
||||
},
|
||||
scanButton: {
|
||||
backgroundColor: '#007AFF',
|
||||
borderRadius: 12,
|
||||
padding: 16,
|
||||
alignItems: 'center',
|
||||
marginBottom: 15,
|
||||
},
|
||||
scanButtonDisabled: {
|
||||
backgroundColor: '#ccc',
|
||||
},
|
||||
scanButtonText: {
|
||||
color: '#fff',
|
||||
fontSize: 16,
|
||||
fontWeight: 'bold',
|
||||
},
|
||||
infoText: {
|
||||
fontSize: 12,
|
||||
color: '#999',
|
||||
textAlign: 'center',
|
||||
marginBottom: 20,
|
||||
},
|
||||
resultsContainer: {
|
||||
flex: 1,
|
||||
},
|
||||
resultsHeader: {
|
||||
fontSize: 18,
|
||||
fontWeight: 'bold',
|
||||
color: '#333',
|
||||
marginBottom: 15,
|
||||
},
|
||||
list: {
|
||||
gap: 10,
|
||||
},
|
||||
deviceCard: {
|
||||
backgroundColor: 'rgba(255, 255, 255, 0.8)',
|
||||
borderRadius: 16,
|
||||
padding: 15,
|
||||
flexDirection: 'row',
|
||||
justifyContent: 'space-between',
|
||||
alignItems: 'center',
|
||||
shadowColor: '#000',
|
||||
shadowOffset: { width: 0, height: 2 },
|
||||
shadowOpacity: 0.1,
|
||||
shadowRadius: 8,
|
||||
elevation: 3,
|
||||
},
|
||||
deviceInfo: {
|
||||
flex: 1,
|
||||
},
|
||||
deviceName: {
|
||||
fontSize: 16,
|
||||
fontWeight: 'bold',
|
||||
color: '#333',
|
||||
marginBottom: 4,
|
||||
},
|
||||
deviceDetail: {
|
||||
fontSize: 14,
|
||||
color: '#666',
|
||||
marginBottom: 2,
|
||||
},
|
||||
vendorText: {
|
||||
fontSize: 12,
|
||||
color: '#999',
|
||||
fontStyle: 'italic',
|
||||
},
|
||||
addButton: {
|
||||
width: 44,
|
||||
height: 44,
|
||||
backgroundColor: 'rgba(76, 175, 80, 0.9)',
|
||||
borderRadius: 22,
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
},
|
||||
addButtonText: {
|
||||
color: '#fff',
|
||||
fontSize: 24,
|
||||
fontWeight: 'bold',
|
||||
},
|
||||
emptyContainer: {
|
||||
flex: 1,
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
},
|
||||
emptyText: {
|
||||
fontSize: 16,
|
||||
color: '#999',
|
||||
textAlign: 'center',
|
||||
},
|
||||
modalBlur: {
|
||||
flex: 1,
|
||||
justifyContent: 'flex-end',
|
||||
},
|
||||
modalContent: {
|
||||
backgroundColor: 'rgba(255, 255, 255, 0.95)',
|
||||
borderTopLeftRadius: 24,
|
||||
borderTopRightRadius: 24,
|
||||
maxHeight: '90%',
|
||||
},
|
||||
modalHeader: {
|
||||
flexDirection: 'row',
|
||||
justifyContent: 'space-between',
|
||||
alignItems: 'center',
|
||||
padding: 20,
|
||||
borderBottomWidth: 1,
|
||||
borderBottomColor: 'rgba(0, 0, 0, 0.1)',
|
||||
},
|
||||
modalTitle: {
|
||||
fontSize: 20,
|
||||
fontWeight: 'bold',
|
||||
color: '#333',
|
||||
},
|
||||
closeButton: {
|
||||
fontSize: 24,
|
||||
color: '#999',
|
||||
padding: 8,
|
||||
},
|
||||
modalBody: {
|
||||
padding: 20,
|
||||
},
|
||||
formGroup: {
|
||||
marginBottom: 16,
|
||||
},
|
||||
label: {
|
||||
fontSize: 14,
|
||||
fontWeight: '600',
|
||||
color: '#333',
|
||||
marginBottom: 8,
|
||||
},
|
||||
input: {
|
||||
backgroundColor: 'rgba(255, 255, 255, 0.8)',
|
||||
borderWidth: 1,
|
||||
borderColor: 'rgba(0, 0, 0, 0.1)',
|
||||
borderRadius: 12,
|
||||
padding: 14,
|
||||
fontSize: 16,
|
||||
},
|
||||
hint: {
|
||||
fontSize: 12,
|
||||
color: '#666',
|
||||
marginTop: 4,
|
||||
},
|
||||
saveButton: {
|
||||
backgroundColor: '#4CAF50',
|
||||
borderRadius: 12,
|
||||
padding: 16,
|
||||
alignItems: 'center',
|
||||
marginTop: 10,
|
||||
},
|
||||
saveButtonText: {
|
||||
color: '#fff',
|
||||
fontSize: 16,
|
||||
fontWeight: 'bold',
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user