Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
16 changes: 9 additions & 7 deletions src/app/(dashboard)/dashboard/settings/components/ProxyTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@ import DocumentationTab from "./proxy/DocumentationTab";

type TabId = "global-config" | "proxy-pool" | "free-pool" | "documentation";

const TABS: Array<{ id: TabId; labelKey: string }> = [
{ id: "global-config", labelKey: "proxyGlobalConfigTab" },
{ id: "proxy-pool", labelKey: "proxyPoolTab" },
{ id: "free-pool", labelKey: "freePoolTab" },
{ id: "documentation", labelKey: "proxyDocumentationTab" },
const TABS: Array<{ id: TabId; labelKey: string; fallback: string }> = [
{ id: "global-config", labelKey: "proxyGlobalConfigTab", fallback: "Global config" },
{ id: "proxy-pool", labelKey: "proxyPoolTab", fallback: "Proxy pool" },
{ id: "free-pool", labelKey: "freePoolTab", fallback: "Free pool" },
{ id: "documentation", labelKey: "proxyDocumentationTab", fallback: "Documentation" },
];

export default function ProxyTab() {
const t = useTranslations("settings");
const searchParams = useSearchParams();
const router = useRouter();
const pathname = usePathname();
const translateOrFallback = (key: string, fallback: string) =>
typeof t.has === "function" && !t.has(key) ? fallback : t(key);

const activeTab = useMemo<TabId>(() => {
const tabParam = searchParams.get("tab") as TabId | null;
Expand All @@ -38,7 +40,7 @@ export default function ProxyTab() {
<div
className="flex gap-1 border-b border-border overflow-x-auto"
role="tablist"
aria-label={t("proxySubTabsAria")}
aria-label={translateOrFallback("proxySubTabsAria", "Proxy sections")}
>
{TABS.map((tab) => (
<button
Expand All @@ -52,7 +54,7 @@ export default function ProxyTab() {
: "border-transparent text-text-muted hover:text-text"
}`}
>
{t(tab.labelKey)}
{translateOrFallback(tab.labelKey, tab.fallback)}
</button>
))}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ const MAX_VISIBLE_PAGES = 7;

export default function FreePoolTab() {
const t = useTranslations("settings");
const translateOrFallback = (
key: string,
fallback: string,
values?: Record<string, string | number>
) => (typeof t.has === "function" && !t.has(key) ? fallback : t(key, values));
const [proxies, setProxies] = useState<FreeProxyRowData[]>([]);
const [stats, setStats] = useState<FreePoolStats | null>(null);
const [disabledSources, setDisabledSources] = useState<Set<SourceId>>(new Set());
Expand Down Expand Up @@ -222,9 +227,9 @@ export default function FreePoolTab() {
value={filterProtocol}
onChange={(e) => setFilterProtocol(e.target.value)}
className="text-xs bg-surface-alt border border-border rounded px-2 py-1"
aria-label={t("proxyFreePoolFilterProtocol")}
aria-label={translateOrFallback("proxyFreePoolFilterProtocol", "Filter by protocol")}
>
<option value="">{t("proxyFreePoolProtocol")}</option>
<option value="">{translateOrFallback("proxyFreePoolProtocol", "Protocol")}</option>
{["http", "https", "socks4", "socks5"].map((p) => (
<option key={p} value={p}>
{p.toUpperCase()}
Expand All @@ -233,44 +238,54 @@ export default function FreePoolTab() {
</select>
<input
type="text"
placeholder={t("proxyFreePoolCountryPlaceholder")}
placeholder={translateOrFallback(
"proxyFreePoolCountryPlaceholder",
"Country (e.g. US)"
)}
value={filterCountry}
onChange={(e) => setFilterCountry(e.target.value.toUpperCase().slice(0, 2))}
className="text-xs bg-surface-alt border border-border rounded px-2 py-1 w-28"
aria-label={t("proxyFreePoolFilterCountry")}
aria-label={translateOrFallback("proxyFreePoolFilterCountry", "Filter by country")}
/>
<input
type="number"
placeholder={t("proxyFreePoolMinQualityPlaceholder")}
placeholder={translateOrFallback("proxyFreePoolMinQualityPlaceholder", "Min quality")}
value={minQuality}
onChange={(e) => setMinQuality(e.target.value)}
min={0}
max={100}
className="text-xs bg-surface-alt border border-border rounded px-2 py-1 w-24"
aria-label={t("proxyFreePoolMinQualityLabel")}
aria-label={translateOrFallback(
"proxyFreePoolMinQualityLabel",
"Minimum quality score"
)}
/>
<Button size="sm" variant="secondary" icon="sync" onClick={handleSync} disabled={syncing}>
{syncing ? t("syncing") : t("proxyFreePoolSyncAll")}
{syncing
? translateOrFallback("syncing", "Syncing...")
: translateOrFallback("proxyFreePoolSyncAll", "Sync all")}
</Button>
</div>
</div>

{stats && (
<div className="text-xs text-text-muted flex gap-4 flex-wrap">
<span>
{t("proxyFreePoolTotal")}: {stats.total}
{translateOrFallback("proxyFreePoolTotal", "Total")}: {stats.total}
</span>
<span>
{t("proxyFreePoolInPool")}: {stats.inPool}
{translateOrFallback("proxyFreePoolInPool", "In pool")}: {stats.inPool}
</span>
{stats.avgQuality != null && (
<span>
{t("proxyFreePoolAvgQuality")}: {stats.avgQuality}
{translateOrFallback("proxyFreePoolAvgQuality", "Average quality")}:{" "}
{stats.avgQuality}
</span>
)}
{stats.lastSyncAt && (
<span>
{t("lastSync")}: {new Date(stats.lastSyncAt).toLocaleTimeString()}
{translateOrFallback("lastSync", "Last sync")}:{" "}
{new Date(stats.lastSyncAt).toLocaleTimeString()}
</span>
)}
Comment thread
JxnLexn marked this conversation as resolved.
Resolved
</div>
Expand All @@ -292,9 +307,13 @@ export default function FreePoolTab() {

{selected.size > 0 && (
<div className="flex items-center gap-2 p-2 bg-primary/10 rounded border border-primary/20">
<span className="text-xs">{t("proxyFreePoolSelected", { count: selected.size })}</span>
<span className="text-xs">
{translateOrFallback("proxyFreePoolSelected", `${selected.size} selected`, {
count: selected.size,
})}
</span>
<Button size="sm" variant="primary" onClick={() => handleBulkAdd(Array.from(selected))}>
{t("proxyFreePoolAddSelected")}
{translateOrFallback("proxyFreePoolAddSelected", "Add selected to pool")}
</Button>
{bulkProgress && <span className="text-xs text-text-muted">{bulkProgress}</span>}
</div>
Expand All @@ -307,7 +326,7 @@ export default function FreePoolTab() {
variant="secondary"
onClick={() => handleBulkAdd(notInPoolProxies.slice(0, 100).map((p) => p.id))}
>
{t("proxyFreePoolAddVisible")}
{translateOrFallback("proxyFreePoolAddVisible", "Add all visible to pool")}
</Button>
</div>
)}
Expand All @@ -318,22 +337,22 @@ export default function FreePoolTab() {
<tr>
<th className="px-3 py-2 text-left w-8" scope="col"></th>
<th className="px-3 py-2 text-left" scope="col">
{t("proxyFreePoolSource")}
{translateOrFallback("proxyFreePoolSource", "Source")}
</th>
<th className="px-3 py-2 text-left" scope="col">
{t("proxyFreePoolHostPort")}
{translateOrFallback("proxyFreePoolHostPort", "Host:Port")}
</th>
<th className="px-3 py-2 text-left" scope="col">
{t("proxyFreePoolType")}
{translateOrFallback("proxyFreePoolType", "Type")}
</th>
<th className="px-3 py-2 text-left" scope="col">
{t("proxyFreePoolCountry")}
{translateOrFallback("proxyFreePoolCountry", "Country")}
</th>
<th className="px-3 py-2 text-left" scope="col">
{t("proxyFreePoolQuality")}
{translateOrFallback("proxyFreePoolQuality", "Quality")}
</th>
<th className="px-3 py-2 text-left" scope="col">
{t("proxyFreePoolLatency")}
{translateOrFallback("proxyFreePoolLatency", "Latency")}
</th>
<th className="px-3 py-2 text-left" scope="col"></th>
</tr>
Expand All @@ -342,13 +361,16 @@ export default function FreePoolTab() {
{loading ? (
<tr>
<td colSpan={8} className="px-3 py-8 text-center text-text-muted">
{t("loading")}
{translateOrFallback("loading", "Loading...")}
</td>
</tr>
) : proxies.length === 0 ? (
<tr>
<td colSpan={8} className="px-3 py-8 text-center text-text-muted">
{t("proxyFreePoolEmpty")}
{translateOrFallback(
"proxyFreePoolEmpty",
"No proxies found. Click Sync all to fetch from sources."
)}
</td>
</tr>
) : (
Expand Down
26 changes: 25 additions & 1 deletion src/i18n/messages/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -4509,7 +4509,7 @@
"proxy": "Stellvertreter",
"httpProxy": "HTTP Proxy",
"1proxy": "1proxy",
"proxySubTabsAria": "Proxy sections",
"proxySubTabsAria": "Proxy-Bereiche",
"requestBodyLimitTitle": "Request Body Limit",
"requestBodyLimitDescription": "Maximum API payload size accepted before a request body is parsed. Dedicated upload routes keep at least their built-in 100 MB limit.",
"requestBodyLimitInputLabel": "Request body limit in MB",
Expand Down Expand Up @@ -4561,6 +4561,30 @@
"syncNow": "Sync Now",
"syncing": "Syncing...",
"lastSync": "Last sync",
"proxyGlobalConfigTab": "Globale Konfiguration",
"proxyPoolTab": "Proxy-Pool",
"freePoolTab": "Kostenloser Pool",
"proxyDocumentationTab": "Dokumentation",
"proxyFreePoolFilterProtocol": "Nach Protokoll filtern",
"proxyFreePoolProtocol": "Protokoll",
"proxyFreePoolCountryPlaceholder": "Land (z. B. DE)",
"proxyFreePoolFilterCountry": "Nach Land filtern",
"proxyFreePoolMinQualityPlaceholder": "Mindestqualität",
"proxyFreePoolMinQualityLabel": "Minimale Qualitätsbewertung",
"proxyFreePoolSyncAll": "Alle synchronisieren",
"proxyFreePoolTotal": "Gesamt",
"proxyFreePoolInPool": "Im Pool",
"proxyFreePoolAvgQuality": "Durchschnittliche Qualität",
"proxyFreePoolSelected": "{count} ausgewählt",
"proxyFreePoolAddSelected": "Ausgewählte zum Pool hinzufügen",
"proxyFreePoolAddVisible": "Alle sichtbaren zum Pool hinzufügen",
"proxyFreePoolSource": "Quelle",
"proxyFreePoolHostPort": "Host:Port",
"proxyFreePoolType": "Typ",
"proxyFreePoolCountry": "Land",
"proxyFreePoolQuality": "Qualität",
"proxyFreePoolLatency": "Latenz",
"proxyFreePoolEmpty": "Keine Proxys gefunden. Klicke auf „Alle synchronisieren“, um sie aus den Quellen abzurufen.",
"never": "Never",
"justNow": "gerade jetzt",
"modelsDevStats": "Sync Statistics",
Expand Down
41 changes: 15 additions & 26 deletions src/shared/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import { usePathname } from "next/navigation";
import { cn } from "@/shared/utils/cn";
import { getActiveSidebarHref } from "@/shared/utils/sidebarRouteMatch";
import { filterSidebarSectionsByQuery } from "@/shared/utils/sidebarSearch";
import {
expandActiveSection,
hydrateExpandedSections,
toggleExpandedSection,
} from "@/shared/utils/sidebarExpansionState";
import { APP_CONFIG } from "@/shared/constants/appConfig";
import OmniRouteLogo from "./OmniRouteLogo";
import Button from "./Button";
Expand Down Expand Up @@ -102,10 +107,11 @@ export default function Sidebar({
new Set([DEFAULT_EXPANDED])
);
const [pinnedSections, setPinnedSections] = useState<Set<SidebarSectionId>>(new Set());
const [sidebarExpansionLoaded, setSidebarExpansionLoaded] = useState(false);
const [hoveredItem, setHoveredItem] = useState<HoveredItem>(null);
const [searchQuery, setSearchQuery] = useState("");

// Load persisted state on mount; OmniProxy is pinned by default on first visit
// Load persisted state on mount. A stored [] intentionally means "all sections collapsed".
useEffect(() => {
const storedExpanded = loadFromStorage<SidebarSectionId[]>(EXPANDED_SECTIONS_KEY, [
DEFAULT_EXPANDED,
Expand All @@ -122,15 +128,12 @@ export default function Sidebar({
? (JSON.parse(pinnedRaw) as SidebarSectionId[])
: (SIDEBAR_SECTIONS.filter((s) => s.defaultPinned).map((s) => s.id) as SidebarSectionId[]);

const initialExpanded = new Set<SidebarSectionId>(
storedExpanded.length > 0 ? storedExpanded : [DEFAULT_EXPANDED]
);
const initialPinned = new Set<SidebarSectionId>(storedPinned);
// Pinned sections must also be expanded
for (const id of initialPinned) initialExpanded.add(id);
const initialExpanded = hydrateExpandedSections(storedExpanded, initialPinned);

setExpandedSections(initialExpanded);
setPinnedSections(initialPinned);
setSidebarExpansionLoaded(true);
}, []);

useEffect(() => {
Expand Down Expand Up @@ -274,45 +277,31 @@ export default function Sidebar({
? filterSidebarSectionsByQuery(visibleSections, searchQuery)
: visibleSections;

// Auto-expand the section containing the active page (without closing others)
// Keep the active page visible while preserving accordion semantics for unpinned sections.
useEffect(() => {
if (collapsed) return;
if (collapsed || !sidebarExpansionLoaded) return;
for (const section of visibleSections) {
const sectionItems = section.children.flatMap((child: any) =>
child.type === "group" ? child.items : [child]
);
if (sectionItems.some((item: any) => !item.external && item.href === activeHref)) {
setExpandedSections((prev) => {
if (prev.has(section.id as SidebarSectionId)) return prev;
const next = new Set(prev);
next.add(section.id as SidebarSectionId);
const next = expandActiveSection(pinnedSections, section.id as SidebarSectionId);
if ([...next].every((id) => prev.has(id)) && next.size === prev.size) return prev;
saveToStorage(EXPANDED_SECTIONS_KEY, [...next]);
Comment thread
JxnLexn marked this conversation as resolved.
Resolved
return next;
});
break;
}
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [activeHref, collapsed]);
}, [activeHref, collapsed, pinnedSections, sidebarExpansionLoaded]);

// Accordion toggle: opening a section closes all non-pinned sections
const toggleSection = useCallback(
(sectionId: SidebarSectionId) => {
setExpandedSections((prev) => {
const isOpen = prev.has(sectionId);
let next: Set<SidebarSectionId>;
if (isOpen) {
// Close this section
next = new Set(prev);
next.delete(sectionId);
} else {
// Accordion: keep only pinned sections + the new one
next = new Set<SidebarSectionId>();
for (const id of pinnedSections) {
next.add(id);
}
next.add(sectionId);
}
const next = toggleExpandedSection(prev, pinnedSections, sectionId);
saveToStorage(EXPANDED_SECTIONS_KEY, [...next]);
return next;
});
Expand Down
5 changes: 3 additions & 2 deletions src/shared/constants/sidebarVisibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ export { COMPRESSION_CONTEXT_GROUP, SIDEBAR_SECTIONS } from "./sidebarVisibility
import { HIDEABLE_SIDEBAR_ITEM_IDS } from "./sidebarVisibility/types";
import type {
HideableSidebarItemId,
SidebarItemId,
SidebarSectionId,
SidebarItemDefinition,
SidebarSectionChild,
SidebarSectionDefinition,
SidebarPresetDefinition,
} from "./sidebarVisibility/types";

export const SIDEBAR_ICON_ACCENTS: Partial<Record<HideableSidebarItemId, string>> = {
export const SIDEBAR_ICON_ACCENTS: Partial<Record<SidebarItemId, string>> = {
home: "#60A5FA",
"api-manager": "#F59E0B",
endpoints: "#38BDF8",
Expand Down Expand Up @@ -117,7 +118,7 @@ function getDeterministicIconAccent(id: string): string {

export function getSidebarIconAccent(id: string): string {
return (
SIDEBAR_ICON_ACCENTS[id as HideableSidebarItemId] ||
SIDEBAR_ICON_ACCENTS[id as SidebarItemId] ||
SIDEBAR_SUBITEM_ICON_ACCENTS[id] ||
getDeterministicIconAccent(id)
);
Expand Down
1 change: 0 additions & 1 deletion src/shared/constants/sidebarVisibility/sections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,6 @@ export const SIDEBAR_SECTIONS: readonly SidebarSectionDefinition[] = [
INTEGRATIONS_GROUP,
PROXY_ITEM,
],
defaultPinned: true,
},
{
id: "analytics",
Expand Down
Loading