feat(hosts): add drag-and-drop and global subscription ordering (#6895)

Hosts already had one saved order on the Hosts page, but subscriptions honoured
it only inside each inbound, so a host of a later inbound could never come before
one of an earlier inbound (#6894). A new opt-in setting makes raw/base64,
Clash/Mihomo and JSON subscriptions follow the Hosts page order across inbounds;
the default keeps today's inbound-first output unchanged. The Hosts table gains
drag-and-drop reordering next to the Up/Down buttons, on a pointer-reorder hook
the Routing Rules table now shares.
This commit is contained in:
Hamed
2026-10-24 08:57:47 +03:30
committed by GitHub
parent a69ae2b0ea
commit 136c1c4d50
51 changed files with 1643 additions and 149 deletions
+35 -4
View File
@@ -1,4 +1,4 @@
import { useCallback, useEffect, useMemo, useState } from 'react';
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
import {
Button,
@@ -45,6 +45,35 @@ export default function HostsPage() {
const [formMode, setFormMode] = useState<'add' | 'edit'>('add');
const [formHost, setFormHost] = useState<HostRecord | null>(null);
const [selectedGroupIds, setSelectedGroupIds] = useState<string[]>([]);
const [pendingOrder, setPendingOrder] = useState<string[] | null>(null);
const savingOrder = useRef(false);
const visibleHosts = useMemo(
() =>
pendingOrder
? hosts.map((h) => ({ ...h, sortOrder: pendingOrder.indexOf(h.groupId) }))
: hosts,
[hosts, pendingOrder],
);
const onReorder = useCallback(
async (groupIds: string[]) => {
const current = sortHosts(hosts).map((h) => h.groupId);
if (savingOrder.current || current.every((id, i) => id === groupIds[i])) return;
savingOrder.current = true;
setPendingOrder(groupIds);
try {
const msg = await reorder(groupIds);
if (msg?.success) messageApi.success(t('pages.hosts.toasts.update'));
else messageApi.error(msg?.msg || t('somethingWentWrong'));
} catch {
messageApi.error(t('somethingWentWrong'));
} finally {
savingOrder.current = false;
setPendingOrder(null);
}
},
[hosts, reorder, messageApi, t],
);
const onAdd = useCallback(() => {
setFormMode('add');
@@ -99,9 +128,9 @@ export default function HostsPage() {
if (idx < 0 || swapWith < 0 || swapWith >= sorted.length) return;
const groupIds = sorted.map((h) => h.groupId);
[groupIds[idx], groupIds[swapWith]] = [groupIds[swapWith], groupIds[idx]];
await reorder(groupIds);
await onReorder(groupIds);
},
[hosts, reorder],
[hosts, onReorder],
);
const onBulkEnable = useCallback(
@@ -207,7 +236,7 @@ export default function HostsPage() {
<Col span={24}>
<HostList
hosts={hosts}
hosts={visibleHosts}
inboundOptions={inboundOptions}
loading={loading}
isMobile={isMobile}
@@ -218,6 +247,8 @@ export default function HostsPage() {
onDelete={onDelete}
onToggleEnable={onToggleEnable}
onMove={onMove}
onReorder={onReorder}
reordering={pendingOrder !== null}
onBulkEnable={onBulkEnable}
onBulkDelete={onBulkDelete}
/>