| 1 |
export const categoryOrdering = (result, sortableCategories, currentPage, perPage) => { |
| 2 |
const cats = sortableCategories.map((cat) => ({ |
| 3 |
id: cat?.id, |
| 4 |
current_position: cat?.meta?.order[0], |
| 5 |
})); |
| 6 |
let reOrderedCats = []; |
| 7 |
let startIndex = currentPage != 1 ? ((( perPage * currentPage ) + 1) - 10) : currentPage; |
| 8 |
cats?.splice(result?.destination?.index, 0, ...cats?.splice(result?.source?.index, 1)); |
| 9 |
for( let i = 0; i < cats?.length; i++ ) { |
| 10 |
reOrderedCats.push({ |
| 11 |
...cats[i], |
| 12 |
updated_position: (startIndex).toString(), |
| 13 |
}); |
| 14 |
startIndex++; |
| 15 |
} |
| 16 |
return reOrderedCats; |
| 17 |
} |
| 18 |
|
| 19 |
export const faqOrdering = (result, sortedFaqList) => { |
| 20 |
const startIndex = result.source.index; |
| 21 |
const endIndex = result.destination.index; |
| 22 |
|
| 23 |
let data = [...sortedFaqList]; |
| 24 |
let [removed] = data.splice(startIndex, 1); |
| 25 |
data.splice(endIndex, 0, removed); |
| 26 |
return data; |
| 27 |
}; |
| 28 |
|