From d1c9fcefffbd8cc1c7c52fdf0d8f0b293d89e5f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BCdiger=20Diedrich?= Date: Sun, 16 Apr 2023 21:32:56 +0200 Subject: [PATCH] first chicken and egg --- config/prod.exs | 3 +- .../components/chicken_components.ex | 19 ++ .../components/layouts/app.html.heex | 31 +-- .../controllers/page_html/home.html.heex | 237 +----------------- lib/chicken_egg_web/live/index_live.ex | 46 ++++ lib/chicken_egg_web/router.ex | 2 +- 6 files changed, 73 insertions(+), 265 deletions(-) create mode 100644 lib/chicken_egg_web/components/chicken_components.ex create mode 100644 lib/chicken_egg_web/live/index_live.ex diff --git a/config/prod.exs b/config/prod.exs index fecb6da..e6d1e12 100644 --- a/config/prod.exs +++ b/config/prod.exs @@ -9,7 +9,8 @@ import Config # manifest is generated by the `mix assets.deploy` task, # which you should run after static files are built and # before starting your production server. -config :chicken_egg, ChickenEggWeb.Endpoint, cache_static_manifest: "priv/static/cache_manifest.json" +config :chicken_egg, ChickenEggWeb.Endpoint, + cache_static_manifest: "priv/static/cache_manifest.json" # Configures Swoosh API Client config :swoosh, api_client: Swoosh.ApiClient.Finch, finch_name: ChickenEgg.Finch diff --git a/lib/chicken_egg_web/components/chicken_components.ex b/lib/chicken_egg_web/components/chicken_components.ex new file mode 100644 index 0000000..2ef7fcd --- /dev/null +++ b/lib/chicken_egg_web/components/chicken_components.ex @@ -0,0 +1,19 @@ +defmodule ChickenEggWeb.ChickenComponents do + use ChickenEggWeb, :html + + def chicken(assigns) do + ~H""" +
+ +
+ """ + end + + def egg(assigns) do + ~H""" +
+ +
+ """ + end +end diff --git a/lib/chicken_egg_web/components/layouts/app.html.heex b/lib/chicken_egg_web/components/layouts/app.html.heex index e23bfc8..97cbd63 100644 --- a/lib/chicken_egg_web/components/layouts/app.html.heex +++ b/lib/chicken_egg_web/components/layouts/app.html.heex @@ -1,31 +1,6 @@ -
-
-
- - - -

- v<%= Application.spec(:phoenix, :vsn) %> -

-
- -
-
-
-
+
+
+
<.flash_group flash={@flash} /> <%= @inner_content %>
diff --git a/lib/chicken_egg_web/controllers/page_html/home.html.heex b/lib/chicken_egg_web/controllers/page_html/home.html.heex index c75a1da..4c56e69 100644 --- a/lib/chicken_egg_web/controllers/page_html/home.html.heex +++ b/lib/chicken_egg_web/controllers/page_html/home.html.heex @@ -1,237 +1,4 @@ <.flash_group flash={@flash} /> - -
-
- -

- Phoenix Framework - - v<%= Application.spec(:phoenix, :vsn) %> - -

-

- Peace of mind from prototype to production. -

-

- Build rich, interactive web applications quickly, with less code and fewer moving parts. Join our growing community of developers using Phoenix to craft APIs, HTML5 apps and more, for fun or at scale. -

- -
+
+
diff --git a/lib/chicken_egg_web/live/index_live.ex b/lib/chicken_egg_web/live/index_live.ex new file mode 100644 index 0000000..92e27cc --- /dev/null +++ b/lib/chicken_egg_web/live/index_live.ex @@ -0,0 +1,46 @@ +defmodule ChickenEggWeb.IndexLive do + use ChickenEggWeb, :live_view + + alias ChickenEggWeb.ChickenComponents + + def render(assigns) do + ~H""" +
+ + +
+
+ +
+
+
+ """ + end + + def mount(_params, _session, socket) do + eggs = [] + + {:ok, + socket + |> assign(:chicken, %{x: 300, y: 200}) + |> stream(:eggs, eggs)} + end + + def handle_event("boak", _params, socket) do + %{x: cx, y: cy} = socket.assigns.chicken + new_chicken = %{x: Enum.random(1..800), y: Enum.random(1..600)} + + new_egg = + %{id: "egg#{cx}#{cy}", x: cx, y: cy} + |> IO.inspect() + + {:noreply, + socket + |> assign(:chicken, new_chicken) + |> stream_insert(:eggs, new_egg)} + end +end diff --git a/lib/chicken_egg_web/router.ex b/lib/chicken_egg_web/router.ex index 783835d..fcf7744 100644 --- a/lib/chicken_egg_web/router.ex +++ b/lib/chicken_egg_web/router.ex @@ -17,7 +17,7 @@ defmodule ChickenEggWeb.Router do scope "/", ChickenEggWeb do pipe_through :browser - get "/", PageController, :home + live "/", IndexLive end # Other scopes may use custom stacks.