2023-11-17 14:22:28 +01:00
|
|
|
"""Common templates used between pages in the app."""
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
from blurme import styles
|
|
|
|
from blurme.components.sidebar import sidebar
|
|
|
|
from typing import Callable
|
2023-12-12 21:27:48 +01:00
|
|
|
from blurme.state import State
|
2023-11-17 14:22:28 +01:00
|
|
|
|
|
|
|
import reflex as rx
|
|
|
|
|
|
|
|
# Meta tags for the app.
|
|
|
|
default_meta = [
|
|
|
|
{
|
|
|
|
"name": "viewport",
|
|
|
|
"content": "width=device-width, shrink-to-fit=no, initial-scale=1",
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
2023-11-25 14:23:04 +01:00
|
|
|
def dark_mode() -> rx.Component:
|
2023-11-17 14:22:28 +01:00
|
|
|
return rx.box(
|
2023-11-25 14:23:04 +01:00
|
|
|
rx.button(
|
2023-11-17 14:22:28 +01:00
|
|
|
rx.icon(
|
2023-11-25 14:23:04 +01:00
|
|
|
tag="moon",
|
2023-11-17 14:22:28 +01:00
|
|
|
size="4em",
|
|
|
|
color=styles.text_color,
|
|
|
|
),
|
2023-12-12 21:27:48 +01:00
|
|
|
on_click= rx.toggle_color_mode
|
|
|
|
#State.toggle_dark_mode()
|
2023-11-17 14:22:28 +01:00
|
|
|
),
|
|
|
|
position="fixed",
|
|
|
|
right="1.5em",
|
|
|
|
top="1.5em",
|
2023-12-12 21:27:48 +01:00
|
|
|
z_index="500",)
|
2023-11-17 14:22:28 +01:00
|
|
|
|
|
|
|
def template(
|
|
|
|
route: str | None = None,
|
|
|
|
title: str | None = None,
|
|
|
|
image: str | None = None,
|
2023-12-12 21:27:48 +01:00
|
|
|
image_dark: str | None = None,
|
2023-11-17 14:22:28 +01:00
|
|
|
description: str | None = None,
|
|
|
|
meta: str | None = None,
|
|
|
|
script_tags: list[rx.Component] | None = None,
|
|
|
|
on_load: rx.event.EventHandler | list[rx.event.EventHandler] | None = None,
|
|
|
|
) -> Callable[[Callable[[], rx.Component]], rx.Component]:
|
|
|
|
"""The template for each page of the app.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
route: The route to reach the page.
|
|
|
|
title: The title of the page.
|
|
|
|
image: The favicon of the page.
|
2023-12-12 21:27:48 +01:00
|
|
|
image_dark: The dark mode favicon of the page.
|
2023-11-17 14:22:28 +01:00
|
|
|
description: The description of the page.
|
2023-12-12 21:27:48 +01:00
|
|
|
meta: Additional meta to add to the page.
|
|
|
|
on_load: The event handler(s) called when the page loads.
|
2023-11-17 14:22:28 +01:00
|
|
|
script_tags: Scripts to attach to the page.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
The template with the page content.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def decorator(page_content: Callable[[], rx.Component]) -> rx.Component:
|
|
|
|
"""The template for each page of the app.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
page_content: The content of the page.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
The template with the page content.
|
|
|
|
"""
|
|
|
|
# Get the meta tags for the page.
|
|
|
|
all_meta = [*default_meta, *(meta or [])]
|
|
|
|
|
|
|
|
@rx.page(
|
|
|
|
route=route,
|
|
|
|
title=title,
|
|
|
|
image=image,
|
|
|
|
description=description,
|
|
|
|
meta=all_meta,
|
|
|
|
script_tags=script_tags,
|
|
|
|
on_load=on_load,
|
|
|
|
)
|
|
|
|
def templated_page():
|
|
|
|
return rx.hstack(
|
|
|
|
sidebar(),
|
|
|
|
rx.box(
|
|
|
|
rx.box(
|
|
|
|
page_content(),
|
|
|
|
**styles.template_content_style,
|
|
|
|
),
|
|
|
|
**styles.template_page_style,
|
|
|
|
),
|
2023-12-12 21:27:48 +01:00
|
|
|
dark_mode(),
|
2023-11-17 14:22:28 +01:00
|
|
|
align_items="flex-start",
|
|
|
|
transition="left 0.5s, width 0.5s",
|
|
|
|
position="relative",
|
|
|
|
)
|
|
|
|
|
|
|
|
return templated_page
|
|
|
|
|
|
|
|
return decorator
|