Files

33 lines
1.1 KiB
TypeScript
Raw Permalink Normal View History

2024-11-27 05:41:06 +01:00
import {createSortable} from '../modules/sortable.ts';
import {POST} from '../modules/fetch.ts';
import {showErrorToast} from '../modules/toast.ts';
import {queryElemChildren} from '../utils/dom.ts';
export function initRepoSettingsBranchesDrag() {
2026-02-02 01:00:34 +08:00
const protectedBranchesList = document.querySelector<HTMLElement>('#protected-branches-list');
2024-11-27 05:41:06 +01:00
if (!protectedBranchesList) return;
createSortable(protectedBranchesList, {
handle: '.drag-handle',
animation: 150,
onEnd: () => {
(async () => {
const itemElems = queryElemChildren(protectedBranchesList, '.item[data-id]');
2025-12-03 03:13:16 +01:00
const itemIds = Array.from(itemElems, (el) => parseInt(el.getAttribute('data-id')!));
2024-11-27 05:41:06 +01:00
try {
2025-12-03 03:13:16 +01:00
await POST(protectedBranchesList.getAttribute('data-update-priority-url')!, {
2024-11-27 05:41:06 +01:00
data: {
ids: itemIds,
},
});
} catch (err) {
const errorMessage = String(err);
showErrorToast(`Failed to update branch protection rule priority:, error: ${errorMessage}`);
}
})();
},
});
}