build me a basic uptime dashboard template using react
- User
build me a basic uptime dashboard template using react
- Assistant
Absolutely! Here’s a basic uptime dashboard template using React. This example is simple, but you can expand it with real data, authentication, charts, etc.
Features:
- Displays a list of services and their status (Up/Down)
- Simple, clean UI
- Uses React functional components and hooks
1.
App.jsimport React, { useState, useEffect } from "react"; import "./App.css"; const initialServices = [ { name: "API Server", url: "https://api.example.com", status: "unknown" }, { name: "Website", url: "https://example.com", status: "unknown" }, { name: "Database", url: "https://db.example.com", status: "unknown" }, ]; function App() { const [services, setServices] = useState(initialServices); useEffect(() => { // Simulate status check (replace with real API calls) const checkStatus = async () => { const updated = await Promise.all( services.map(async (service) => { try { // Simulate a fetch (replace with real fetch) // const res = await fetch(service.url, { method: "HEAD" }); // return { ...service, status: res.ok ? "up" : "down" }; // For demo, randomize status: const isUp = Math.random() > 0.2; return { ...service, status: isUp ? "up" : "down" }; } catch { return { ...service, status: "down" }; } }) ); setServices(updated); }; checkStatus(); const interval = setInterval(checkStatus, 60000); // Check every 60s return () => clearInterval(interval); }, []); return ( <div className="dashboard"> <h1>Uptime Dashboard</h1> <table> <thead> <tr> <th>Service</th> <th>URL</th> <th>Status</th> </tr> </thead> <tbody> {services.map((service) => ( <tr key={service.name}> <td>{service.name}</td> <td> <a href={service.url} target="_blank" rel="noopener noreferrer"> {service.url} </a> </td> <td> <span className={ service.status === "up" ? "status up" : service.status === "down" ? "status down" : "status unknown" } > {service.status} </span> </td> </tr> ))} </tbody> </table> <p className="note">* Status updates every 60 seconds.</p> </div> ); } export default App;
2.
App.cssbody { font-family: Arial, sans-serif; background: #f4f6fa; margin: 0; padding: 0; } .dashboard { max-width: 600px; margin: 40px auto; background: #fff; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.07); padding: 32px; } h1 { text-align: center; margin-bottom: 24px; } table { width: 100%; border-collapse: collapse; margin-bottom: 16px; } th, td { padding: 12px 8px; text-align: left; } th { background: #f0f2f5; } tr:nth-child(even) { background: #f9f9f9; } .status { padding: 4px 12px; border-radius: 12px; color: #fff; font-weight: bold; text-transform: capitalize; } .status.up { background: #4caf50; } .status.down { background: #f44336; } .status.unknown { background: #9e9e9e; } .note { font-size: 0.9em; color: #888; text-align: center; }
3. Usage
- Place both files in your React project (
App.jsandApp.css). - Run your app with
npm startoryarn start.
To check real uptime:
Replace the random status logic with actualfetchrequests to your endpoints (as commented in the code).Let me know if you want to add charts, notifications, or connect to a real uptime API!
- User
make the code host in a localhost
- Assistant
Absolutely! Here’s how you can host the uptime dashboard on your localhost using React. I’ll walk you through the steps:
1. Set Up a React App
If you haven’t already, create a new React app using Create React App:
npx create-react-app uptime-dashboard cd uptime-dashboard
2. Replace the Default Files
Replace the contents of
src/App.jsandsrc/App.csswith the code provided earlier.src/App.js:import React, { useState, useEffect } from "react"; import "./App.css"; const initialServices = [ { name: "API Server", url: "https://api.example.com", status: "unknown" }, { name: "Website", url: "https://example.com", status: "unknown" }, { name: "Database", url: "https://db.example.com", status: "unknown" }, ]; function App() { const [services, setServices] = useState(initialServices); useEffect(() => { // Simulate status check (replace with real API calls) const checkStatus = async () => { const updated = await Promise.all( services.map(async (service) => { try { // Simulate a fetch (replace with real fetch) // const res = await fetch(service.url, { method: "HEAD" }); // return { ...service, status: res.ok ? "up" : "down" }; // For demo, randomize status: const isUp = Math.random() > 0.2; return { ...service, status: isUp ? "up" : "down" }; } catch { return { ...service, status: "down" }; } }) ); setServices(updated); }; checkStatus(); const interval = setInterval(checkStatus, 60000); // Check every 60s return () => clearInterval(interval); }, []); return ( <div className="dashboard"> <h1>Uptime Dashboard</h1> <table> <thead> <tr> <th>Service</th> <th>URL</th> <th>Status</th> </tr> </thead> <tbody> {services.map((service) => ( <tr key={service.name}> <td>{service.name}</td> <td> <a href={service.url} target="_blank" rel="noopener noreferrer"> {service.url} </a> </td> <td> <span className={ service.status === "up" ? "status up" : service.status === "down" ? "status down" : "status unknown" } > {service.status} </span> </td> </tr> ))} </tbody> </table> <p className="note">* Status updates every 60 seconds.</p> </div> ); } export default App;src/App.css:body { font-family: Arial, sans-serif; background: #f4f6fa; margin: 0; padding: 0; } .dashboard { max-width: 600px; margin: 40px auto; background: #fff; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.07); padding: 32px; } h1 { text-align: center; margin-bottom: 24px; } table { width: 100%; border-collapse: collapse; margin-bottom: 16px; } th, td { padding: 12px 8px; text-align: left; } th { background: #f0f2f5; } tr:nth-child(even) { background: #f9f9f9; } .status { padding: 4px 12px; border-radius: 12px; color: #fff; font-weight: bold; text-transform: capitalize; } .status.up { background: #4caf50; } .status.down { background: #f44336; } .status.unknown { background: #9e9e9e; } .note { font-size: 0.9em; color: #888; text-align: center; }
3. Start the Local Server
In your project directory, run:
npm startor
yarn startThis will start the React development server and open your dashboard at http://localhost:3000 in your browser.
4. View Your Dashboard
Open your browser and go to http://localhost:3000.
You’ll see your uptime dashboard running locally!
You can now edit the code, add real status checks, or customize the dashboard as you like.
Let me know if you want to add real HTTP checks or deploy this somewhere!
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.