mirror of
https://github.com/Spythere/pojazdownik.git
synced 2026-05-03 11:45:34 +00:00
39 lines
978 B
TypeScript
39 lines
978 B
TypeScript
import { useStore } from '../store';
|
|
|
|
export const useStockListUtils = () => {
|
|
const store = useStore();
|
|
|
|
function removeStock(index: number) {
|
|
if (index == -1) return;
|
|
|
|
store.stockList = store.stockList.filter((stock, i) => i != index);
|
|
|
|
if (store.stockList.length < index + 1) store.chosenStockListIndex = -1;
|
|
}
|
|
|
|
function moveUpStock(index: number) {
|
|
if (index < 1) return;
|
|
|
|
const tempStock = store.stockList[index];
|
|
|
|
store.stockList[index] = store.stockList[index - 1];
|
|
store.stockList[index - 1] = tempStock;
|
|
|
|
store.chosenStockListIndex = index - 1;
|
|
}
|
|
|
|
function moveDownStock(index: number) {
|
|
if (index == -1) return;
|
|
if (index > store.stockList.length - 2) return;
|
|
|
|
const tempStock = store.stockList[index];
|
|
|
|
store.stockList[index] = store.stockList[index + 1];
|
|
store.stockList[index + 1] = tempStock;
|
|
|
|
store.chosenStockListIndex = index + 1;
|
|
}
|
|
|
|
return { removeStock, moveDownStock, moveUpStock };
|
|
};
|