Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #13 add connection details #20

Merged
merged 5 commits into from
Jan 21, 2024
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
52 changes: 52 additions & 0 deletions app/details/DatabaseLine.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Button } from "@/components/ui/button"
import { useToast } from "@/components/ui/use-toast"
import { Copy, Eye, EyeOff } from "lucide-react";
import { useState } from "react";

export function DatabaseLine(props: { label: string, value: string, masked?: string }) {

const { toast } = useToast()
const [showPassword, setShowPassword] = useState(false);

function copyToClipboard(value: string) {
navigator.clipboard.writeText(value)
.then(() => {
toast({
variant: "default",
title: "Copied to clipboard",
description: "The value has been copied to your clipboard.",
})
})
.catch(() => {
toast({
variant: "destructive",
title: "Failed to copy to clipboard",
description: "The value could not be copied to your clipboard.",
})
})
}

function showMasked() {
setShowPassword(!showPassword)
}

return (
<div className="flex flex-row space-x-2">
<div className="py-2">{props.label}:</div>
{
props.value.length > 0 &&
<>
<Button className="space-x-2 bg-transparent text-gray-600 px-2 hover:text-slate-50 dark:text-gray-50 dark:hover:text-gray-600" onClick={() => copyToClipboard(props.value)}>
<p className="max-w-[10rem] md:max-w-2xl truncate">{(showPassword || !props.masked) ? props.value : props.masked}</p>
<Copy className="h-3/4" />
</Button>
{props.masked &&
<Button className="bg-transparent text-gray-600 px-2 hover:text-slate-50 dark:text-gray-50 dark:hover:text-gray-600" onClick={showMasked}>
{showPassword ? <EyeOff className="m-0 p-0 h-3/4" /> : <Eye className="m-0 p-0 h-3/4" />}
</Button>
}
</>
}
</div>
);
}
22 changes: 22 additions & 0 deletions app/details/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"use client";

import { useSession } from "next-auth/react";
import { DatabaseLine } from "./DatabaseLine";

// Shows the details of a current database connection
export default function Page() {

const { data: session, status } = useSession()

return (
<div className="w-full h-full p-5 flex flex-col space-y-4">
<h1 className="text-2xl font-bold">Connection Details</h1>
<div className="space-y-2 list-disc border rounded-lg border-gray-300 p-2">
<DatabaseLine label="Host" value={session?.user?.host || "localhost"} />
<DatabaseLine label="Port" value={(session?.user?.port || 6379).toString()} />
<DatabaseLine label="Username" value={session?.user?.name || ""} />
<DatabaseLine label="Password" value={session?.user?.password || ""} masked="********" />
</div>
</div>
)
}
2 changes: 2 additions & 0 deletions app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Navbar from '@/components/custom/navbar'
import { ResizableHandle, ResizablePanel, ResizablePanelGroup } from '@/components/ui/resizable'
import NextAuth from 'next-auth'
import { NextAuthProvider } from './providers'
import { Toaster } from '@/components/ui/toaster'

const inter = Inter({ subsets: ['latin'] })

Expand All @@ -22,6 +23,7 @@ export default function RootLayout({
<html lang="en">
<body className={inter.className}>
<NextAuthProvider>{children}</NextAuthProvider>
<Toaster />
</body>
</html>
)
Expand Down
33 changes: 23 additions & 10 deletions components/custom/navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LogOut, Menu } from "lucide-react";
import { Info, LogOut, Menu, Waypoints } from "lucide-react";
import { signOut, useSession } from "next-auth/react";
import Link from "next/link";
import { Switch } from "../ui/switch";
Expand All @@ -8,8 +8,8 @@ import { useTheme } from "next-themes";

export default function Navbar() {
const { data: session, status } = useSession()
const { theme, setTheme, systemTheme} = useTheme()
const { theme, setTheme, systemTheme } = useTheme()

const [mounted, setMounted] = useState(false)

useEffect(() => {
Expand All @@ -25,7 +25,7 @@ export default function Navbar() {
}
}

let darkmode = theme=="dark" || (theme=="system" && systemTheme=="dark")
let darkmode = theme == "dark" || (theme == "system" && systemTheme == "dark")

return (
<nav className="w-full h-full bg-gray-100 dark:bg-gray-800 p-5 space-y-4 flex flex-col">
Expand All @@ -40,8 +40,9 @@ export default function Navbar() {
<Menu className="h-6 w-6" />
<span className="font-bold">FalkorDB Browser</span>
</div>
<ul className="space-y-2">
{/* <li className="flex items-center space-x-2">
{status === "authenticated" &&
<ul className="space-y-2">
{/* <li className="flex items-center space-x-2">
<AirVentIcon className="h-6 w-6" />
<span>Employees</span>
</li>
Expand All @@ -58,19 +59,31 @@ export default function Navbar() {
<span>Calendar</span>
</li> */}

{/* <li className="flex items-center space-x-2">
{/* <li className="flex items-center space-x-2">
<AirVentIcon className="h-6 w-6" />
<span>Profile</span>
</li> */}
{status === "authenticated" &&

<li className="flex items-center space-x-2">
<Info className="h-6 w-6" />
<Link className="underline underline-offset-2" href="/details">
Connection Details
</Link>
</li>
<li className="flex items-center space-x-2">
<Waypoints className="h-6 w-6" />
<Link className="underline underline-offset-2" href="/graph">
Graph
</Link>
</li>
<li className="flex items-center space-x-2">
<LogOut className="h-6 w-6" />
<Link className="underline underline-offset-2" href="/" onClick={() => signOut({ callbackUrl: '/' })}>
Sign Out
</Link>
</li>
}
</ul>
</ul>
}
</nav>
)
}
Loading