Skip to content

Commit f718715

Browse files
authored
ENG-7927: make builder first option in reflex init cli (#5862)
1 parent 9556a35 commit f718715

File tree

3 files changed

+30
-41
lines changed

3 files changed

+30
-41
lines changed

reflex/constants/base.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ class Templates(SimpleNamespace):
134134
# The reflex.build frontend host
135135
REFLEX_BUILD_FRONTEND = "https://build.reflex.dev"
136136

137+
# The reflex.build frontend with referrer
138+
REFLEX_BUILD_FRONTEND_WITH_REFERRER = (
139+
f"{REFLEX_BUILD_FRONTEND}/?utm_source=reflex_cli"
140+
)
141+
137142
class Dirs(SimpleNamespace):
138143
"""Folders used by the template system of Reflex."""
139144

reflex/utils/redir.py

Lines changed: 21 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,43 @@
11
"""Utilities to handle redirection to browser UI."""
22

3-
import time
4-
import webbrowser
3+
from typing import TYPE_CHECKING
54

6-
from reflex import constants
7-
from reflex.utils import net
5+
if TYPE_CHECKING:
6+
from urllib.parse import SplitResult
87

9-
from . import console
108

11-
12-
def open_browser(target_url: str) -> None:
9+
def open_browser(target_url: "SplitResult") -> None:
1310
"""Open a browser window to target_url.
1411
1512
Args:
1613
target_url: The URL to open in the browser.
1714
"""
18-
if not webbrowser.open(target_url):
15+
import webbrowser
16+
17+
from reflex.utils import console
18+
19+
if not webbrowser.open(target_url.geturl()):
1920
console.warn(
2021
f"Unable to automatically open the browser. Please navigate to {target_url} in your browser."
2122
)
2223
else:
23-
console.info(f"Opening browser to {target_url}.")
24-
25-
26-
def open_browser_and_wait(target_url: str, poll_url: str, interval: int = 2):
27-
"""Open a browser window to target_url and request poll_url until it returns successfully.
28-
29-
Args:
30-
target_url: The URL to open in the browser.
31-
poll_url: The URL to poll for success.
32-
interval: The interval in seconds to wait between polling.
33-
34-
Returns:
35-
The response from the poll_url.
36-
"""
37-
import httpx
38-
39-
open_browser(target_url)
40-
console.info("[b]Complete the workflow in the browser to continue.[/b]")
41-
while True:
42-
try:
43-
response = net.get(poll_url, follow_redirects=True)
44-
if response.is_success:
45-
break
46-
except httpx.RequestError as err:
47-
console.info(f"Will retry after error occurred while polling: {err}.")
48-
time.sleep(interval)
49-
return response
24+
simplified_url = target_url._replace(path="", query="", fragment="").geturl()
25+
console.info(f"Opened browser to {simplified_url}")
5026

5127

5228
def reflex_build_redirect() -> None:
5329
"""Open the browser window to reflex.build."""
54-
open_browser(constants.Templates.REFLEX_BUILD_FRONTEND)
30+
from urllib.parse import urlsplit
31+
32+
from reflex import constants
33+
34+
open_browser(urlsplit(constants.Templates.REFLEX_BUILD_FRONTEND_WITH_REFERRER))
5535

5636

5737
def reflex_templates():
5838
"""Open the browser window to reflex.build/templates."""
59-
open_browser(constants.Templates.REFLEX_TEMPLATES_URL)
39+
from urllib.parse import urlsplit
40+
41+
from reflex import constants
42+
43+
open_browser(urlsplit(constants.Templates.REFLEX_TEMPLATES_URL))

reflex/utils/templates.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -419,13 +419,13 @@ def get_init_cli_prompt_options() -> list[Template]:
419419
"""
420420
return [
421421
Template(
422-
name=constants.Templates.DEFAULT,
423-
description="A blank Reflex app.",
422+
name=constants.Templates.AI,
423+
description="[bold]Try our free AI builder.",
424424
code_url="",
425425
),
426426
Template(
427-
name=constants.Templates.AI,
428-
description="[bold]Try our free AI builder.",
427+
name=constants.Templates.DEFAULT,
428+
description="A blank Reflex app.",
429429
code_url="",
430430
),
431431
Template(

0 commit comments

Comments
 (0)