Skip to content

armgit / mso

Public Imported from GitHub
0

Browser-based graphical shell and control plane for a Linux server you own — real terminal, file manager, live metrics and BYOK AI in one mobile-first workspace. Next.js 16 · React 19 · node-pty · Tailwind v4 · shadcn/ui. Public alpha, self-hosted.

2.8 KB
Raw Blame
"use client";

import { Compass, Heart, Leaf, Shield, Sparkles, Star, UserRound, Zap, type LucideIcon } from "lucide-react";
import type { AccountIcon, AccountPreset } from "@/lib/auth/account-profile-model";
import { DynamicIcon } from "@/features/icon-picker";
import { cn } from "@/lib/utils";

const PRESET_ICON: Record<AccountPreset, LucideIcon> = {
  user: UserRound,
  spark: Sparkles,
  shield: Shield,
  star: Star,
  heart: Heart,
  zap: Zap,
  leaf: Leaf,
  compass: Compass,
};

/** The picker stores emoji as a bare glyph (`🎯`, `🎯?c=0b6e99`) but the account store
 *  requires the explicit `emoji:` namespace (see LIBRARY_ICON in
 *  lib/auth/account-profile.ts). These two functions are the only translation point. */
export function libraryValueFromPicker(value: string): string {
  if (!value) return value;
  if (value.startsWith("lucide:") || value.startsWith("phosphor:") || value.startsWith("emoji:")) return value;
  return `emoji:${value}`;
}

export function pickerValueFromLibrary(value: string | null): string | null {
  if (!value) return null;
  return value.startsWith("emoji:") ? value.slice("emoji:".length) : value;
}

export function AccountAvatar({ icon, className }: { icon: AccountIcon; className?: string }) {
  if (icon.type === "image") {
    // Owner-uploaded data URLs are authenticated bytes, not optimizer inputs.
    return (
      // eslint-disable-next-line @next/next/no-img-element
      <img src={icon.src} alt="" className={cn("size-16 rounded-full object-cover", className)} />
    );
  }
  if (icon.type === "library") {
    return (
      <span className={cn("grid size-16 place-items-center rounded-full bg-primary text-primary-foreground", className)}>
        {/* forceNative: an account avatar must not fetch a glyph from a CDN. */}
        <DynamicIcon value={pickerValueFromLibrary(icon.value)} size={32} forceNative />
      </span>
    );
  }
  // Stored `preset` icons predate the picker; they must keep rendering.
  const Icon = PRESET_ICON[icon.id];
  return (
    <span className={cn("grid size-16 place-items-center rounded-full bg-primary text-primary-foreground", className)}>
      <Icon className="size-8" aria-hidden />
    </span>
  );
}

export function AccountPresetButton({
  id,
  pressed,
  disabled,
  onSelect,
}: {
  id: AccountPreset;
  pressed: boolean;
  disabled: boolean;
  onSelect: (id: AccountPreset) => void;
}) {
  const Icon = PRESET_ICON[id];
  return (
    <button
      type="button"
      aria-pressed={pressed}
      aria-label={`Use ${id} icon`}
      disabled={disabled}
      onClick={() => onSelect(id)}
      className={cn(
        "grid min-h-11 place-items-center rounded-lg border",
        pressed ? "border-primary bg-primary text-primary-foreground" : "border-border bg-secondary text-foreground",
      )}
    >
      <Icon className="size-5" aria-hidden />
    </button>
  );
}