App.ComboLibrary = function ComboLibrary() {
const [combos, setCombos] = React.useState([]);
const [myCombos, setMyCombos] = React.useState([]);
const [loading, setLoading] = React.useState(true);
const [page, setPage] = React.useState(1);
const [totalPages, setTotalPages] = React.useState(1);
const [deleteModal, setDeleteModal] = React.useState(null); // { comboId, comboName, step: 'confirm' | 'in_use', polls: [] }
const loadCombos = (p) => {
setLoading(true);
App.API.get('combos?page=' + p + '&limit=20&fingerprint=' + App.fingerprint).then(data => {
setCombos(data.combos);
setMyCombos(data.myCombos || []);
setTotalPages(data.pages || 1);
setLoading(false);
});
};
React.useEffect(() => { loadCombos(page); }, [page]);
const handleDeleteRequest = (comboId, comboName) => {
setDeleteModal({ comboId: comboId, comboName: comboName, step: 'confirm', polls: [] });
};
const handleDeleteConfirm = () => {
if (!deleteModal) return;
App.API.post('combos/' + deleteModal.comboId, {
_action: 'delete',
fingerprint: App.fingerprint,
})
.then((data) => {
if (data.error === 'in_use') {
setDeleteModal(prev => ({ ...prev, step: 'in_use', polls: data.polls || [] }));
} else {
setDeleteModal(null);
loadCombos(page);
}
})
.catch(err => {
setDeleteModal(null);
alert(err.message);
});
};
if (loading) return
Browse and manage race combinations
{myCombos.length > 0 && (No community combos yet. Be the first to create one!
Create Race ComboAre you sure you want to delete "{deleteModal.comboName}"?
"{deleteModal.comboName}" is used in the following polls. Remove it from these polls first: