mirror of
				https://github.com/karl0ss/homepage.git
				synced 2025-10-31 14:34:00 +00:00 
			
		
		
		
	add ping indicator style setting
This commit is contained in:
		
							parent
							
								
									68ff9a94fc
								
							
						
					
					
						commit
						58c7fb15ea
					
				| @ -29,8 +29,6 @@ export default function Item({ service, group }) { | |||||||
|     } |     } | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
|   return ( |   return ( | ||||||
|     <li key={service.name} id={service.id} className="service" data-name={service.name || ""}> |     <li key={service.name} id={service.id} className="service" data-name={service.name || ""}> | ||||||
|       <div |       <div | ||||||
| @ -81,7 +79,7 @@ export default function Item({ service, group }) { | |||||||
|           <div className="absolute top-0 right-0 flex flex-row justify-end gap-2 mr-2 z-30 service-tags"> |           <div className="absolute top-0 right-0 flex flex-row justify-end gap-2 mr-2 z-30 service-tags"> | ||||||
|               {service.ping && ( |               {service.ping && ( | ||||||
|                 <div className="flex-shrink-0 flex items-center justify-center service-tag service-ping"> |                 <div className="flex-shrink-0 flex items-center justify-center service-tag service-ping"> | ||||||
|                   <Ping group={group} service={service.name} /> |                   <Ping group={group} service={service.name} style={service.pingStyle} /> | ||||||
|                   <span className="sr-only">Ping status</span> |                   <span className="sr-only">Ping status</span> | ||||||
|                 </div> |                 </div> | ||||||
|               )} |               )} | ||||||
|  | |||||||
| @ -1,7 +1,7 @@ | |||||||
| import { useTranslation } from "react-i18next"; | import { useTranslation } from "react-i18next"; | ||||||
| import useSWR from "swr"; | import useSWR from "swr"; | ||||||
| 
 | 
 | ||||||
| export default function Ping({ group, service }) { | export default function Ping({ group, service, style }) { | ||||||
|   const { t } = useTranslation(); |   const { t } = useTranslation(); | ||||||
|   const { data, error } = useSWR(`/api/ping?${new URLSearchParams({ group, service }).toString()}`, { |   const { data, error } = useSWR(`/api/ping?${new URLSearchParams({ group, service }).toString()}`, { | ||||||
|     refreshInterval: 30000 |     refreshInterval: 30000 | ||||||
| @ -23,20 +23,41 @@ export default function Ping({ group, service }) { | |||||||
|     ); |     ); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   const statusText = `${service}: HTTP status ${data.status}`; |   var statusText = `HTTP status ${data.status}`; | ||||||
|  |   var status; | ||||||
| 
 | 
 | ||||||
|   if (data.status > 403) { |   if (data.status > 403) { | ||||||
|  |     if (style === "basic") { | ||||||
|  |       status = t("docker.offline") | ||||||
|  |     } else if (style === "dot") { | ||||||
|  |       status = "◉" | ||||||
|  |     } else { | ||||||
|  |       status = data.status | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     return ( |     return ( | ||||||
|       <div className="w-auto px-1.5 py-0.5 text-center bg-theme-500/10 dark:bg-theme-900/50 rounded-b-[3px] overflow-hidden ping-status-invalid" title={statusText}> |       <div className="w-auto px-1.5 py-0.5 text-center bg-theme-500/10 dark:bg-theme-900/50 rounded-b-[3px] overflow-hidden ping-status-invalid" title={statusText}> | ||||||
|         <div className="text-[8px] font-bold text-rose-500/80">{data.status}</div> |         <div className="text-[8px] font-bold text-rose-500/80 uppercase">{status}</div> | ||||||
|       </div> |       </div> | ||||||
|     ); |     ); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |   // Sucessful ping | ||||||
|  |   var ping = t("common.ms", { value: data.latency, style: "unit", unit: "millisecond", maximumFractionDigits: 0 }) | ||||||
|  | 
 | ||||||
|  |   statusText += ` (${ping})`; | ||||||
|  | 
 | ||||||
|  |   if (style === "basic") { | ||||||
|  |     status = t("docker.running") | ||||||
|  |   } else if (style === "dot") { | ||||||
|  |     status = "◉" | ||||||
|  |   } else { | ||||||
|  |     status = ping | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|   return ( |   return ( | ||||||
|     <div className="w-auto px-1.5 py-0.5 text-center bg-theme-500/10 dark:bg-theme-900/50 rounded-b-[3px] overflow-hidden ping-status-valid" title={statusText}> |     <div className="w-auto px-1.5 py-0.5 text-center bg-theme-500/10 dark:bg-theme-900/50 rounded-b-[3px] overflow-hidden ping-status-valid" title={statusText}> | ||||||
|       <div className="text-[8px] font-bold text-emerald-500/80">{t("common.ms", { value: data.latency, style: "unit", unit: "millisecond", maximumFractionDigits: 0 })}</div> |       <div className="text-[8px] font-bold text-emerald-500/80 uppercase">{status}</div> | ||||||
|     </div> |     </div> | ||||||
|   ); |   ); | ||||||
| 
 |  | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Luca Kröger
						Luca Kröger