// components/portal/UtilitySwitcher.tsx "use client"; import { useEffect, useMemo, useRef, useState } from "react"; import { useRouter, useSearchParams } from "next/navigation"; import { cn } from "@/lib/utils"; type Item = { key: string; // used in ?t= label: string; note?: string; icon?: string; // optional icon (public/images/utils/) href: string; // absolute URL }; const ITEMS: Item[] = [ // On-site (embed) { key: "laser-toolkit", label: "Laser Toolkit", note: "convert laser settings, interval and more", icon: "toolkit.png", href: "https://makearmy.io/laser-toolkit", }, { key: "files", label: "File Server", note: "download from our file explorer", icon: "fs.png", href: "https://makearmy.io/files", }, { key: "buying-guide", label: "Buying Guide", note: "reviews and listings for relevant products", icon: "bg.png", href: "https://makearmy.io/buying-guide", }, { key: "svgnest", label: "SVGnest", note: "automatically nests parts and exports svg", icon: "nest.png", href: "https://makearmy.io/svgnest", }, { key: "background-remover", label: "BG Remover", note: "open source background remover", icon: "bgrm.png", href: "https://makearmy.io/background-remover", }, // Subdomains (new tab) { key: "picsur", label: "Picsur", note: "Simple Image Host", icon: "picsur.png", href: "https://images.makearmy.io", }, { key: "privatebin", label: "PrivateBin", note: "Encrypted internet clipboard", icon: "privatebin.png", href: "https://paste.makearmy.io/", }, { key: "forgejo", label: "Forgejo", note: "git for our community members", icon: "forgejo.png", href: "https://forge.makearmy.io", }, ]; function isExternal(urlStr: string) { try { const u = new URL(urlStr); return u.hostname !== "makearmy.io"; } catch { return true; } } /** For on-site URLs, convert absolute https://makearmy.io/path → /path for iframe src */ function toOnsitePath(urlStr: string): string { try { const u = new URL(urlStr); if (u.hostname === "makearmy.io") { return `${u.pathname}${u.search}${u.hash}`; } } catch {} return urlStr; } function Panel({ item }: { item: Item }) { const external = isExternal(item.href); if (external) { return (
Opened {item.label} in a new tab.
Click here if it didn’t open.
); } const src = toOnsitePath(item.href); return (
{item.note}