From e0ad13ee6cb121c7b355479fa2d7cc2d87aa7ea5 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Sat, 21 Nov 2020 20:11:17 -0700 Subject: [PATCH] preview first line only (#65) --- lib/planner/tasks/task.ex | 4 ++++ lib/planner_web/live/tasks_components.ex | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/planner/tasks/task.ex b/lib/planner/tasks/task.ex index 89dd6e0..121330d 100644 --- a/lib/planner/tasks/task.ex +++ b/lib/planner/tasks/task.ex @@ -26,5 +26,9 @@ defmodule Planner.Tasks.Task do change(task, finished_at: now()) end + def preview(task) do + hd(String.split(task.value, "\n")) + end + defp now(), do: NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second) end diff --git a/lib/planner_web/live/tasks_components.ex b/lib/planner_web/live/tasks_components.ex index 41bf8e6..aa9f6f5 100644 --- a/lib/planner_web/live/tasks_components.ex +++ b/lib/planner_web/live/tasks_components.ex @@ -67,6 +67,8 @@ end defmodule TaskComponent do use Phoenix.LiveComponent + alias Planner.Tasks.Task + import PlannerWeb.Util def render(assigns) do @@ -111,7 +113,7 @@ defmodule TaskComponent do style: "display: block;" ) do %>
- <%= md_to_html(@task.value) %> + <%= md_to_html(Task.preview(@task)) %>
<% end %> <%= if(not is_nil(@task.due_at)) do %>