Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update examples to support reflex 0.2.0 #128

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions clock/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.web
pynecone.db
*.py[cod]
__pycache__/
.web
__pycache__/
reflex.db
48 changes: 24 additions & 24 deletions clock/clock/clock.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""A Pynecone example of a analog clock."""
"""A Reflex example of a analog clock."""

import asyncio
from datetime import datetime
from typing import Any

import pynecone as pc
import reflex as rx
import pytz


Expand Down Expand Up @@ -32,7 +32,7 @@ def rotate(degrees: int) -> str:
return f"rotate({degrees}deg)"


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

# The time zone to display the clock in.
Expand All @@ -41,7 +41,7 @@ class State(pc.State):
# Whether the clock is running.
running: bool = False

@pc.var
@rx.var
def time_info(self) -> dict[str, Any]:
"""Get the current time info.

Expand Down Expand Up @@ -91,7 +91,7 @@ def flip_switch(self, running: bool):
return self.tick


def clock_hand(rotation: str, color: str, length: str) -> pc.Component:
def clock_hand(rotation: str, color: str, length: str) -> rx.Component:
"""Create a clock hand.

Args:
Expand All @@ -102,7 +102,7 @@ def clock_hand(rotation: str, color: str, length: str) -> pc.Component:
Returns:
A clock hand component.
"""
return pc.divider(
return rx.divider(
transform=rotation,
width=f"{length}em",
position="absolute",
Expand All @@ -113,11 +113,11 @@ def clock_hand(rotation: str, color: str, length: str) -> pc.Component:
)


def analog_clock() -> pc.Component:
def analog_clock() -> rx.Component:
"""Create the analog clock."""
return pc.circle(
return rx.circle(
# The inner circle.
pc.circle(
rx.circle(
width="1em",
height="1em",
border_width="thick",
Expand All @@ -137,15 +137,15 @@ def analog_clock() -> pc.Component:
)


def digital_clock() -> pc.Component:
def digital_clock() -> rx.Component:
"""Create the digital clock."""
return pc.hstack(
pc.heading(State.time_info["hour"]),
pc.heading(":"),
pc.heading(State.time_info["minute_display"]),
pc.heading(":"),
pc.heading(State.time_info["second_display"]),
pc.heading(State.time_info["meridiem"]),
return rx.hstack(
rx.heading(State.time_info["hour"]),
rx.heading(":"),
rx.heading(State.time_info["minute_display"]),
rx.heading(":"),
rx.heading(State.time_info["second_display"]),
rx.heading(State.time_info["meridiem"]),
border_width="medium",
border_color="#43464B",
border_radius="2em",
Expand All @@ -155,9 +155,9 @@ def digital_clock() -> pc.Component:
)


def timezone_select() -> pc.Component:
def timezone_select() -> rx.Component:
"""Create the timezone select."""
return pc.select(
return rx.select(
TIMEZONES,
placeholder="Select a time zone.",
on_change=State.set_zone,
Expand All @@ -168,12 +168,12 @@ def timezone_select() -> pc.Component:

def index():
"""The main view."""
return pc.center(
pc.vstack(
return rx.center(
rx.vstack(
analog_clock(),
pc.hstack(
rx.hstack(
digital_clock(),
pc.switch(is_checked=State.running, on_change=State.flip_switch),
rx.switch(is_checked=State.running, on_change=State.flip_switch),
),
timezone_select(),
padding="5em",
Expand All @@ -188,6 +188,6 @@ def index():


# Add state and page to the app.
app = pc.App(state=State)
app = rx.App(state=State)
app.add_page(index, title="Clock", on_load=State.on_load)
app.compile()
9 changes: 0 additions & 9 deletions clock/pcconfig.py

This file was deleted.

2 changes: 1 addition & 1 deletion clock/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pynecone>=0.1.33
reflex>=0.2.0
pytz==2022.7.1
7 changes: 7 additions & 0 deletions clock/rxconfig.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import reflex as rx

config = rx.Config(
app_name="clock",
db_url="sqlite:///reflex.db",
env=rx.Env.DEV,
)
1 change: 0 additions & 1 deletion counter/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
*.py[cod]
.web
__pycache__/
pynecone.db
reflex.db
2 changes: 1 addition & 1 deletion counter/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pynecone>=0.1.33
reflex>=0.2.0
2 changes: 0 additions & 2 deletions counter/rxconfig.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import reflex as rx


config = rx.Config(
app_name="counter",
bun_path="$HOME/.bun/bin/bun",
db_url="sqlite:///reflex.db",
env=rx.Env.DEV,
)
4 changes: 2 additions & 2 deletions crm/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*.py[cod]
.web
pynecone.db
__pycache__/
*.py[cod]
reflex.db
60 changes: 30 additions & 30 deletions crm/crm/components/crm.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from crm.state import State
from crm.state.models import Contact
import pynecone as pc
import reflex as rx


class CRMState(State):
contacts: list[Contact] = []
query = ""

def get_contacts(self) -> list[Contact]:
with pc.session() as sess:
with rx.session() as sess:
if self.query != "":
print("Query...")
self.contacts = (
Expand All @@ -28,7 +28,7 @@ def filter(self, query):
print("Returning...")
return self.get_contacts()

@pc.var
@rx.var
def num_contacts(self):
return len(self.contacts)

Expand All @@ -44,7 +44,7 @@ def toggle(self):
def add_contact(self):
if not self.user:
raise ValueError("No user logged in")
with pc.session() as sess:
with rx.session() as sess:
sess.expire_on_commit = False
sess.add(
Contact(
Expand All @@ -57,22 +57,22 @@ def add_contact(self):


def add_modal():
return pc.modal(
pc.modal_overlay(
pc.modal_content(
pc.modal_header("Add"),
pc.modal_body(
pc.input(
return rx.modal(
rx.modal_overlay(
rx.modal_content(
rx.modal_header("Add"),
rx.modal_body(
rx.input(
on_change=AddModalState.set_name,
placeholder="Name",
margin_bottom="0.5rem",
),
pc.input(on_change=AddModalState.set_email, placeholder="Email"),
rx.input(on_change=AddModalState.set_email, placeholder="Email"),
padding_y=0,
),
pc.modal_footer(
pc.button("Close", on_click=AddModalState.toggle),
pc.button(
rx.modal_footer(
rx.button("Close", on_click=AddModalState.toggle),
rx.button(
"Add", on_click=AddModalState.add_contact, margin_left="0.5rem"
),
),
Expand All @@ -85,27 +85,27 @@ def add_modal():
def contact_row(
contact,
):
return pc.tr(
pc.td(contact.contact_name),
pc.td(contact.email),
pc.td(pc.badge(contact.stage)),
return rx.tr(
rx.td(contact.contact_name),
rx.td(contact.email),
rx.td(rx.badge(contact.stage)),
)


def crm():
return pc.box(
pc.button("Refresh", on_click=CRMState.get_contacts),
pc.hstack(
pc.heading("Contacts"),
pc.button("Add", on_click=AddModalState.toggle),
return rx.box(
rx.button("Refresh", on_click=CRMState.get_contacts),
rx.hstack(
rx.heading("Contacts"),
rx.button("Add", on_click=AddModalState.toggle),
justify_content="space-between",
align_items="flex-start",
margin_bottom="1rem",
),
pc.responsive_grid(
pc.box(
pc.stat(
pc.stat_label("Contacts"), pc.stat_number(CRMState.num_contacts)
rx.responsive_grid(
rx.box(
rx.stat(
rx.stat_label("Contacts"), rx.stat_number(CRMState.num_contacts)
),
border="1px solid #eaeaef",
padding="1rem",
Expand All @@ -115,9 +115,9 @@ def crm():
margin_bottom="1rem",
),
add_modal(),
pc.input(placeholder="Filter by name...", on_change=CRMState.filter),
pc.table_container(
pc.table(pc.tbody(pc.foreach(CRMState.contacts, contact_row))),
rx.input(placeholder="Filter by name...", on_change=CRMState.filter),
rx.table_container(
rx.table(rx.tbody(rx.foreach(CRMState.contacts, contact_row))),
margin_top="1rem",
),
width="100%",
Expand Down
20 changes: 10 additions & 10 deletions crm/crm/components/navbar.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
from crm.state import State, LoginState
import pynecone as pc
import reflex as rx


def navbar():
return pc.box(
pc.hstack(
pc.link("Pyneknown", href="/", font_weight="medium"),
pc.hstack(
pc.cond(
return rx.box(
rx.hstack(
rx.link("Pyneknown", href="/", font_weight="medium"),
rx.hstack(
rx.cond(
State.user,
pc.hstack(
pc.link(
rx.hstack(
rx.link(
"Log out",
color="blue.600",
on_click=LoginState.log_out,
),
pc.avatar(name=State.user.email, size="md"),
rx.avatar(name=State.user.email, size="md"),
spacing="1rem",
),
pc.box(),
rx.box(),
)
),
justify_content="space-between",
Expand Down
6 changes: 3 additions & 3 deletions crm/crm/crm.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""Welcome to Pynecone! This file outlines the steps to create a basic app."""
import pynecone as pc
"""Welcome to Reflex! This file outlines the steps to create a basic app."""
import reflex as rx
from crm.pages import index, login
from crm.state import State


# Add state and page to the app.
app = pc.App(state=State)
app = rx.App(state=State)
app.add_page(index)
app.add_page(login)
app.compile()
18 changes: 9 additions & 9 deletions crm/crm/pages/index.py
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pyneknown => maybe should find another name, not blocking for PR approval

Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
from crm.components import navbar
from crm.components import crm
from crm.state import State
import pynecone as pc
import reflex as rx


def index():
return pc.vstack(
return rx.vstack(
navbar(),
pc.cond(
rx.cond(
State.user,
crm(),
pc.vstack(
pc.heading("Welcome to Pyneknown!"),
pc.text(
"This Pynecone example demonstrates how to build a fully-fledged customer relationship management (CRM) interface."
rx.vstack(
rx.heading("Welcome to Pyneknown!"),
rx.text(
"This Reflex example demonstrates how to build a fully-fledged customer relationship management (CRM) interface."
),
pc.link(
pc.button(
rx.link(
rx.button(
"Log in to get started", color_scheme="blue", underline="none"
),
href="/login",
Expand Down
Loading