Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 106 additions & 15 deletions frontend/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,11 @@ function serverIconUrl(server) {

// A server's Discord CDN icon (the icon hash /api/me already returns), or a
// letter avatar when it has none or the image fails to load.
function ServerIcon({ guild }) {
function ServerIcon({ guild, size = 20 }) {
const url = serverIconUrl({ guild_id: guild.id, icon_hash: guild.icon });
const [failed, setFailed] = useState(null);
if (url && failed !== url)
return h("img", { className: "server-icon", src: url, alt: "", width: 20, height: 20, onError: () => setFailed(url) });
return h("img", { className: "server-icon", src: url, alt: "", width: size, height: size, onError: () => setFailed(url) });
const initial = Array.from(String(guild.name || "").trim())[0] || "?";
return h("span", { className: "server-icon server-icon-letter", "aria-hidden": "true" }, initial.toUpperCase());
}
Expand Down Expand Up @@ -2864,8 +2864,46 @@ function useWorkspaceNavOffsets(view, preview, showSubBar) {
return { main, banner, ribbon, header, subBar };
}

const RAIL_EXPANDED_STORAGE_KEY = "jmodguard.railExpanded";

function readRailExpanded() {
try {
return window.localStorage.getItem(RAIL_EXPANDED_STORAGE_KEY) === "true";
} catch (_) {
return false;
}
}

function writeRailExpanded(expanded) {
try {
window.localStorage.setItem(RAIL_EXPANDED_STORAGE_KEY, expanded ? "true" : "false");
} catch (_) {
/* Session still works when browser storage is blocked. */
}
}

function Workspace({ appearance }) {
const display = useStore(ui, selectWorkspace);
const [railExpanded, setRailExpanded] = useState(readRailExpanded);
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Resolved
const toggleRailExpanded = () => {
setRailExpanded((prev) => {
const next = !prev;
writeRailExpanded(next);
return next;
});
};

useEffect(() => {
const onStorage = (event) => {
if (event.key === RAIL_EXPANDED_STORAGE_KEY) {
setRailExpanded(event.newValue === "true");
} else if (event.key === null) {
setRailExpanded(false);
}
};
window.addEventListener("storage", onStorage);
return () => window.removeEventListener("storage", onStorage);
}, []);

useEffect(() => {
const beforeUnload = (event) => {
Expand Down Expand Up @@ -2929,37 +2967,81 @@ function Workspace({ appearance }) {
h(TelemetryRibbon, { display, ribbonRef: navigationRefs.ribbon }),
h(
"div",
{ className: "sf-body" },
{ className: `sf-body${railExpanded ? " sf-body-rail-expanded" : ""}` },
h(
"aside",
{ className: "sidebar sf-rail", "aria-label": "Servers and fleet" },
{
id: "server-rail",
className: `sidebar sf-rail${railExpanded ? " sf-rail-expanded" : ""}`,
"aria-label": "Servers and fleet",
"data-rail-expanded": railExpanded ? "true" : "false",
},
h(
"div",
{ className: "brand", title: "jModGuard" },
h("span", { className: "brand-mark", "aria-hidden": true }, "jG"),
{ className: "sf-rail-head" },
h(
"div",
{ className: "brand", title: "jModGuard" },
h("span", { className: "brand-mark", "aria-hidden": true }, "jG"),
railExpanded && h("span", { className: "sf-brand-name" }, "jModGuard"),
),
h(
UnstyledButton,
{
type: "button",
className: "sf-rail-toggle",
"data-rail-toggle": "true",
"aria-expanded": railExpanded ? "true" : "false",
"aria-controls": "server-rail",
"aria-label": railExpanded ? "Collapse server rail" : "Expand server rail",
title: railExpanded ? "Collapse server rail" : "Expand server rail",
onClick: toggleRailExpanded,
},
h(Icon, { name: railExpanded ? "chevron-left" : "chevron-right" }),
),
),
h("span", { className: "sf-rail-div", "aria-hidden": true }),
display.guilds.length > 0 && h(
"div",
{ className: "sf-rail-guilds", role: "group", "aria-label": "Switch server" },
...display.guilds.map((guild) => {
const selected = guild.id === display.guildId && activeHubId !== "fleet";
const statusText = guild.enrollment_status === "set_up"
? "Set up"
: guild.enrollment_status === "pending"
? "Pending"
: null;
const collapsedLabel = statusText ? `${guild.name} — ${statusText}` : guild.name;
return h(
ActionButton,
{
component: UnstyledButton,
key: guild.id,
className: `sf-srv-btn${selected ? " sf-srv-active" : ""}`,
"aria-label": guild.name,
"aria-label": railExpanded ? undefined : collapsedLabel,
"aria-current": selected ? "true" : undefined,
title: guild.name,
title: statusText ? `${guild.name} (${statusText})` : guild.name,
onClick: () => selectServerFromRail(guild.id),
},
h(ServerIcon, { guild }),
["set_up", "pending"].includes(guild.enrollment_status) && h("span", {
className: `sf-srv-dot${guild.enrollment_status === "pending" ? " sf-srv-dot-pending" : ""}`,
"aria-hidden": true,
}),
h(
"span",
{ className: "sf-srv-icon" },
h(ServerIcon, { guild, size: 32 }),
statusText && h("span", {
className: `sf-srv-dot${guild.enrollment_status === "pending" ? " sf-srv-dot-pending" : ""}`,
"aria-hidden": true,
}),
),
railExpanded && h(
"span",
{ className: "sf-srv-meta" },
h("span", { className: "sf-srv-name", title: guild.name }, guild.name),
statusText && h(
"span",
{ className: `sf-srv-status${guild.enrollment_status === "pending" ? " sf-srv-status-pending" : " sf-srv-status-ready"}` },
statusText,
),
),
);
}),
),
Expand All @@ -2972,12 +3054,21 @@ function Workspace({ appearance }) {
component: UnstyledButton,
className: `sf-srv-btn${activeHubId === "fleet" ? " sf-srv-active" : ""}`,
"data-rail-fleet": "true",
"aria-label": "Fleet and server access",
"aria-label": railExpanded ? undefined : "Fleet and server access",
"aria-current": activeHubId === "fleet" ? "true" : undefined,
title: "Fleet and server access",
onClick: () => navigate(fleetHub.items[0][0]),
},
h(Icon, { name: NAV_ICONS.administration.icon, intent: NAV_ICONS.administration.intent, className: "nav-icon" }),
h(
"span",
{ className: "sf-srv-icon" },
h(Icon, { name: NAV_ICONS.administration.icon, intent: NAV_ICONS.administration.intent, className: "nav-icon" }),
),
railExpanded && h(
"span",
{ className: "sf-srv-meta" },
h("span", { className: "sf-srv-name" }, "Fleet & Access"),
),
),
),
),
Expand Down
4 changes: 3 additions & 1 deletion frontend/icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ export const ICON_PATHS = {
clock: ["M3 12a9 9 0 1 0 18 0a9 9 0 1 0-18 0", "M12 7v5l3 2"],
"message-square": ["M5 4h14a1 1 0 0 1 1 1v10a1 1 0 0 1-1 1h-8l-5 4v-4H5a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1z"],
paperclip: ["M20 11l-8 8a5 5 0 0 1-7-7l8-8a3.5 3.5 0 0 1 5 5l-8 8a2 2 0 0 1-3-3l7-7"],
// Sorted table column direction.
// Sorted table column direction and rail collapse/expand toggle.
"chevron-down": ["M6 9l6 6l6-6"],
"chevron-up": ["M6 15l6-6l6 6"],
"chevron-left": ["M15 6l-6 6l6 6"],
"chevron-right": ["M9 6l6 6l-6 6"],
// Navigation.
"layout-grid": ["M4 4h6v6H4z", "M14 4h6v6h-6z", "M4 14h6v6H4z", "M14 14h6v6h-6z"],
"bar-chart": ["M4 4v16h16", "M9 16v-5", "M13 16V8", "M17 16v-3"],
Expand Down
Loading
Loading