Skip to content

Commit

Permalink
fix: scanner resets scannerString too often
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianAndersen committed Jan 21, 2025
1 parent 65a802c commit 6863178
Showing 1 changed file with 18 additions and 23 deletions.
41 changes: 18 additions & 23 deletions src/app/bl-common/blc-scanner/blc-scanner.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ export class BlcScannerDirective {
} else if (event.key.length === 1) {
this.scannerString += event.key;
}

if (this.scannerString.length > 13) {
this.scannerString = "";
}
}

@HostListener("window:paste", ["$event"])
Expand All @@ -65,26 +61,25 @@ export class BlcScannerDirective {
}

private processScannerString() {
if (
this.scannerString.length === 12 ||
this._blcScannerService.isUllernBlid(this.scannerString)
) {
this._blcScannerService.scanBlid(this.scannerString);
} else if (
this.scannerString.length > 9 &&
this.scannerString.length < 14 &&
this.isNumeric(this.scannerString)
) {
this._blcScannerService.scanIsbn(this.scannerString);
} else {
this._toasterService.add(
"WARNING",
{
text: `"${this.scannerString}" er ikke en gyldig blid eller isbn.`,
},
5000
);
if (this.isNumeric(this.scannerString)) {
if (this.scannerString.length === 8) {
return this._blcScannerService.scanBlid(this.scannerString);
}
if (
this.scannerString.length < 10 ||
this.scannerString.length > 13
) {
return this._toasterService.add(
"WARNING",
{
text: `"${this.scannerString}" er ikke en gyldig blid eller isbn.`,
},
5000
);
}
return this._blcScannerService.scanIsbn(this.scannerString);
}
this._blcScannerService.scanBlid(this.scannerString.slice(-12));
}

private isNumeric(value) {
Expand Down

0 comments on commit 6863178

Please sign in to comment.