diff --git a/src/stores/utils/index.ts b/src/stores/utils/index.ts index 1e483a09..35fa356e 100644 --- a/src/stores/utils/index.ts +++ b/src/stores/utils/index.ts @@ -96,20 +96,20 @@ export function notify( } } -export function moveItemUp(items: unknown[], index: number) { - if (index > 0) { - const temp = items[index]; - items[index] = items[index - 1]; - items[index - 1] = temp; - } +export function moveItem( + arr: T, + idx: number, + offset: number, +) { + arr.splice(idx + offset, 0, ...arr.splice(idx, 1)); } -export function moveItemDown(items: unknown[], index: number) { - if (index < items.length - 1) { - const temp = items[index]; - items[index] = items[index + 1]; - items[index + 1] = temp; - } +export function moveItemUp(items: T, index: number) { + moveItem(items, index, -1); +} + +export function moveItemDown(items: T, index: number) { + moveItem(items, index, 1); } export function deleteItem(items: unknown[], index: number) { @@ -504,4 +504,17 @@ export function calculateDaysUntilExpire(expireDate: Date): number { return diffInDays; } +export function createDataRefBase( + defaultPage = 1, + defaultPageMax = 1, + defaultPageSize = 30, +) { + return { + data: ref(), + page: ref(defaultPage), + pageMax: ref(defaultPageMax), + pageSize: ref(defaultPageSize), + }; +} + export default useUtilsStore;