Small updates and fixes

This commit is contained in:
Nathan Chapman 2024-11-20 09:28:19 -07:00
parent 8336350ed4
commit 35b9fab724
7 changed files with 62 additions and 23 deletions

View File

@ -293,10 +293,31 @@ input[type="checkbox"] {
}
}
.dl-default {
display: flex;
flex-direction: column;
gap: 1rem;
& dt {
font-weight: bold;
}
& dd {
padding: 1rem;
background-color: var(--grey-dark);
margin: 0;
border-radius: 1rem;
}
}
.error {
color: var(--red);
}
.back-link {
margin-bottom: 2rem;
}
.banner {
max-width: 1024px;
margin: 0 auto;
@ -313,3 +334,16 @@ input[type="checkbox"] {
font-size: 1.75em;
}
}
.text-content {
& h1,
h2,
h3,
h4,
h5,
h6,
p:not(:last-child) {
margin-bottom: 1rem;
}
}

View File

@ -130,7 +130,7 @@ defmodule SendIt.Marketing do
"""
def list_messages do
Repo.all(Message)
Repo.all(from m in Message, order_by: [desc: m.inserted_at])
end
@doc """

View File

@ -495,14 +495,12 @@ defmodule SendItWeb.CoreComponents do
def list(assigns) do
~H"""
<div>
<dl>
<dl class="dl-default">
<div :for={item <- @item}>
<dt><%= item.title %></dt>
<dd><%= render_slot(item) %></dd>
</div>
</dl>
</div>
"""
end
@ -518,10 +516,9 @@ defmodule SendItWeb.CoreComponents do
def back(assigns) do
~H"""
<div>
<div class="back-link">
<.link navigate={@navigate}>
<.icon name="hero-arrow-left-solid" />
<%= render_slot(@inner_block) %>
&larr; <%= render_slot(@inner_block) %>
</.link>
</div>
"""
@ -627,4 +624,11 @@ defmodule SendItWeb.CoreComponents do
def translate_errors(errors, field) when is_list(errors) do
for {^field, {msg, opts}} <- errors, do: translate_error({msg, opts})
end
@doc """
Converts time into readable time
"""
def format_date(date) do
Calendar.strftime(date, "%a, %b %d %Y")
end
end

View File

@ -1,6 +1,7 @@
<.back navigate={~p"/contacts"}>Back to contacts</.back>
<.header>
Contact <%= @contact.id %>
<:subtitle>This is a contact record from your database.</:subtitle>
Contact
<:actions>
<.link patch={~p"/contacts/#{@contact}/edit"} phx-click={JS.push_focus()}>
<.button>Edit contact</.button>
@ -14,8 +15,6 @@
<:item title="Subscribed"><%= @contact.subscribed %></:item>
</.list>
<.back navigate={~p"/contacts"}>Back to contacts</.back>
<.modal :if={@live_action == :edit} id="contact-modal" show on_cancel={JS.patch(~p"/contacts/#{@contact}")}>
<.live_component
module={SendItWeb.ContactLive.FormComponent}

View File

@ -34,7 +34,7 @@ defmodule SendItWeb.MessageLive.Index do
@impl true
def handle_info({SendItWeb.MessageLive.FormComponent, {:saved, message}}, socket) do
{:noreply, stream_insert(socket, :messages, message)}
{:noreply, stream_insert(socket, :messages, message, at: 0)}
end
@impl true

View File

@ -16,7 +16,7 @@
<%= message.subject %>
</:col>
<:col :let={{_id, message}} label="Created">
<%= message.inserted_at %>
<%= format_date(message.inserted_at) %>
</:col>
<:action :let={{id, message}}>
<.link

View File

@ -1,6 +1,8 @@
<.back navigate={~p"/messages"}>Back to messages</.back>
<.header>
Message <%= @message.id %>
<:subtitle>This is a message record from your database.</:subtitle>
Message
<:subtitle>Sent: <%= format_date(@message.inserted_at) %></:subtitle>
</.header>
<.list>
@ -8,12 +10,12 @@
<%= @message.subject %>
</:item>
<:item title="Content">
<%= @message.content %>
<div class="text-content">
<%= raw(@message.content) %>
</div>
</:item>
</.list>
<.back navigate={~p"/messages"}>Back to messages</.back>
<.modal
:if={@live_action == :edit}
id="message-modal"