Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
65 changes: 54 additions & 11 deletions src/app/(dashboard)/dashboard/settings/components/SidebarTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ import {
applySectionOrder,
applyItemOrder,
normalizeHiddenSidebarItems,
HIDEABLE_SIDEBAR_ITEM_IDS,
type HideableSidebarItemId,
type SidebarItemId,
type SidebarSectionId,
type SidebarItemOrder,
type SidebarPresetId,
Expand Down Expand Up @@ -215,11 +217,48 @@ interface ItemRowProps {
}

// Items that must always remain visible (safety guard)
const PROTECTED_ITEM_IDS = new Set(["settings-sidebar"]);
const PROTECTED_ITEM_IDS = new Set<SidebarItemId>(["proxy", "settings-sidebar"]);

function isHideableSidebarItemId(id: SidebarItemId): id is HideableSidebarItemId {
return HIDEABLE_SIDEBAR_ITEM_IDS.includes(id as HideableSidebarItemId);
}

function GroupItemVisibilityControl({
item,
hiddenSet,
onToggleItem,
}: {
item: SidebarItemDefinition;
hiddenSet: Set<HideableSidebarItemId>;
onToggleItem: (id: HideableSidebarItemId) => void;
}) {
const tSidebar = useTranslations("sidebar");
const hideableId = isHideableSidebarItemId(item.id) ? item.id : null;
if (hideableId !== null) {
return (
<Toggle
size="sm"
checked={!hiddenSet.has(hideableId)}
onChange={() => onToggleItem(hideableId)}
/>
);
}

return (
<span
className="material-symbols-outlined text-[16px] text-text-muted/40"
title={tSidebar("cannotHide")}
aria-label={tSidebar("alwaysVisible")}
>
lock
</span>
);
}

function ItemRow({ item, hiddenSet, onToggleItem, getLabel }: ItemRowProps) {
const tSidebar = useTranslations("sidebar");
const isProtected = PROTECTED_ITEM_IDS.has(item.id);
const hideableId = isHideableSidebarItemId(item.id) ? item.id : null;
const isProtected = PROTECTED_ITEM_IDS.has(item.id) || hideableId === null;
return (
<div className="flex items-center justify-between gap-4 px-4 py-3">
<div className="flex items-center gap-2 min-w-0">
Expand All @@ -237,7 +276,7 @@ function ItemRow({ item, hiddenSet, onToggleItem, getLabel }: ItemRowProps) {
lock
</span>
) : (
<Toggle checked={!hiddenSet.has(item.id)} onChange={() => onToggleItem(item.id)} />
<Toggle checked={!hiddenSet.has(hideableId)} onChange={() => onToggleItem(hideableId)} />
)}
</div>
);
Expand Down Expand Up @@ -288,7 +327,8 @@ function GroupRow({
</span>
</button>
<span className="text-xs text-text-muted/40">
{group.items.filter((i) => !hiddenSet.has(i.id)).length}/{group.items.length}
{group.items.filter((i) => !isHideableSidebarItemId(i.id) || !hiddenSet.has(i.id)).length}/
{group.items.length}
</span>
{canToggleSeparator && (
<div className="flex items-center gap-2 border-l border-border/60 pl-3">
Expand All @@ -311,10 +351,10 @@ function GroupRow({
</span>
<p className="text-sm font-medium truncate">{getLabel(item.i18nKey, item.id)}</p>
</div>
<Toggle
size="sm"
checked={!hiddenSet.has(item.id)}
onChange={() => onToggleItem(item.id)}
<GroupItemVisibilityControl
Comment thread
JxnLexn marked this conversation as resolved.
Resolved
item={item}
hiddenSet={hiddenSet}
onToggleItem={onToggleItem}
/>
</div>
))}
Expand Down Expand Up @@ -418,11 +458,14 @@ export default function SidebarTab() {
patch({ [HIDDEN_SIDEBAR_GROUP_LABELS_SETTING_KEY]: next, [SIDEBAR_PRESET_KEY]: null });
};

const visibleSections = SIDEBAR_SECTIONS.filter((s) => s.visibility !== "debug" || showDebug).map(
(s) => ({ ...s, title: getLabel(s.titleKey, s.titleFallback) })
const visibleSections = SIDEBAR_SECTIONS.filter(
(s) => s.visibility !== "debug" || showDebug
);

const orderedSections = applySectionOrder(visibleSections, sectionOrder);
const orderedSections = applySectionOrder(visibleSections, sectionOrder).map((s) => ({
...s,
title: getLabel(s.titleKey, s.titleFallback),
}));

const sectionIds = orderedSections.map((s) => s.id);

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()}
<span suppressHydrationWarning>
{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
Loading
Loading