Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
"icon": "./assets/images/noBgScaleManagerLogo.png",
"scheme": "myapp",
"userInterfaceStyle": "automatic",
"newArchEnabled": true,
"ios": {
"supportsTablet": true,
"bundleIdentifier": "com.scaleManager.scaleManager",
"appleTeamId": "PB5QFHF445",
"buildNumber": "2",
"infoPlist": {
"ITSAppUsesNonExemptEncryption": false
"ITSAppUsesNonExemptEncryption": false,
"NSAppTransportSecurity": {
"NSAllowsArbitraryLoads": true
}
}
},
"android": {
Expand Down Expand Up @@ -42,7 +44,8 @@
],
"expo-font",
"expo-web-browser",
"expo-status-bar"
"expo-status-bar",
"expo-sharing"
],
"experiments": {
"typedRoutes": true
Expand Down
110 changes: 47 additions & 63 deletions app/(tabs)/_layout.tsx
Original file line number Diff line number Diff line change
@@ -1,151 +1,135 @@
import { TopTabs } from "expo-router/js-top-tabs";
import { Tabs } from "expo-router";
import { MaterialCommunityIcons } from "@expo/vector-icons";
import { getServerConfig } from "../utils/getServer";
import { useEffect, useState, type ComponentProps } from "react";
import { StyleSheet, Text, type ColorValue } from "react-native";
import { useEffect, useMemo, useState, type ComponentProps, type ReactNode } from "react";
import { isV026OrHigher } from "../utils/headscaleVersion";
import { useTheme } from "@/theme";
import { spacing } from "@/theme/spacing";
import { TabSwipeHost } from "@/app/components/TabSwipeHost";

function tabIcon(name: ComponentProps<typeof MaterialCommunityIcons>["name"]) {
return ({ color }: { color: string }) => (
<MaterialCommunityIcons name={name} color={color} size={24} />
);
}

function TabLabel({
color,
children,
}: {
color: ColorValue;
children: string;
}) {
const { theme } = useTheme();

return (
<Text
numberOfLines={1}
style={{
...theme.typography.label,
marginTop: 2,
fontSize: 11,
color,
textAlign: "center",
}}
>
{children}
</Text>
);
function TabBarIcon({ color }: { color: string }) {
return <MaterialCommunityIcons name={name} color={color} size={24} />;
}
TabBarIcon.displayName = `TabBarIcon(${name})`;
return TabBarIcon;
}

export default function TabLayout() {
const [hideRoutes, setHideRoutes] = useState(false);
const { theme } = useTheme();

useEffect(() => {
let cancelled = false;
async function checkVersion() {
const serverConf = await getServerConfig();
if (isV026OrHigher(serverConf?.version)) {
if (!cancelled && isV026OrHigher(serverConf?.version)) {
setHideRoutes(true);
}
}
checkVersion();
return () => {
cancelled = true;
};
}, []);

const tabOrder = useMemo(
() =>
hideRoutes
? ["index", "users", "devices", "preauthkeys", "apikeys", "acl"]
: ["index", "users", "devices", "preauthkeys", "apikeys", "routes", "acl"],
[hideRoutes],
);

const screenLayout = useMemo(
() =>
function SwipeScreenLayout({ children }: { children: ReactNode }) {
return <TabSwipeHost tabOrder={tabOrder}>{children}</TabSwipeHost>;
},
[tabOrder],
);

return (
<TopTabs
tabBarPosition="bottom"
<Tabs
screenLayout={screenLayout}
screenOptions={{
swipeEnabled: true,
animationEnabled: true,
lazy: true,
lazyPreloadDistance: 1,
tabBarShowIcon: true,
headerShown: false,
tabBarActiveTintColor: theme.colors.primary,
tabBarInactiveTintColor: theme.colors.tabBarInactive,
tabBarPressColor: theme.colors.primarySoft,
tabBarIndicatorStyle: { height: 0 },
tabBarStyle: {
backgroundColor: theme.colors.tabBar,
borderTopColor: theme.colors.tabBarBorder,
borderTopWidth: StyleSheet.hairlineWidth,
height: 84,
paddingTop: spacing.xs,
paddingBottom: spacing.sm,
elevation: 0,
shadowOpacity: 0,
},
tabBarLabelStyle: {
...theme.typography.label,
marginTop: 2,
fontSize: 11,
},
tabBarItemStyle: {
paddingVertical: spacing.xs,
paddingHorizontal: 0,
},
tabBarLabel: ({
color,
children,
}: {
color: ColorValue;
children: string;
}) => <TabLabel color={color}>{children}</TabLabel>,
sceneStyle: { backgroundColor: theme.colors.background },
}}
>
<TopTabs.Screen
<Tabs.Screen
name="index"
options={{
title: "Home",
tabBarIcon: tabIcon("home"),
}}
/>

<TopTabs.Screen
<Tabs.Screen
name="users"
options={{
title: "Users",
tabBarIcon: tabIcon("account-group"),
}}
/>

<TopTabs.Screen
<Tabs.Screen
name="devices"
options={{
title: "Devices",
tabBarIcon: tabIcon("devices"),
}}
/>

<TopTabs.Screen
<Tabs.Screen
name="preauthkeys"
options={{
title: "Auth Keys",
tabBarIcon: tabIcon("key-chain"),
}}
/>

<TopTabs.Screen
<Tabs.Screen
name="apikeys"
options={{
title: "API Keys",
tabBarIcon: tabIcon("key"),
}}
/>

<TopTabs.Protected guard={!hideRoutes}>
<TopTabs.Screen
<Tabs.Protected guard={!hideRoutes}>
<Tabs.Screen
name="routes"
options={{
title: "Routes",
tabBarIcon: tabIcon("router-network"),
}}
/>
</TopTabs.Protected>
</Tabs.Protected>

<TopTabs.Screen
<Tabs.Screen
name="acl"
options={{
title: "ACL",
tabBarIcon: tabIcon("shield-account"),
}}
/>
</TopTabs>
</Tabs>
);
}
14 changes: 7 additions & 7 deletions app/(tabs)/acl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,15 @@ export default function ACLScreen() {
</View>

{policy ? (
<ScrollView
horizontal
showsHorizontalScrollIndicator={true}
className="rounded-xl p-4" style={{ backgroundColor: colors.background }}
>
<Text className="font-mono text-xs leading-5" style={{ color: colors.success }} selectable>
<View className="rounded-xl p-4" style={{ backgroundColor: colors.background }}>
<Text
className="font-mono text-xs leading-5"
style={{ color: colors.success }}
selectable
>
{policy}
</Text>
</ScrollView>
</View>
) : (
<View className="rounded-xl p-8 items-center" style={{ backgroundColor: colors.background }}>
<View className="rounded-full p-6 mb-3" style={{ backgroundColor: colors.surface }}>
Expand Down
62 changes: 39 additions & 23 deletions app/(tabs)/devices.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,21 @@ import {
TextInput,
} from "react-native";
import { SafeAreaView } from "react-native-safe-area-context";
import { useLocalSearchParams } from "expo-router";
import { MaterialIcons } from "@expo/vector-icons";
import { useDevices } from "@/app/funcs/devices";
import { RegisterDeviceModal } from "@/app/components/RegisterDeviceModal";
import { ScreenLoading } from "@/app/components/ScreenLoading";
import { useTheme } from "@/theme";

type DeviceFilter = "all" | "online" | "offline";

function parseDeviceFilter(value: string | string[] | undefined): DeviceFilter {
const raw = Array.isArray(value) ? value[0] : value;
if (raw === "online" || raw === "offline" || raw === "all") return raw;
return "all";
}

export default function DevicesScreen() {
const {
devices,
Expand All @@ -40,11 +49,20 @@ export default function DevicesScreen() {
} = useDevices();
const { theme } = useTheme();
const { colors } = theme;
const { filter: filterParam } = useLocalSearchParams<{ filter?: string }>();

const [searchQuery, setSearchQuery] = useState("");
const [filterOnline, setFilterOnline] = useState<"all" | "online" | "offline">("all");
const [manualFilter, setManualFilter] = useState<DeviceFilter | null>(null);
const [seenFilterParam, setSeenFilterParam] = useState(filterParam);
const [sortBy, setSortBy] = useState<"name" | "lastSeen" | "user">("name");

// Prefer route params from Home taps; clear manual override when they change.
if (filterParam !== seenFilterParam) {
setSeenFilterParam(filterParam);
setManualFilter(null);
}
const filterOnline = manualFilter ?? parseDeviceFilter(filterParam);

const filteredAndSortedDevices = sortDevices(
devices
.filter(device => {
Expand Down Expand Up @@ -123,28 +141,26 @@ export default function DevicesScreen() {

{/* Filter and Sort Controls */}
<View className="flex-row space-x-2">
{/* Status Filter */}
<ScrollView horizontal showsHorizontalScrollIndicator={false} className="flex-1">
<View className="flex-row space-x-2 pt-2">
{[
{ key: "all", label: "All", count: devices.length },
{ key: "online", label: "Online", count: devices.filter(d => d.online).length },
{ key: "offline", label: "Offline", count: devices.filter(d => !d.online).length },
].map((filter) => (
<TouchableOpacity
key={filter.key}
onPress={() => setFilterOnline(filter.key as any)}
activeOpacity={0.8}
className="px-3 mr-2 py-2 rounded-lg"
style={{ backgroundColor: filterOnline === filter.key ? colors.primary : colors.surfaceMuted }}
>
<Text className="text-sm font-medium" style={{ color: filterOnline === filter.key ? colors.onPrimary : colors.textSecondary }}>
{filter.label} ({filter.count})
</Text>
</TouchableOpacity>
))}
</View>
</ScrollView>
{/* Status Filter — plain row (not horizontal ScrollView) so tab swipes aren't stolen mid-gesture */}
<View className="flex-1 flex-row flex-wrap gap-2 pt-2">
{[
{ key: "all", label: "All", count: devices.length },
{ key: "online", label: "Online", count: devices.filter(d => d.online).length },
{ key: "offline", label: "Offline", count: devices.filter(d => !d.online).length },
].map((filter) => (
<TouchableOpacity
key={filter.key}
onPress={() => setManualFilter(filter.key as DeviceFilter)}
activeOpacity={0.8}
className="px-3 py-2 rounded-lg"
style={{ backgroundColor: filterOnline === filter.key ? colors.primary : colors.surfaceMuted }}
>
<Text className="text-sm font-medium" style={{ color: filterOnline === filter.key ? colors.onPrimary : colors.textSecondary }}>
{filter.label} ({filter.count})
</Text>
</TouchableOpacity>
))}
</View>
{/* Sort Button */}
<TouchableOpacity
onPress={() => {
Expand Down
Loading
Loading