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

@@ -11,14 +11,23 @@ defmodule LabelmakerWeb.Tools do
|> Map.take(Constants.permitted_keys())
|> Map.new(fn {k, v} -> {String.to_atom(k), v} end)
|> Enum.map(fn
{:preview_height, _} -> {:preview_height, size + size * line_breaks}
{:preview_text, _} -> {:preview_text, String.split(label, "\\n")}
pair -> pair
{:label, label} ->
if String.length(label) > Constants.max_label_length(),
do: {:label, String.slice(label, 0, Constants.max_label_length())},
else: {:label, label}
{:preview_height, _} ->
{:preview_height, size + size * line_breaks}
{:preview_text, _} ->
{:preview_text, String.split(label, "\\n")}
pair ->
pair
end)
|> Enum.filter(fn
{:color, color} -> color in Constants.colors()
{:font, font} -> font in Constants.fonts()
{:label, label} -> String.length(label) <= Constants.max_label_length()
{:outline, outline} -> outline in Constants.outlines()
{:size, size} -> size in Constants.sizes()
_ -> true