vaulterm/frontend/app/index.tsx

85 lines
2.2 KiB
TypeScript
Raw Normal View History

2024-11-06 17:32:39 +00:00
import { View, ScrollView, Button } from "react-native";
2024-11-06 14:53:07 +07:00
import React, { useState } from "react";
2024-11-05 18:43:59 +07:00
import { Stack } from "expo-router";
2024-11-06 17:32:39 +00:00
import InteractiveSession, {
InteractiveSessionProps,
} from "@/components/containers/interactive-session";
2024-11-06 14:53:07 +07:00
import PagerView from "@/components/ui/pager-view";
let nextSession = 1;
2024-11-05 18:43:59 +07:00
2024-11-06 17:32:39 +00:00
type Session = InteractiveSessionProps & { id: string };
2024-11-05 18:43:59 +07:00
const HomePage = () => {
2024-11-06 17:32:39 +00:00
const [sessions, setSessions] = useState<Session[]>([
{
id: "1",
type: "ssh",
params: { serverId: "1" },
},
{
id: "2",
type: "pve",
params: { client: "vnc", serverId: "2" },
},
{
id: "3",
type: "pve",
params: { client: "xtermjs", serverId: "3" },
},
]);
2024-11-06 14:53:07 +07:00
const [curSession, setSession] = useState(0);
2024-11-05 18:43:59 +07:00
return (
2024-11-06 06:24:14 +00:00
<View style={{ flex: 1 }}>
2024-11-05 18:43:59 +07:00
<Stack.Screen options={{ title: "Home" }} />
2024-11-06 06:24:14 +00:00
2024-11-06 14:53:07 +07:00
<ScrollView
horizontal
style={{ flexGrow: 0 }}
contentContainerStyle={{ flexDirection: "row", gap: 8 }}
>
{sessions.map((session, idx) => (
<View
2024-11-06 17:32:39 +00:00
key={session.id}
2024-11-06 14:53:07 +07:00
style={{ flexDirection: "row", alignItems: "center" }}
>
<Button
2024-11-06 17:32:39 +00:00
title={"Session " + session.id}
2024-11-06 14:53:07 +07:00
color="#222"
onPress={() => setSession(idx)}
/>
<Button
title="X"
onPress={() => {
2024-11-06 17:32:39 +00:00
const newSessions = sessions.filter((s) => s.id !== session.id);
2024-11-06 14:53:07 +07:00
setSessions(newSessions);
setSession(
Math.min(Math.max(curSession, 0), newSessions.length - 1)
);
}}
/>
</View>
))}
2024-11-06 17:32:39 +00:00
{/* <Button
2024-11-06 14:53:07 +07:00
title="[ + ]"
onPress={() => {
nextSession += 1;
setSessions([...sessions, nextSession.toString()]);
setSession(sessions.length);
}}
2024-11-06 17:32:39 +00:00
/> */}
2024-11-06 14:53:07 +07:00
</ScrollView>
<PagerView style={{ flex: 1 }} page={curSession}>
{sessions.map((session) => (
2024-11-06 17:32:39 +00:00
<InteractiveSession key={session.id} {...session} />
2024-11-06 14:53:07 +07:00
))}
</PagerView>
2024-11-05 18:43:59 +07:00
</View>
);
};
export default HomePage;