Move resolveIcon func to utils for reusability
This commit is contained in:
parent
9916ae3372
commit
f5c7663767
3 changed files with 19 additions and 18 deletions
|
@ -1,7 +1,8 @@
|
|||
import classNames from "classnames";
|
||||
import Image from "next/future/image";
|
||||
import classNames from "classnames";
|
||||
|
||||
import List from "components/services/list";
|
||||
import { resolveIcon } from "utils/icon-resolver";
|
||||
|
||||
export default function ServicesGroup({ services, layout }) {
|
||||
return (
|
||||
|
@ -14,7 +15,7 @@ export default function ServicesGroup({ services, layout }) {
|
|||
>
|
||||
<div className="flex select-none">
|
||||
{services.icon &&
|
||||
<Image src={services.icon} width={32} height={32} alt="logo" className="flex-shrink-0 flex items-center justify-center w-10"/>
|
||||
<Image src={resolveIcon(services.icon)} width={32} height={32} alt="logo" className="flex-shrink-0 flex items-center justify-center w-10"/>
|
||||
}
|
||||
<h2 className={services.icon ? "text-theme-800 dark:text-theme-300 text-xl font-medium flex-1 flex items-center justify-between rounded-r-md flex-1 px-2 py-2 text-sm text-left" : "text-theme-800 dark:text-theme-300 text-xl font-medium h2-title-noicon"}>{services.name}</h2>
|
||||
</div>
|
||||
|
|
|
@ -7,22 +7,7 @@ import Widget from "./widget";
|
|||
import Docker from "./widgets/service/docker";
|
||||
|
||||
import { SettingsContext } from "utils/settings-context";
|
||||
|
||||
function resolveIcon(icon) {
|
||||
if (icon.startsWith("http")) {
|
||||
return `/api/proxy?url=${encodeURIComponent(icon)}`;
|
||||
}
|
||||
|
||||
if (icon.startsWith("/")) {
|
||||
return icon;
|
||||
}
|
||||
|
||||
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`;
|
||||
}
|
||||
import { resolveIcon } from "utils/icon-resolver";
|
||||
|
||||
export default function Item({ service }) {
|
||||
const hasLink = service.href && service.href !== "#";
|
||||
|
|
15
src/utils/icon-resolver.js
Normal file
15
src/utils/icon-resolver.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
export function resolveIcon(icon) {
|
||||
if (icon.startsWith("http")) {
|
||||
return `/api/proxy?url=${encodeURIComponent(icon)}`;
|
||||
}
|
||||
|
||||
if (icon.startsWith("/")) {
|
||||
return icon;
|
||||
}
|
||||
|
||||
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`;
|
||||
}
|
Loading…
Add table
Reference in a new issue