diff --git a/lib/labelmaker_web/live/home.ex b/lib/labelmaker_web/live/home.ex index e5c0339..1a93723 100644 --- a/lib/labelmaker_web/live/home.ex +++ b/lib/labelmaker_web/live/home.ex @@ -2,19 +2,64 @@ defmodule LabelmakerWeb.Home do use LabelmakerWeb, :live_view def mount(_params, _session, socket) do - {:ok, assign(socket, :label, "")} + {:ok, + assign(socket, + label: "", + font: "Helvetica", + color: "black", + size: "24" + )} end - def handle_event("update_label", %{"label" => label}, socket) do - {:noreply, assign(socket, :label, label)} + def handle_event("update_label", params, socket) do + {:noreply, + assign(socket, + label: params["label"] || "", + font: params["font"] || "Helvetica", + color: params["color"] || "black", + size: params["size"] || "24" + )} + end + + def handle_event("make_label", params, socket) do + {:noreply, push_navigate(socket, to: ~p"/#{params["label"]}?#{Map.drop(params, ["label"])}")} end def render(assigns) do ~H"""
-

|{@label}|

-
- +

Label Maker

+ + +
+ {@label} +
+ + + +
""" diff --git a/lib/labelmaker_web/live/label.ex b/lib/labelmaker_web/live/label.ex index d8f7d22..908db21 100644 --- a/lib/labelmaker_web/live/label.ex +++ b/lib/labelmaker_web/live/label.ex @@ -19,12 +19,11 @@ defmodule LabelmakerWeb.Label do |> Map.merge(params) |> Map.take(@permitted_keys) - IO.inspect(options) filename = "#{options["label"]}.png" filepath = Path.join(@label_dir, filename) unless File.exists?(filepath) do - generate_label_image(options, filepath) + generate_image(options, filepath) end {:ok, @@ -43,7 +42,7 @@ defmodule LabelmakerWeb.Label do """ end - defp generate_label_image(options, filepath) do + defp generate_image(options, filepath) do args = [ "-background", "none", @@ -58,14 +57,5 @@ defmodule LabelmakerWeb.Label do ] {_, 0} = System.cmd("magick", args) - - IO.puts(filepath) - # png_binary = File.read!(filepath) - # File.rm(tmp_file) - # Base.encode64(png_binary) end - - # defp get_image_settings(socket) do - # - # end end