From 8296b78d3e4b3b3030574fc8a639bc59223af5df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BCdiger=20Diedrich?= Date: Sun, 2 Jun 2024 15:55:18 +0200 Subject: [PATCH] refactor pagination buttons --- lib/something_erlang_web/live/thread_live.ex | 33 ++++++-------------- 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/lib/something_erlang_web/live/thread_live.ex b/lib/something_erlang_web/live/thread_live.ex index 77c0922..220aae2 100644 --- a/lib/something_erlang_web/live/thread_live.ex +++ b/lib/something_erlang_web/live/thread_live.ex @@ -83,30 +83,15 @@ defmodule SomethingErlangWeb.ThreadLive do """ end - defp label_button(%{label: "«", page: page} = assigns), - do: ~H""" - <.icon name="hero-chevron-double-left-mini" /><%= page %> - """ - - defp label_button(%{label: "‹", page: page} = assigns), - do: ~H""" - <.icon name="hero-chevron-left-mini" /><%= page %> - """ - - defp label_button(%{label: "›", page: page} = assigns), - do: ~H""" - <%= page %><.icon name="hero-chevron-right-mini" /> - """ - - defp label_button(%{label: "»", page: page} = assigns), - do: ~H""" - <%= page %><.icon name="hero-chevron-double-right-mini" /> - """ - - defp label_button(%{page: page} = assigns), - do: ~H""" - <%= page %> - """ + defp label_button(%{label: label} = assigns) do + case label do + "«" -> ~H{<.icon name="hero-chevron-double-left-mini" /><%= @page %>} + "‹" -> ~H{<.icon name="hero-chevron-left-mini" /><%= @page %>} + "›" -> ~H{<%= @page %><.icon name="hero-chevron-right-mini" />} + "»" -> ~H{<%= @page %><.icon name="hero-chevron-double-right-mini" />} + _ -> ~H{<%= @page %>} + end + end defp buttons(thread) do %{page: page_number, page_count: page_count} = thread