prevent doubles
This commit is contained in:
+30
-3
@@ -396,6 +396,11 @@
|
||||
width: 200px;
|
||||
}
|
||||
|
||||
/* Hidden code column — stores raw scan code for duplicate checking */
|
||||
.col-code {
|
||||
display: none;
|
||||
}
|
||||
|
||||
tbody tr {
|
||||
border-bottom: 1px solid var(--card);
|
||||
animation: rowIn 0.28s ease-out;
|
||||
@@ -881,6 +886,7 @@
|
||||
<th>Country</th>
|
||||
<th>Name</th>
|
||||
<th>Tag</th>
|
||||
<th class="col-code">Code</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="tableBody"></tbody>
|
||||
@@ -1201,6 +1207,15 @@
|
||||
});
|
||||
}
|
||||
|
||||
// ── Duplicate check ──────────────────────────────────────────────────────
|
||||
function isDuplicate(code) {
|
||||
const cells = tableBody.querySelectorAll(".col-code");
|
||||
for (const cell of cells) {
|
||||
if (cell.textContent === code.trim()) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// ── Submit Scan ──────────────────────────────────────────────────────────
|
||||
async function submitScan(code) {
|
||||
const user = userSelect.value;
|
||||
@@ -1216,6 +1231,17 @@
|
||||
return;
|
||||
}
|
||||
|
||||
// Duplicate check against already-scanned codes in the table
|
||||
if (isDuplicate(code)) {
|
||||
showToast(
|
||||
"⚠️ Already scanned: " + code.trim(),
|
||||
"fail",
|
||||
4000,
|
||||
);
|
||||
scanInput.select();
|
||||
return;
|
||||
}
|
||||
|
||||
showBanner("Looking up package…", "loading");
|
||||
|
||||
try {
|
||||
@@ -1253,7 +1279,7 @@
|
||||
return;
|
||||
}
|
||||
hideBanner();
|
||||
addRow(item);
|
||||
addRow(item, code);
|
||||
showToast(
|
||||
"✓ Added: " + (item.name || item.producttag || code),
|
||||
"ok",
|
||||
@@ -1273,8 +1299,8 @@
|
||||
}
|
||||
}
|
||||
|
||||
// ── Table Row ────────────────────────────────────────────────────────────
|
||||
function addRow(item) {
|
||||
// ── Table Row ───────────────────────────────────────────────────────────────────
|
||||
function addRow(item, code) {
|
||||
emptyState.style.display = "none";
|
||||
scanCount++;
|
||||
countPill.textContent =
|
||||
@@ -1286,6 +1312,7 @@
|
||||
<td><span class="country-badge">${esc(item.country || "—")}</span></td>
|
||||
<td class="name-cell">${esc(item.name || "—")}</td>
|
||||
<td><span class="tag-pill" title="${esc(item.producttag || "")}">${esc(item.producttag || "—")}</span></td>
|
||||
<td class="col-code">${esc(code.trim())}</td>
|
||||
`;
|
||||
// Newest row at the top
|
||||
tableBody.insertBefore(tr, tableBody.firstChild);
|
||||
|
||||
Reference in New Issue
Block a user