1
0
Fork 0
mirror of https://github.com/s-frick/effigenix.git synced 2026-03-28 15:49:35 +01:00
effigenix/frontend/apps/cli/src/hooks/useStockNameLookup.ts
Sebastian Frick e25d4437d9 feat(tui): Stock-Suche mit Namensanzeige für Bestände
StockPicker-Komponente für Bestandssuche nach Artikel-/Lagerort-Namen.
StockBatchEntryScreen nutzt StockPicker statt manueller UUID-Eingabe.
StockListScreen mit Suchfilter [s] und Namensanzeige statt IDs.
StockDetailScreen zeigt Artikel-/Lagerort-Namen im Header.
2026-02-24 01:21:02 +01:00

37 lines
1.1 KiB
TypeScript

import { useEffect, useMemo, useCallback } from 'react';
import { useArticles } from './useArticles.js';
import { useStorageLocations } from './useStorageLocations.js';
export function useStockNameLookup() {
const { articles, fetchArticles } = useArticles();
const { storageLocations, fetchStorageLocations } = useStorageLocations();
useEffect(() => {
void fetchArticles();
void fetchStorageLocations();
}, [fetchArticles, fetchStorageLocations]);
const articleNames = useMemo(() => {
const map = new Map<string, string>();
for (const a of articles) map.set(a.id, a.name);
return map;
}, [articles]);
const locationNames = useMemo(() => {
const map = new Map<string, string>();
for (const l of storageLocations) map.set(l.id, l.name);
return map;
}, [storageLocations]);
const articleName = useCallback(
(id: string) => articleNames.get(id) ?? id.substring(0, 8) + '…',
[articleNames],
);
const locationName = useCallback(
(id: string) => locationNames.get(id) ?? id.substring(0, 8) + '…',
[locationNames],
);
return { articleName, locationName };
}