From d13f3ce83154d9f7a64467c4fcece40cc36ad44c Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Fri, 14 Feb 2025 11:44:10 +0000 Subject: [PATCH] Improve camera request flow and layout --- assets/js/barcode-scanner.js | 12 ++++---- .../record_live/barcode_scanner_component.ex | 29 +++++++++++++++---- priv/gettext/default.pot | 4 +-- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/assets/js/barcode-scanner.js b/assets/js/barcode-scanner.js index 36bc43b4..85d826cc 100644 --- a/assets/js/barcode-scanner.js +++ b/assets/js/barcode-scanner.js @@ -27,7 +27,7 @@ export default { .getUserMedia(constraints) .then((mediaStream) => { console.debug("Camera access allowed") - this.pushEventTo(this.cameraPreview, "camera_allowed", {}); + this.pushEventTo(this.el, "camera_allowed", {}); this.cameraPreview.srcObject = mediaStream; this.cameraPreview.onloadedmetadata = () => { this.cameraPreview.play(); @@ -37,7 +37,7 @@ export default { barcodes.forEach(barcode => { if (!detectedBarcodes.has(barcode.rawValue)) { - this.pushEventTo(this.cameraPreview, "barcode_scanned", { number: barcode.rawValue }); + this.pushEventTo(this.el, "barcode_scanned", { number: barcode.rawValue }); detectedBarcodes.add(barcode.rawValue); }; }); @@ -46,13 +46,15 @@ export default { }) .catch((err) => { console.error(`${err.name}: ${err.message}`); - this.pushEventTo(this.cameraPreview, "camera_denied", {}); + this.pushEventTo(this.el, "camera_denied", {}); }); }) }, destroyed() { - this.cameraPreview.srcObject.getTracks().forEach(track => track.stop()); - window.clearInterval(this.scanInterval); + if (this.cameraPreview.srcObject) { + this.cameraPreview.srcObject.getTracks().forEach(track => track.stop()); + window.clearInterval(this.scanInterval); + } } } diff --git a/lib/music_library_web/live/record_live/barcode_scanner_component.ex b/lib/music_library_web/live/record_live/barcode_scanner_component.ex index 040f71ba..5387a122 100644 --- a/lib/music_library_web/live/record_live/barcode_scanner_component.ex +++ b/lib/music_library_web/live/record_live/barcode_scanner_component.ex @@ -11,7 +11,21 @@ defmodule MusicLibraryWeb.RecordLive.BarcodeScannerComponent do socket |> assign(:camera, :pending) |> assign(:barcodes, MapSet.new()) - |> assign(:releases, [])} + |> assign(:releases, [ + %MusicBrainz.ReleaseSearchResult{ + id: "dc393148-be34-4056-be66-b2b95905c5c1", + title: "Equally Cursed and Blessed", + release_group: %{ + id: "c35fc446-65cc-3645-939b-1b3782e60639", + type: :album, + title: "Equally Cursed and Blessed" + }, + artists: "Catatonia", + date: "1999-04-12", + barcode: "639842709422", + media: [%{format: "CD", disc_count: 5, track_count: 11}] + } + ])} end @impl true @@ -26,10 +40,15 @@ defmodule MusicLibraryWeb.RecordLive.BarcodeScannerComponent do

{@camera}

- +