aboutsummaryrefslogtreecommitdiff
path: root/web/src/app/components
diff options
context:
space:
mode:
Diffstat (limited to 'web/src/app/components')
-rw-r--r--web/src/app/components/Card.jsx7
-rw-r--r--web/src/app/components/Navbar.jsx83
-rw-r--r--web/src/app/components/sign-out.jsx15
3 files changed, 96 insertions, 9 deletions
diff --git a/web/src/app/components/Card.jsx b/web/src/app/components/Card.jsx
new file mode 100644
index 0000000..e6d55fd
--- /dev/null
+++ b/web/src/app/components/Card.jsx
@@ -0,0 +1,7 @@
+export default function Card({children}) {
+ return (
+ <div className="p-4 bg-gray-900 rounded-md">
+ {children}
+ </div>
+ )
+}
diff --git a/web/src/app/components/Navbar.jsx b/web/src/app/components/Navbar.jsx
index 242175c..f07718c 100644
--- a/web/src/app/components/Navbar.jsx
+++ b/web/src/app/components/Navbar.jsx
@@ -1,25 +1,94 @@
+'use client';
+import { useState, useEffect } from 'react';
import SignOut from "@/app/components/sign-out";
+import Link from "next/link";
+import { fetchWithAuth } from '@/utils/api';
export default function Navbar() {
+ const [versionInfo, setVersionInfo] = useState({
+ ab_version: 'Loading...',
+ api_version: 'Loading...'
+ });
+ const [uptime, setUptime] = useState('Loading...');
+
+ useEffect(() => {
+ // Get the API URL
+ const apiUrl = localStorage.getItem('apiUrl');
+ if (!apiUrl) return;
+
+ // Fetch version information - no auth required
+ fetch(`${apiUrl}/api/version`)
+ .then(response => response.json())
+ .then(data => {
+ setVersionInfo({
+ ab_version: data.ab_version,
+ api_version: data.api_version
+ });
+ })
+ .catch(error => {
+ console.error('Failed to fetch version info:', error);
+ setVersionInfo({
+ ab_version: 'Error',
+ api_version: 'Error'
+ });
+ });
+
+ // Fetch uptime information - no auth required
+ fetch(`${apiUrl}/api/uptime`)
+ .then(response => response.json())
+ .then(data => {
+ // Convert milliseconds to a readable format
+ const ms = data.uptime;
+ const seconds = Math.floor(ms / 1000);
+ const minutes = Math.floor(seconds / 60);
+ const hours = Math.floor(minutes / 60);
+ const days = Math.floor(hours / 24);
+
+ let uptimeText = '';
+ if (days > 0) {
+ uptimeText = `${days} day${days !== 1 ? 's' : ''}`;
+ } else if (hours > 0) {
+ uptimeText = `${hours} hour${hours !== 1 ? 's' : ''}`;
+ } else if (minutes > 0) {
+ uptimeText = `${minutes} minute${minutes !== 1 ? 's' : ''}`;
+ } else {
+ uptimeText = `${seconds} second${seconds !== 1 ? 's' : ''}`;
+ }
+
+ setUptime(uptimeText);
+ })
+ .catch(error => {
+ console.error('Failed to fetch uptime:', error);
+ setUptime('Error');
+ });
+ }, []);
+
return (
<nav className="bg-gray-900 text-white">
<div className="max-w-screen-xl flex items-center justify-between mx-auto p-4">
<div className="flex items-center space-x-4">
<h1 className="text-xl font-medium">AleeBot</h1>
<ul>
- <li className="inline-block mx-2">Guilds</li>
- <li className="inline-block mx-2">Quotes</li>
- <li className="inline-block mx-2">Settings</li>
+ {[
+ ['Guilds', '/guilds'],
+ ['Quotes', '/quotes'],
+ ].map(([title, url]) => (
+ <li key={title} className="inline-block mx-2">
+ <Link href={url}>
+ {title}
+ </Link>
+ </li>
+ ))}
</ul>
</div>
<div className="flex items-center space-x-4">
- <span>Uptime: 1 day</span>
- <span>API v(version)</span>
- <span>4.0.0 Beta</span>
+ <span>Uptime: {uptime}</span>
+ <span>API v{versionInfo.api_version}</span>
+ <span>{versionInfo.ab_version}</span>
<SignOut />
</div>
</div>
</nav>
- )
+ );
}
diff --git a/web/src/app/components/sign-out.jsx b/web/src/app/components/sign-out.jsx
index dd6693d..b0762d8 100644
--- a/web/src/app/components/sign-out.jsx
+++ b/web/src/app/components/sign-out.jsx
@@ -1,5 +1,16 @@
+'use client';
+import { useAuth } from '@/context/middleware';
+
export default function SignOut() {
+ const { logout } = useAuth();
+
return (
- <button type="submit" className="py-2 px-4 rounded-md text-md bg-red-700 hover:bg-red-500">Sign out</button>
- )
+ <button
+ type="button"
+ onClick={logout}
+ className="py-2 px-4 rounded-md text-md bg-red-700 hover:bg-red-500"
+ >
+ Sign out
+ </button>
+ );
}