Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into masenf/parametrize-re…
Browse files Browse the repository at this point in the history
…flex-version
  • Loading branch information
masenf committed Oct 12, 2023
2 parents 09f590d + 88b42c8 commit 4e675af
Show file tree
Hide file tree
Showing 39 changed files with 481 additions and 225 deletions.
6 changes: 4 additions & 2 deletions chatroom/chatroom/chatroom.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def index() -> rx.Component:
),
rx.button("Send", on_click=State.send_message),
),
on_submit=State.send_message,
on_submit=lambda d: State.send_message(),
),
width="60vw",
align_items="left",
Expand Down Expand Up @@ -104,7 +104,9 @@ async def broadcast_event(name: str, payload: t.Dict[str, t.Any] = {}) -> None:
# Emit the event.
responses.append(
app.event_namespace.emit(
str(rx.constants.SocketEvent.EVENT), update.json(), to=state.get_sid()
str(rx.constants.SocketEvent.EVENT),
update.json(),
to=state.get_sid(),
),
)
for response in responses:
Expand Down
2 changes: 1 addition & 1 deletion chatroom/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
reflex>=0.2.0
reflex>=0.2.9
44 changes: 33 additions & 11 deletions clock/clock/clock.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""A Reflex example of a analog clock."""

import asyncio
from datetime import datetime
from datetime import datetime, timezone
from typing import Any

import reflex as rx
Expand All @@ -18,6 +18,7 @@
"US/Pacific",
"US/Eastern",
]
DEFAULT_ZONE = TIMEZONES[-2]


def rotate(degrees: int) -> str:
Expand All @@ -36,12 +37,28 @@ class State(rx.State):
"""The app state."""

# The time zone to display the clock in.
zone: str = "US/Pacific"
zone: str = rx.Cookie(DEFAULT_ZONE)

# Whether the clock is running.
running: bool = False

@rx.var
# The last updated timestamp
_now: datetime = datetime.fromtimestamp(0)

@rx.cached_var
def valid_zone(self) -> str:
"""Get the current time zone.
Returns:
The current time zone.
"""
try:
pytz.timezone(self.zone)
except Exception:
return DEFAULT_ZONE
return self.zone

@rx.cached_var
def time_info(self) -> dict[str, Any]:
"""Get the current time info.
Expand All @@ -50,7 +67,7 @@ def time_info(self) -> dict[str, Any]:
Returns:
A dictionary of the current time info.
"""
now = datetime.now(pytz.timezone(self.zone))
now = self._now.astimezone(pytz.timezone(self.valid_zone))
return {
"hour": now.hour if now.hour <= 12 else now.hour % 12,
"minute": now.minute,
Expand All @@ -66,16 +83,21 @@ def time_info(self) -> dict[str, Any]:
def on_load(self):
"""Switch the clock off when the page refreshes."""
self.running = False
self.zone = "US/Pacific"
self.refresh()

def refresh(self):
"""Refresh the clock."""
self._now = datetime.now(timezone.utc)

@rx.background
async def tick(self):
"""Update the clock every second."""
# Sleep for a second.
await asyncio.sleep(1)
while self.running:
async with self:
self.refresh()

# If the clock is running, tick again.
if self.running:
return State.tick
# Sleep for a second.
await asyncio.sleep(1)

def flip_switch(self, running: bool):
"""Start or stop the clock.
Expand Down Expand Up @@ -161,7 +183,7 @@ def timezone_select() -> rx.Component:
TIMEZONES,
placeholder="Select a time zone.",
on_change=State.set_zone,
value=State.zone,
value=State.valid_zone,
bg="#white",
)

Expand Down
2 changes: 1 addition & 1 deletion clock/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
reflex>=0.2.0
reflex>=0.2.9
pytz==2022.7.1
2 changes: 1 addition & 1 deletion counter/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
reflex>=0.2.0
reflex>=0.2.9
2 changes: 1 addition & 1 deletion crm/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
reflex>=0.2.0
reflex>=0.2.9
1 change: 1 addition & 0 deletions dalle/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.db
*.py[cod]
.web
__pycache__/
Expand Down
9 changes: 6 additions & 3 deletions dalle/dalle/dalle.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
import reflex as rx



class State(rx.State):
"""The app state."""

image_url = ""
image_processing = False
image_made = False

def get_dalle_result(self, form_data: dict[str, str]):
prompt_text:str = form_data["prompt_text"]
prompt_text: str = form_data["prompt_text"]
self.image_made = False
self.image_processing = True
yield
Expand All @@ -24,6 +25,7 @@ def get_dalle_result(self, form_data: dict[str, str]):
self.image_processing = False
yield rx.window_alert("Error with OpenAI Execution.")


def index():
return rx.center(
rx.vstack(
Expand Down Expand Up @@ -60,7 +62,8 @@ def index():
background="radial-gradient(circle at 22% 11%,rgba(62, 180, 137,.20),hsla(0,0%,100%,0) 19%),radial-gradient(circle at 82% 25%,rgba(33,150,243,.18),hsla(0,0%,100%,0) 35%),radial-gradient(circle at 25% 61%,rgba(250, 128, 114, .28),hsla(0,0%,100%,0) 55%)",
)


# Add state and page to the app.
app = rx.App(state=State)
app.add_page(index, title="Pynecone:DALL-E")
app.add_page(index, title="Reflex:DALL-E")
app.compile()
2 changes: 1 addition & 1 deletion dalle/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
reflex>=0.2.0
reflex>=0.2.9
openai
1 change: 1 addition & 0 deletions ecommerce/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.db
*.py[cod]
.web
__pycache__/
Expand Down
2 changes: 1 addition & 1 deletion ecommerce/ecommerce/ecommerce.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def inventory():
data=State.product_data,
pagination=True,
sort=True,
search=True,
# search=True,
)
return rx.vstack(search_bar, table)

Expand Down
2 changes: 1 addition & 1 deletion ecommerce/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
reflex>=0.2.0
reflex>=0.2.9
icecream==2.1.1
pandas==2.1.0
2 changes: 1 addition & 1 deletion fragments/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
reflex>=0.2.0
reflex>=0.2.9
22 changes: 14 additions & 8 deletions github-stats/github_stats/github_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,24 @@ def index() -> rx.Component:
on_submit=State.handle_form,
),
rx.box(
rx.bar_chart(
rx.graphing_tooltip(cursor=False),
rx.bar(
rx.recharts.bar_chart(
rx.recharts.graphing_tooltip(cursor=False),
rx.recharts.bar(
data_key="repositoriesContributedTo",
stroke="#8884d8",
fill="#8884d8",
),
rx.bar(data_key="mergedPullRequests", stroke="#82ca9d", fill="#82ca9d"),
rx.bar(data_key="openIssues", stroke="#ffc658", fill="#ffc658"),
rx.bar(data_key="closedIssues", stroke="#ff0000", fill="#ff0000"),
rx.x_axis(data_key="login"),
rx.y_axis(),
rx.recharts.bar(
data_key="mergedPullRequests", stroke="#82ca9d", fill="#82ca9d"
),
rx.recharts.bar(
data_key="openIssues", stroke="#ffc658", fill="#ffc658"
),
rx.recharts.bar(
data_key="closedIssues", stroke="#ff0000", fill="#ff0000"
),
rx.recharts.x_axis(data_key="login"),
rx.recharts.y_axis(),
data=State.user_stats,
),
width="100%",
Expand Down
2 changes: 1 addition & 1 deletion github-stats/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
reflex>=0.3.0a1
reflex>=0.2.9
2 changes: 1 addition & 1 deletion gpt/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
reflex>=0.2.0
reflex>=0.2.9
openai
2 changes: 1 addition & 1 deletion local_auth/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
reflex>=0.2.7
reflex>=0.2.9
passlib
bcrypt
4 changes: 3 additions & 1 deletion lorem-stream/lorem_stream/lorem_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ def render_task(task_id: int) -> rx.Component:
is_indeterminate=LoremState.progress[task_id] < 1,
),
rx.button(
rx.cond(LoremState.progress[task_id] < LoremState.end_at[task_id], "⏯️", "🔄"),
rx.cond(
LoremState.progress[task_id] < LoremState.end_at[task_id], "⏯️", "🔄"
),
on_click=LoremState.toggle_running(task_id),
),
rx.button("❌", on_click=LoremState.kill(task_id)),
Expand Down
2 changes: 1 addition & 1 deletion lorem-stream/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
reflex>=0.2.8
reflex>=0.2.9
lorem_text>=2.1
2 changes: 1 addition & 1 deletion nba/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
reflex>=0.2.0
reflex>=0.2.9
plotly-express
plotly
pandas
15 changes: 9 additions & 6 deletions qr-scanner/qr_scanner/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ class QrScanner(NoSSRComponent):
container_style: rx.Var[Dict[str, str]]
video_style: rx.Var[Dict[str, str]]

def get_controlled_triggers(self) -> Dict[str, Var]:
def get_event_triggers(self) -> Dict[str, Var]:
"""Dict mapping (event -> expected arguments)."""
return super().get_controlled_triggers() | {
"on_result": rx.EVENT_ARG,
"on_decode": rx.EVENT_ARG,
"on_error": BaseVar(name=rx.EVENT_ARG.name + "?.message", type_=str),

return {
**super().get_event_triggers(),
"on_result": lambda e0: [e0],
"on_decode": lambda e0: [e0],
"on_error": lambda e0: [BaseVar(name="_e0?.message")],
}

qr_scanner = QrScanner.create

qr_scanner = QrScanner.create
2 changes: 1 addition & 1 deletion qr-scanner/qr_scanner/qr_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ def index() -> rx.Component:

app = rx.App()
app.add_page(index)
app.compile()
app.compile()
2 changes: 1 addition & 1 deletion qr-scanner/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
reflex>=0.2.5
reflex>=0.2.9
3 changes: 2 additions & 1 deletion qr-scanner/rxconfig.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import reflex as rx


class QrscannerConfig(rx.Config):
pass


config = QrscannerConfig(
app_name="qr_scanner",
frontend_packages=["@yudiel/react-qr-scanner"],
)
1 change: 1 addition & 0 deletions quiz/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.db
*.py[cod]
.web
__pycache__/
Expand Down
10 changes: 8 additions & 2 deletions quiz/quiz/quiz.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@

class State(rx.State):
"""The app state."""

default_answers = [None, None, [False, False, False, False, False]]
answers:List[Any]
answers: List[Any]
answer_key = ["False", "[10, 20, 30, 40]", [False, False, True, True, True]]
score: int

def onload(self):
self.answers = copy.deepcopy(self.default_answers)

Expand All @@ -38,6 +40,10 @@ def submit(self):
self.score = int(correct / total * 100)
return rx.redirect("/result")

@rx.var
def percent_score(self):
return f"{self.score}%"


def header():
return rx.vstack(
Expand All @@ -63,7 +69,7 @@ def question1():
["True", "False"],
default_value=State.default_answers[0],
default_checked=True,
on_change=lambda answer: State.set_answers(answer, 0)
on_change=lambda answer: State.set_answers(answer, 0),
),
style=question_style,
)
Expand Down
4 changes: 2 additions & 2 deletions quiz/quiz/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def results(State):
rx.divider(),
rx.center(
rx.circular_progress(
rx.circular_progress_label(State.score + "%"),
rx.circular_progress_label(State.percent_score),
value=State.score,
size="3em",
)
Expand All @@ -49,7 +49,7 @@ def results(State):
),
rx.foreach(State.answers, lambda answer, i: render_answer(State, i)),
),
rx.link(rx.button("Take Quiz Again"), href="/"),
rx.box(rx.link(rx.button("Take Quiz Again"), href="/")),
bg="white",
padding_x="5em",
padding_y="2em",
Expand Down
2 changes: 1 addition & 1 deletion quiz/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
reflex>=0.2.0
reflex>=0.2.9
1 change: 1 addition & 0 deletions sales/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.db
*.py[cod]
.web
__pycache__/
Expand Down
Binary file modified sales/assets/favicon.ico
Binary file not shown.
2 changes: 1 addition & 1 deletion sales/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
reflex>=0.2.0
reflex>=0.2.9
openai
Loading

0 comments on commit 4e675af

Please sign in to comment.