mirror of
https://github.com/Spythere/pojazdownik.git
synced 2026-05-03 19:48:11 +00:00
restruct: stock list components
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
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 };
|
||||
};
|
||||
Reference in New Issue
Block a user