don't erase what a user wrote when they go over max_label_length

This commit is contained in:
Gavin McDonald
2025-05-11 11:48:56 -04:00
parent 590c4014df
commit 8a42947995
3 changed files with 25 additions and 11 deletions

View File

@@ -6,7 +6,6 @@ defmodule LabelmakerWeb.Home do
def mount(_params, _session, socket) do
assigns =
Constants.defaults()
|> Map.replace(:label, "")
|> Map.merge(Constants.preview())
|> Enum.to_list()
@@ -45,9 +44,13 @@ defmodule LabelmakerWeb.Home do
]}
style={"height: calc(2rem + #{@preview_height}px); color: #{@color}; font-family: #{@font}; font-size: #{@size}px; line-height: #{@size}px;"}
>
<%= for {str, i} <- Enum.with_index(@preview_text) do %>
{str}
{if i < length(@preview_text) - 1, do: raw("<br />")}
<%= if String.length(@label) > Constants.max_label_length() do %>
{Constants.max_label_error()}
<% else %>
<%= for {str, i} <- Enum.with_index(@preview_text) do %>
{str}
{if i < length(@preview_text) - 1, do: raw("<br />")}
<% end %>
<% end %>
</div>