restruct: stock list components

This commit is contained in:
2025-03-09 15:40:22 +01:00
parent 82a016dca7
commit 862aebb158
12 changed files with 943 additions and 745 deletions
+38
View File
@@ -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 };
};