Fixes for a few oddities and the Traefik issues
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-01-24 17:18:42 -05:00
parent 4a0fe47000
commit ef2846f626
4 changed files with 66 additions and 38 deletions

View File

@@ -18,29 +18,29 @@ export function Bins() {
switch (event.key) { switch (event.key) {
case 'ArrowDown': case 'ArrowDown':
event.preventDefault(); event.preventDefault();
setBin(Bin.LOSS); !!item && setBin(Bin.LOSS);
break; break;
case 'ArrowLeft': case 'ArrowLeft':
event.preventDefault(); event.preventDefault();
setBin(Bin.PROCESS); !!item && setBin(Bin.PROCESS);
break; break;
case 'ArrowRight': case 'ArrowRight':
event.preventDefault(); event.preventDefault();
setBin(Bin.SHOULDER_TAP); !!item && setBin(Bin.SHOULDER_TAP);
break; break;
case 'ArrowUp': case 'ArrowUp':
event.preventDefault(); event.preventDefault();
setBin(Bin.DONATE); !!item && setBin(Bin.DONATE);
break; break;
} }
}, [bin, item, setBin, setItem]); }, [item, setBin]);
useEffect(() => { useEffect(() => {
window.addEventListener('keydown', handleKeydown); window.addEventListener('keydown', handleKeydown);
return () => { return () => {
window.removeEventListener('keydown', handleKeydown); window.removeEventListener('keydown', handleKeydown);
}; };
}, []); }, [handleKeydown]);
return ( return (
<div className={styles.bins}> <div className={styles.bins}>

View File

@@ -15,7 +15,6 @@ export function ProductInfo() {
const { item, setItem } = useContext(BinnerContext); const { item, setItem } = useContext(BinnerContext);
const { processors } = useContext(SupplyChainContext); const { processors } = useContext(SupplyChainContext);
const [inputItem, setInputItem] = useState<Partial<ParsedBarcode> | null>(null); const [inputItem, setInputItem] = useState<Partial<ParsedBarcode> | null>(null);
const dateRef = useRef<HTMLInputElement>(null);
const weightRef = useRef<HTMLInputElement>(null); const weightRef = useRef<HTMLInputElement>(null);
const getProcessorByBarcodeId = useGetProcessorByBarcodeId(); const getProcessorByBarcodeId = useGetProcessorByBarcodeId();
@@ -24,16 +23,32 @@ export function ProductInfo() {
const [isEntryMode, setIsEntryMode] = useState(!isCompleteItem(item)); const [isEntryMode, setIsEntryMode] = useState(!isCompleteItem(item));
useEffect(() => { useEffect(() => {
console.log('item', { item, complete: isCompleteItem(item) });
setIsEntryMode(!isCompleteItem(item)); setIsEntryMode(!isCompleteItem(item));
}, [item]) }, [item])
useEffect(() => { useEffect(() => {
if (isCompleteItem(inputItem)) { if (isCompleteItem(inputItem)) {
console.log('inputItem', { inputItem, barcode: `${inputItem?.product}${inputItem?.date}${inputItem?.processor}${inputItem?.weight}` });
setItem(barcodeToProduct(`${inputItem?.product}${inputItem?.date}${inputItem?.processor}${inputItem?.weight}`)); setItem(barcodeToProduct(`${inputItem?.product}${inputItem?.date}${inputItem?.processor}${inputItem?.weight}`));
setInputItem(null); setInputItem(null);
} }
setIsEntryMode(!isCompleteItem(inputItem)); }, [inputItem]);
}, [inputItem])
const getDateString = (date: Date) => {
const yyyy = date.getFullYear();
let mm: number | string = date.getMonth() + 1;
let dd: number | string = date.getDate();
if (dd < 10) {
dd = '0' + dd;
}
if (mm < 10) {
mm = '0' + mm;
}
return `${yyyy}-${mm}-${dd}`;
}
return ( return (
<div className={styles.productInfo}> <div className={styles.productInfo}>
@@ -58,13 +73,13 @@ export function ProductInfo() {
<div className={styles.card}> <div className={styles.card}>
<label htmlFor="date">Packaged Date</label> <label htmlFor="date">Packaged Date</label>
<input <input
id="date" value={!!item ? ordinalToDate(item.date).toDateString() : ''} id="date"
type="date"
value={!!item ? getDateString(ordinalToDate(item.date)) : undefined}
contentEditable={isEntryMode} contentEditable={isEntryMode}
ref={dateRef} onChange={isEntryMode ? (e) => {
onChange={(e) => { setInputItem({ ...inputItem || {}, date: `${dateToOrdinal(new Date(e.currentTarget.valueAsNumber))}` })
dateRef.current.value = e.currentTarget.value; } : undefined}
setInputItem({ ...inputItem || {}, date: dateToOrdinal(new Date(e.currentTarget.value)) })
}}
/> />
</div> </div>
<div className={styles.card}> <div className={styles.card}>
@@ -86,26 +101,36 @@ export function ProductInfo() {
</div> </div>
<div className={styles.card}> <div className={styles.card}>
<label htmlFor="weight">Weight</label> <label htmlFor="weight">Weight</label>
<div className={styles.inputWithButton}> {isEntryMode ? (
<input <div className={styles.inputWithButton}>
id="weight" <input
value={!!item ? `${item.weight} lbs.` : ''} id="weight"
contentEditable={false} contentEditable={false}
tabIndex={-1} tabIndex={-1}
ref={weightRef} ref={weightRef}
/> />
{isEntryMode && ( <button
<button onClick={(e) => {
onClick={(e) => { const weight = faker.number.int({ min: 1000, max: 1999 });
const weight = faker.number.int({ min: 1000, max: 1999 }); if (weightRef.current) {
weightRef.current.value = `${weight / 100} lbs`; setInputItem({ ...inputItem || {}, weight }) weightRef.current.value = `${weight / 100} lbs`;
}} }
tabIndex={0} setInputItem({ ...inputItem || {}, weight })
> }}
Weight from Scale tabIndex={0}
</button> >
Weight from Scale
</button>
</div>
) : (
<input
id="weight"
value={!!item ? `${item?.weight} lbs.` : ''}
contentEditable={false}
tabIndex={-1}
readOnly
/>
)} )}
</div>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -22,17 +22,21 @@ export default function Page() {
break; break;
case 'Escape': case 'Escape':
event.preventDefault(); event.preventDefault();
setBin(null); if (bin !== null) {
setBin(null);
} else {
setItem(null);
}
break; break;
} }
}, [bin, item, setBin, setItem]); }, [bin, setBin, setItem]);
useEffect(() => { useEffect(() => {
window.addEventListener('keydown', handleKeydown); window.addEventListener('keydown', handleKeydown);
return () => { return () => {
window.removeEventListener('keydown', handleKeydown); window.removeEventListener('keydown', handleKeydown);
}; };
}, []); }, [handleKeydown]);
return ( return (
<main className={styles.page}> <main className={styles.page}>

View File

@@ -2,7 +2,6 @@ import { faker } from '@faker-js/faker';
import { Product } from "./product.enum"; import { Product } from "./product.enum";
import { dateToOrdinal } from './ordinalDate'; import { dateToOrdinal } from './ordinalDate';
import { ValueOf } from 'next/dist/shared/lib/constants';
export type Barcode = string; export type Barcode = string;