2022-08-25 14:32:53 +03:00
|
|
|
import Image from "next/future/image";
|
2022-09-25 19:38:02 +03:00
|
|
|
import classNames from "classnames";
|
|
|
|
import { useContext, useState } from "react";
|
2022-08-24 10:44:35 +03:00
|
|
|
|
|
|
|
import Status from "./status";
|
|
|
|
import Widget from "./widget";
|
|
|
|
|
2022-09-26 02:23:02 +03:00
|
|
|
import Docker from "widgets/docker/component";
|
2022-09-26 12:04:37 +03:00
|
|
|
import { SettingsContext } from "utils/contexts/settings";
|
2022-09-21 09:00:57 +03:00
|
|
|
|
2022-08-27 13:49:24 +03:00
|
|
|
function resolveIcon(icon) {
|
|
|
|
if (icon.startsWith("http")) {
|
|
|
|
return `/api/proxy?url=${encodeURIComponent(icon)}`;
|
2022-09-07 16:53:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (icon.startsWith("/")) {
|
2022-08-27 18:07:57 +03:00
|
|
|
return icon;
|
2022-08-27 13:49:24 +03:00
|
|
|
}
|
2022-09-07 16:53:24 +03:00
|
|
|
|
|
|
|
if (icon.endsWith(".png")) {
|
|
|
|
return `https://cdn.jsdelivr.net/gh/walkxcode/dashboard-icons/png/${icon}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
return `https://cdn.jsdelivr.net/gh/walkxcode/dashboard-icons/png/${icon}.png`;
|
2022-08-27 13:49:24 +03:00
|
|
|
}
|
|
|
|
|
2022-09-21 09:00:57 +03:00
|
|
|
export default function Item({ service }) {
|
2022-09-12 11:55:01 +03:00
|
|
|
const hasLink = service.href && service.href !== "#";
|
2022-09-21 09:00:57 +03:00
|
|
|
const { settings } = useContext(SettingsContext);
|
2022-09-25 19:38:02 +03:00
|
|
|
const [statsOpen, setStatsOpen] = useState(false);
|
2022-09-26 14:42:40 +03:00
|
|
|
const [statsClosing, setStatsClosing] = useState(false);
|
|
|
|
|
|
|
|
// set stats to closed after 300ms
|
|
|
|
const closeStats = () => {
|
|
|
|
if (statsOpen) {
|
|
|
|
setStatsClosing(true);
|
|
|
|
setTimeout(() => {
|
|
|
|
setStatsOpen(false);
|
|
|
|
setStatsClosing(false);
|
|
|
|
}, 300);
|
|
|
|
}
|
|
|
|
};
|
2022-09-12 11:55:01 +03:00
|
|
|
|
2022-08-24 10:44:35 +03:00
|
|
|
return (
|
2022-09-02 10:55:19 +03:00
|
|
|
<li key={service.name}>
|
2022-09-25 19:38:02 +03:00
|
|
|
<div
|
|
|
|
className={`${
|
|
|
|
hasLink ? "cursor-pointer " : " "
|
|
|
|
}transition-all h-15 mb-3 p-1 rounded-md font-medium text-theme-700 hover:text-theme-700/70 dark:text-theme-200 dark:hover:text-theme-300 shadow-md shadow-black/10 dark:shadow-black/20 bg-white/50 hover:bg-theme-300/20 dark:bg-white/10 dark:hover:bg-white/20`}
|
|
|
|
>
|
|
|
|
<div className="flex select-none">
|
|
|
|
{service.icon &&
|
|
|
|
(hasLink ? (
|
2022-09-18 18:49:50 +03:00
|
|
|
<a
|
2022-09-18 16:41:01 +03:00
|
|
|
href={service.href}
|
2022-09-21 09:00:57 +03:00
|
|
|
target={settings.target ?? "_blank"}
|
2022-09-18 18:49:50 +03:00
|
|
|
rel="noreferrer"
|
2022-09-25 19:38:02 +03:00
|
|
|
className="flex-shrink-0 flex items-center justify-center w-12 "
|
2022-08-27 13:49:24 +03:00
|
|
|
>
|
2022-09-25 19:38:02 +03:00
|
|
|
<Image src={resolveIcon(service.icon)} width={32} height={32} alt="logo" />
|
2022-09-18 18:49:50 +03:00
|
|
|
</a>
|
2022-09-12 11:55:01 +03:00
|
|
|
) : (
|
2022-09-25 19:38:02 +03:00
|
|
|
<div className="flex-shrink-0 flex items-center justify-center w-12 ">
|
|
|
|
<Image src={resolveIcon(service.icon)} width={32} height={32} alt="logo" />
|
2022-09-12 11:55:01 +03:00
|
|
|
</div>
|
2022-09-25 19:38:02 +03:00
|
|
|
))}
|
2022-08-27 13:49:24 +03:00
|
|
|
|
2022-09-25 19:38:02 +03:00
|
|
|
{hasLink ? (
|
|
|
|
<a
|
|
|
|
href={service.href}
|
|
|
|
target={settings.target ?? "_blank"}
|
|
|
|
rel="noreferrer"
|
|
|
|
className="flex-1 flex items-center justify-between rounded-r-md "
|
|
|
|
>
|
|
|
|
<div className="flex-1 px-2 py-2 text-sm text-left">
|
|
|
|
{service.name}
|
|
|
|
<p className="text-theme-500 dark:text-theme-400 text-xs font-light">{service.description}</p>
|
|
|
|
</div>
|
|
|
|
</a>
|
|
|
|
) : (
|
|
|
|
<div className="flex-1 flex items-center justify-between rounded-r-md ">
|
|
|
|
<div className="flex-1 px-2 py-2 text-sm text-left">
|
|
|
|
{service.name}
|
|
|
|
<p className="text-theme-500 dark:text-theme-400 text-xs font-light">{service.description}</p>
|
|
|
|
</div>
|
2022-08-24 10:44:35 +03:00
|
|
|
</div>
|
2022-09-25 19:38:02 +03:00
|
|
|
)}
|
|
|
|
|
|
|
|
{service.container && (
|
|
|
|
<button
|
|
|
|
type="button"
|
2022-09-26 14:42:40 +03:00
|
|
|
onClick={() => (statsOpen ? closeStats() : setStatsOpen(true))}
|
2022-09-25 19:38:02 +03:00
|
|
|
className="flex-shrink-0 flex items-center justify-center w-12 cursor-pointer"
|
|
|
|
>
|
|
|
|
<Status service={service} />
|
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
</div>
|
2022-08-24 10:44:35 +03:00
|
|
|
|
2022-09-26 12:04:37 +03:00
|
|
|
{service.container && service.server && (
|
|
|
|
<div
|
|
|
|
className={classNames(
|
2022-09-26 14:42:40 +03:00
|
|
|
statsOpen && !statsClosing ? "max-h-[55px] opacity-100" : " max-h-[0] opacity-0",
|
2022-09-26 12:04:37 +03:00
|
|
|
"w-full overflow-hidden transition-all duration-300 ease-in-out"
|
|
|
|
)}
|
|
|
|
>
|
2022-09-26 14:42:40 +03:00
|
|
|
{statsOpen && <Docker service={{ widget: { container: service.container, server: service.server } }} />}
|
2022-09-26 12:04:37 +03:00
|
|
|
</div>
|
|
|
|
)}
|
2022-09-25 19:38:02 +03:00
|
|
|
|
|
|
|
{service.widget && <Widget service={service} />}
|
|
|
|
</div>
|
2022-08-24 10:44:35 +03:00
|
|
|
</li>
|
|
|
|
);
|
|
|
|
}
|