Fix format route and code cleanup (#399)
This commit is contained in:
parent
41fffe677b
commit
6b97de71a0
@ -17,7 +17,7 @@ DEFAULT_IMPORTS: ImportDict = {
|
|||||||
"next/router": {"useRouter"},
|
"next/router": {"useRouter"},
|
||||||
f"/{constants.STATE_PATH}": {"connect", "updateState", "E"},
|
f"/{constants.STATE_PATH}": {"connect", "updateState", "E"},
|
||||||
"": {"focus-visible/dist/focus-visible"},
|
"": {"focus-visible/dist/focus-visible"},
|
||||||
"@chakra-ui/react": {"useColorMode"},
|
"@chakra-ui/react": {constants.USE_COLOR_MODE},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -199,4 +199,4 @@ ROUTER = f"const {constants.ROUTER} = useRouter()"
|
|||||||
SOCKET = "const socket = useRef(null)"
|
SOCKET = "const socket = useRef(null)"
|
||||||
|
|
||||||
# Color toggle
|
# Color toggle
|
||||||
COLORTOGGLE = "const { colorMode, toggleColorMode } = useColorMode()"
|
COLORTOGGLE = f"const {{ {constants.COLOR_MODE}, {constants.TOGGLE_COLOR_MODE} }} = {constants.USE_COLOR_MODE}()"
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
"""Document components."""
|
"""Document components."""
|
||||||
|
|
||||||
from pynecone.components.component import Component
|
from pynecone.components.component import Component
|
||||||
|
from pynecone.components.libs.chakra import ChakraComponent
|
||||||
|
|
||||||
|
|
||||||
class NextDocumentLib(Component):
|
class NextDocumentLib(Component):
|
||||||
@ -33,13 +34,7 @@ class Script(NextDocumentLib):
|
|||||||
tag = "NextScript"
|
tag = "NextScript"
|
||||||
|
|
||||||
|
|
||||||
class ChakraUiReactLib(Component):
|
class ColorModeScript(ChakraComponent):
|
||||||
"""Chakra UI React document components."""
|
|
||||||
|
|
||||||
library = "@chakra-ui/react"
|
|
||||||
|
|
||||||
|
|
||||||
class ColorModeScript(ChakraUiReactLib):
|
|
||||||
"""Chakra color mode script."""
|
"""Chakra color mode script."""
|
||||||
|
|
||||||
tag = "ColorModeScript"
|
tag = "ColorModeScript"
|
||||||
|
@ -162,11 +162,6 @@ class Component(Base, ABC):
|
|||||||
Raises:
|
Raises:
|
||||||
ValueError: If the value is not a valid event chain.
|
ValueError: If the value is not a valid event chain.
|
||||||
"""
|
"""
|
||||||
# If it's a JS var, return it.
|
|
||||||
if isinstance(value, Var):
|
|
||||||
if value.is_local is False and value.is_string is False:
|
|
||||||
return value
|
|
||||||
|
|
||||||
# If it's an event chain var, return it.
|
# If it's an event chain var, return it.
|
||||||
if isinstance(value, Var):
|
if isinstance(value, Var):
|
||||||
if value.type_ is not EventChain:
|
if value.type_ is not EventChain:
|
||||||
|
@ -226,3 +226,8 @@ SLUG_404 = "[..._]"
|
|||||||
TITLE_404 = "404 - Not Found"
|
TITLE_404 = "404 - Not Found"
|
||||||
FAVICON_404 = "favicon.ico"
|
FAVICON_404 = "favicon.ico"
|
||||||
DESCRIPTION_404 = "The page was not found"
|
DESCRIPTION_404 = "The page was not found"
|
||||||
|
|
||||||
|
# Color mode variables
|
||||||
|
USE_COLOR_MODE = "useColorMode"
|
||||||
|
COLOR_MODE = "colorMode"
|
||||||
|
TOGGLE_COLOR_MODE = "toggleColorMode"
|
||||||
|
@ -2,17 +2,12 @@
|
|||||||
|
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from pynecone import utils
|
from pynecone import constants, utils
|
||||||
from pynecone.var import Var
|
from pynecone.event import EventChain
|
||||||
|
from pynecone.var import BaseVar, Var
|
||||||
|
|
||||||
|
|
||||||
def toggle_color_mode():
|
toggle_color_mode = BaseVar(name=constants.TOGGLE_COLOR_MODE, type_=EventChain)
|
||||||
"""Toggle the color mode.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Toggle color mode JS event as a variable
|
|
||||||
"""
|
|
||||||
return Var.create(value="toggleColorMode", is_local=False, is_string=False)
|
|
||||||
|
|
||||||
|
|
||||||
def convert(style_dict):
|
def convert(style_dict):
|
||||||
|
@ -952,12 +952,14 @@ def format_route(route: str) -> str:
|
|||||||
Returns:
|
Returns:
|
||||||
The formatted route.
|
The formatted route.
|
||||||
"""
|
"""
|
||||||
|
# Strip the route.
|
||||||
|
route = route.strip("/")
|
||||||
|
route = to_snake_case(route).replace("_", "-")
|
||||||
|
|
||||||
# If the route is empty, return the index route.
|
# If the route is empty, return the index route.
|
||||||
if route == "":
|
if route == "":
|
||||||
return constants.INDEX_ROUTE
|
return constants.INDEX_ROUTE
|
||||||
|
|
||||||
route = route.strip("/")
|
|
||||||
route = to_snake_case(route).replace("_", "-")
|
|
||||||
return route
|
return route
|
||||||
|
|
||||||
|
|
||||||
|
@ -210,6 +210,7 @@ def test_is_generic_alias(cls: type, expected: bool):
|
|||||||
"route,expected",
|
"route,expected",
|
||||||
[
|
[
|
||||||
("", "index"),
|
("", "index"),
|
||||||
|
("/", "index"),
|
||||||
("custom-route", "custom-route"),
|
("custom-route", "custom-route"),
|
||||||
("custom-route/", "custom-route"),
|
("custom-route/", "custom-route"),
|
||||||
("/custom-route", "custom-route"),
|
("/custom-route", "custom-route"),
|
||||||
|
Loading…
Reference in New Issue
Block a user