Skip to content

Commit

Permalink
Pin to @yudiel/react-qr-scanner@^1.2.10 (#28)
Browse files Browse the repository at this point in the history
* Pin to @yudiel/react-qr-scanner@^1.2.10

* Pin the library version to match the wrapped API
* Update wrapping conventions for latest reflex 0.6.5 (unreleased)

* Update dep and fix deprecations
  • Loading branch information
masenf authored Jan 18, 2025
1 parent 5ef9729 commit 7580a84
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
21 changes: 9 additions & 12 deletions examples/qr-scanner/qr_scanner/component.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from typing import Dict
from typing import Dict, Tuple
import reflex as rx
from reflex.components.component import NoSSRComponent
from reflex.vars import BaseVar, Var


def _on_error_signature(err: rx.Var[dict]) -> Tuple[rx.Var[str]]:
return err.message,


class QrScanner(NoSSRComponent):
library = "@yudiel/react-qr-scanner"
library = "@yudiel/react-qr-scanner@^1.2.10"
tag = "QrScanner"

# The delay between scans in milliseconds.
Expand All @@ -20,15 +23,9 @@ class QrScanner(NoSSRComponent):
container_style: rx.Var[Dict[str, str]]
video_style: rx.Var[Dict[str, str]]

def get_event_triggers(self) -> Dict[str, Var]:
"""Dict mapping (event -> expected arguments)."""

return {
**super().get_event_triggers(),
"on_result": lambda e0: [e0],
"on_decode": lambda e0: [e0],
"on_error": lambda e0: [Var.create("_e0?.message", _var_is_local=False)],
}
on_result: rx.EventHandler[rx.event.passthrough_event_spec(dict)]
on_decode: rx.EventHandler[rx.event.passthrough_event_spec(str)]
on_error: rx.EventHandler[_on_error_signature]


qr_scanner = QrScanner.create
12 changes: 6 additions & 6 deletions examples/qr-scanner/qr_scanner/qr_scanner.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import json
from pprint import pformat
from typing import Any

import reflex as rx
Expand All @@ -24,11 +24,11 @@ def on_result(self, result: dict[str, Any]):
def on_error(self, error: str):
self.last_error = error

@rx.var
def json_result(self) -> str:
return json.dumps(self.last_result, indent=2)
@rx.var(cache=True)
def pretty_result(self) -> str:
return pformat(self.get_value(self.last_result))

@rx.var
@rx.var(cache=True)
def is_link(self) -> bool:
return self.last_scan.startswith("http")

Expand Down Expand Up @@ -67,7 +67,7 @@ def index() -> rx.Component:
border="1px solid black",
width="80vw",
),
rc.code(State.json_result, white_space="pre-wrap"),
rc.code(State.pretty_result, white_space="pre-wrap"),
spacing="1.5em",
)

Expand Down
3 changes: 2 additions & 1 deletion examples/qr-scanner/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
reflex>=0.3.8
reflex>=0.6.5
reflex-chakra>=0.6.0

0 comments on commit 7580a84

Please sign in to comment.