Skip to content
Merged
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
2 changes: 2 additions & 0 deletions apps/client/src/entities/flow/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ interface FlowState {
createNewFlow: (name: string) => Promise<void>;
saveGraph: (comment?: string) => Promise<void>;
loadGraph: () => Promise<void>;
resetFlowState: () => void;
}

export const useFlowStore = create<FlowState>((set, get) => ({
Expand Down Expand Up @@ -134,4 +135,5 @@ export const useFlowStore = create<FlowState>((set, get) => ({
console.error(error);
}
},
resetFlowState: () => set({ nodes: [], edges: [], currentFlowId: null }),
}));
66 changes: 62 additions & 4 deletions apps/client/src/features/auth/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { useNavigate } from "react-router";
import { Badge } from "@/components/ui/badge";

const RECENT_URLS_COOKIE = "recent_server_urls";
const MAX_RECENT_URLS = 5;

export function LoginForm({
className,
Expand All @@ -17,12 +21,16 @@ export function LoginForm({
const [password, setPassword] = useState("");
const [showAuthFields, setShowAuthFields] = useState(false);
const [isLoading, setIsLoading] = useState(false);
const [recentUrls, setRecentUrls] = useState<string[]>([]);
const navigate = useNavigate();

const handleConnect = async (e: React.FormEvent) => {
e.preventDefault();
const connectToServer = async (targetUrl: string) => {
if (!targetUrl) {
toast.error("Server URL cannot be empty.");
return;
}
setIsLoading(true);
const processedUrl = url.replace(/\/$/, "");
const processedUrl = targetUrl.replace(/\/$/, "");

try {
const response = await fetch(`${processedUrl}/info`, {
Expand All @@ -44,7 +52,17 @@ export function LoginForm({
data.status === "success"
) {
toast.success("Connected to server successfully. Please authenticate.");
Cookies.set("server_url", processedUrl, { expires: 1 / 24 });

const updatedUrls = [
processedUrl,
...recentUrls.filter((u) => u !== processedUrl),
].slice(0, MAX_RECENT_URLS);

setRecentUrls(updatedUrls);
Cookies.set(RECENT_URLS_COOKIE, JSON.stringify(updatedUrls), {
expires: 365,
});
Cookies.set("server_url", processedUrl, { expires: 1 });

setShowAuthFields(true);
} else {
Expand All @@ -61,6 +79,11 @@ export function LoginForm({
}
};

const handleConnect = async (e: React.FormEvent) => {
e.preventDefault();
await connectToServer(url);
};

const handleAuth = async (e: React.FormEvent) => {
e.preventDefault();
setIsLoading(true);
Expand Down Expand Up @@ -89,6 +112,7 @@ export function LoginForm({

if (data.token) {
Cookies.set("token", data.token, { expires: 1 / 24 });
Cookies.set("server_url", processedUrl, { expires: 1 / 24 });
toast.success("Successfully authenticated.");
navigate("/dashboard");
} else {
Expand All @@ -107,6 +131,20 @@ export function LoginForm({
const token = Cookies.get("token");
if (token) {
navigate("/dashboard");
return;
}

const storedUrls = Cookies.get(RECENT_URLS_COOKIE);
if (storedUrls) {
try {
const parsedUrls = JSON.parse(storedUrls);
if (Array.isArray(parsedUrls)) {
setRecentUrls(parsedUrls);
}
} catch (error) {
console.error("Failed to parse recent URLs from cookies.", error);
Cookies.remove(RECENT_URLS_COOKIE);
}
}
}, [navigate]);

Expand Down Expand Up @@ -141,6 +179,26 @@ export function LoginForm({
onChange={(e) => setUrl(e.target.value)}
disabled={isLoading}
/>
{recentUrls.length > 0 && (
<div className='flex flex-wrap items-center gap-2'>
<span className='text-muted-foreground text-xs'>
Recent:
</span>
{recentUrls.map((recentUrl) => (
<Badge
key={recentUrl}
variant='outline'
className='cursor-pointer'
onClick={async () => {
setUrl(recentUrl);
await connectToServer(recentUrl);
}}
>
{recentUrl}
</Badge>
))}
</div>
)}
</div>
) : (
<>
Expand Down
6 changes: 3 additions & 3 deletions apps/client/src/features/code/FileTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ const TreeNode: React.FC<TreeNodeProps> = ({ entry, onDeleteRequest }) => {
>
{entry.isDir ? (
<ChevronRight
className={`w-4 h-4 mr-1 transition-transform ${
className={`w-4 h-4 mr-0 transition-transform ${
isOpen ? "rotate-90" : ""
}`}
/>
Expand Down Expand Up @@ -171,7 +171,7 @@ const TreeNode: React.FC<TreeNodeProps> = ({ entry, onDeleteRequest }) => {
</ContextMenuItem>
<ContextMenuItem
onSelect={() => onDeleteRequest(entry)}
className='text-destructive focus:text-destructive'
className='text-red-500 focus:text-red-500'
>
<Trash2 className='w-4 h-4 mr-2' />
Delete
Expand Down Expand Up @@ -283,7 +283,7 @@ export const FileTree = () => {
return (
<div className='p-2'>
<div className='flex items-center justify-between mb-2'>
<p className='font-bold text-sm'>Project</p>
<p className='font-bold text-sm ps-2'>Project</p>
<div className='flex items-center gap-1'>
<Button
variant='ghost'
Expand Down
11 changes: 10 additions & 1 deletion apps/client/src/features/entity/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,16 @@ export function EntityCard({
</CardHeader>
<CardFooter className='flex-col items-start gap-1 px-4 text-sm'>
<div className='font-medium'>{item.platform}</div>
<div className='text-muted-foreground'></div>
<div className='text-muted-foreground'>
{isEnabledStream(
item.configuration.rtsp_url as string,
streamsState,
) ? (
<Online />
) : (
<Offline />
)}
</div>
</CardFooter>
</Card>
);
Expand Down
5 changes: 4 additions & 1 deletion apps/client/src/features/flow/AddCustomNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,10 @@ export function AddCustomNode() {

{view === "list" && (
<div className='flex-grow overflow-y-auto pr-2'>
<div className='flex justify-end mb-4'>
<div className='flex justify-end mb-4 gap-2'>
<Button size='sm' variant={"outline"}>
<PlusCircle className='mr-2 h-4 w-4' /> Select dir
</Button>
<Button size='sm' onClick={handleAddNew}>
<PlusCircle className='mr-2 h-4 w-4' /> Add New Node
</Button>
Expand Down
20 changes: 16 additions & 4 deletions apps/client/src/features/flow/Flow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,16 @@ import { RunFlowButton } from "./RunFlow";
import { FlowLog } from "../flow-log/FlowLog";

export default function FlowPage() {
const { nodes, edges, setNodes, setEdges, flows, fetchFlows, currentFlowId } =
useFlowStore();
const {
nodes,
edges,
setNodes,
setEdges,
flows,
fetchFlows,
currentFlowId,
resetFlowState,
} = useFlowStore();

// const saveAndRunFlow = async () => {
// await saveGraph();
Expand All @@ -49,7 +57,11 @@ export default function FlowPage() {

useEffect(() => {
fetchFlows();
}, [fetchFlows]);

return () => {
resetFlowState();
};
}, [fetchFlows, resetFlowState]);

useEffect(() => {
console.log("Fetched flows from API:", flows);
Expand Down Expand Up @@ -178,7 +190,7 @@ export function FlowSidebar() {
};

return (
<aside className='w-84 border-r bg-card text-card-foreground p-4 flex flex-col overflow-scroll'>
<aside className='w-86 border-r bg-card text-card-foreground p-4 flex flex-col overflow-scroll'>
<div className='flex items-center justify-between mb-4'>
<h2 className='mb-1 text-lg font-semibold tracking-tight'>Files</h2>
<div className='flex items-center'>
Expand Down
Loading