From c0892647e07112caa43f539c4cb79b44443868c5 Mon Sep 17 00:00:00 2001 From: Larry Ogrodnek Date: Sun, 29 Sep 2024 21:52:05 -0400 Subject: [PATCH] cleanup and styling tweaks --- examples/views/recipes/components/ratings.py | 6 +----- .../views/recipes/components/recipe_card.css | 17 ++++++++++++----- .../views/recipes/components/recipe_card.py | 6 ------ .../recipes/{recipe_db.py => recipe_list.py} | 1 - examples/views/recipes/recipes.css | 8 ++++++++ examples/views/recipes/recipes.html | 6 +++++- examples/views/recipes/recipes.py | 6 ++---- .../live_component/live_components_context.py | 4 ---- 8 files changed, 28 insertions(+), 26 deletions(-) rename examples/views/recipes/{recipe_db.py => recipe_list.py} (99%) diff --git a/examples/views/recipes/components/ratings.py b/examples/views/recipes/components/ratings.py index 8e52166..a46de8c 100644 --- a/examples/views/recipes/components/ratings.py +++ b/examples/views/recipes/components/ratings.py @@ -4,8 +4,4 @@ @components.register("Ratings") class RatingsComponent(LiveComponent): - async def mount(self, socket): - print("Ratings mounted") - - async def update(self, socket, template_vars): - print("Ratings updated", template_vars) + pass diff --git a/examples/views/recipes/components/recipe_card.css b/examples/views/recipes/components/recipe_card.css index baea9fc..edd363d 100644 --- a/examples/views/recipes/components/recipe_card.css +++ b/examples/views/recipes/components/recipe_card.css @@ -16,7 +16,9 @@ } .recipe_card-content { - padding: 0.75em; + padding-inline: 0.75em; + padding-bottom: 0.75em; + } .recipe_card-header { @@ -25,14 +27,19 @@ align-items: flex-end; } + .recipe_card-content .recipe_card-title { - font-size: 1.1em; - font-weight: 500; + font-family: var(--recipe-title-font); + font-weight: 400; + font-style: normal; + + font-size: 1.6em; + color: #333; } .recipe_card-content .recipe_card-time { - font-size: 0.9em; + font-size: 0.8em; color: #666; font-weight: 100; } @@ -51,7 +58,7 @@ } .recipe_card-actions { - padding-top: .75em; + padding-top: 0.25em; display: flex; justify-content: space-between; } diff --git a/examples/views/recipes/components/recipe_card.py b/examples/views/recipes/components/recipe_card.py index 4702ba4..e95dc1e 100644 --- a/examples/views/recipes/components/recipe_card.py +++ b/examples/views/recipes/components/recipe_card.py @@ -6,9 +6,3 @@ class RecipeCardComponent(LiveComponent): def __init__(self): super().__init__() - - async def mount(self, socket): - print("RecipeCard mounted") - - async def update(self, socket, template_vars): - print("RecipeCard updated", template_vars) diff --git a/examples/views/recipes/recipe_db.py b/examples/views/recipes/recipe_list.py similarity index 99% rename from examples/views/recipes/recipe_db.py rename to examples/views/recipes/recipe_list.py index 11e4283..6aaad40 100644 --- a/examples/views/recipes/recipe_db.py +++ b/examples/views/recipes/recipe_list.py @@ -1,5 +1,4 @@ from dataclasses import dataclass, field -import random import uuid from typing import Optional diff --git a/examples/views/recipes/recipes.css b/examples/views/recipes/recipes.css index 5e91f76..f1a839a 100644 --- a/examples/views/recipes/recipes.css +++ b/examples/views/recipes/recipes.css @@ -1,9 +1,17 @@ +:root { + --recipe-title-font: "Shadows Into Light", cursive; +} + main { margin: 0; padding: 20px; height: 100vh; } +.recipes_title { + margin-top: 0; +} + html { background-color: #F0F0F0; } diff --git a/examples/views/recipes/recipes.html b/examples/views/recipes/recipes.html index 09af703..d3cd00d 100644 --- a/examples/views/recipes/recipes.html +++ b/examples/views/recipes/recipes.html @@ -1,5 +1,9 @@ + + + +
-

Latest Recipes

+

Latest Recipes

{% for recipe in recipes %} {% live_component "RecipeCard" with id = recipe.id & recipe = recipe %} diff --git a/examples/views/recipes/recipes.py b/examples/views/recipes/recipes.py index 9777579..31c101a 100644 --- a/examples/views/recipes/recipes.py +++ b/examples/views/recipes/recipes.py @@ -1,6 +1,6 @@ from pyview import LiveView, LiveViewSocket -from dataclasses import dataclass, field -from .recipe_db import Recipe, all_recipes +from dataclasses import dataclass +from .recipe_list import Recipe, all_recipes @dataclass @@ -29,6 +29,4 @@ async def handle_event(self, event, payload, socket): id = payload["id"] recipe = next((r for r in socket.context.recipes if r.id == id), None) if recipe is not None: - print("Set rating", recipe.rating, "to", payload["rating"]) - recipe.rating = int(payload["rating"]) diff --git a/pyview/live_component/live_components_context.py b/pyview/live_component/live_components_context.py index 39bf74f..831d5b2 100644 --- a/pyview/live_component/live_components_context.py +++ b/pyview/live_component/live_components_context.py @@ -31,15 +31,11 @@ def register_component( id = f"{user_id}-{component.__class__.__name__}" ref = ComponentReference(id, self.cid_index) - print("Registering component", id, ref) for c in self.components: if c.ref.id == id: c.context = context - print("Component already registered", id) return c.ref - print("Component not registered", id) - self.components.append(LiveComponentContext(ref, component, context)) self.cid_index += 1 return ref