devel #189

Merged
inhji merged 8 commits from devel into main 2023-07-07 12:04:36 +02:00
4 changed files with 47 additions and 11 deletions

View file

@ -40,14 +40,28 @@ defmodule Chiya.Notes do
end
def list_notes_by_channel(%Chiya.Channels.Channel{} = channel) do
Note
|> join(:inner, [n], c in assoc(n, :channels))
|> where([n, c], c.id == ^channel.id)
list_notes_by_channel_query(channel)
|> order_by([n], desc: n.updated_at, desc: n.published_at)
|> Repo.all()
|> Repo.preload(@preloads)
end
def list_notes_by_channel_published(%Chiya.Channels.Channel{} = channel) do
list_notes_by_channel_query(channel)
|> order_by([n], desc: n.published_at)
end
def list_notes_by_channel_updated(%Chiya.Channels.Channel{} = channel) do
list_notes_by_channel_query(channel)
|> order_by([n], desc: n.published_at)
end
defp list_notes_by_channel_query(%Chiya.Channels.Channel{} = channel) do
Note
|> join(:inner, [n], c in assoc(n, :channels))
|> where([n, c], c.id == ^channel.id)
end
@doc """
Preloads a note

View file

@ -35,7 +35,7 @@
</style>
</head>
<body class="bg-theme-background | h-feed hfeed">
<aside class="max-w-2xl mx-auto block">
<aside class="block">
<%= raw @settings.custom_html %>
</aside>
<header class="my-8 block px-3">
@ -48,7 +48,12 @@
</li>
<li>
<a href="/about">
<.icon name="hero-hand-raised" /> About
<.icon name="hero-face-smile" /> About
</a>
</li>
<li>
<a href="/wiki">
<.icon name="hero-paper-clip" /> Wiki
</a>
</li>
<%= if @current_user do %>

View file

@ -67,14 +67,21 @@ defmodule ChiyaWeb.PageController do
def wiki(conn, _params) do
settings = conn.assigns.settings
channel =
[notes_updated, notes_published] =
case settings.wiki_channel_id do
nil -> nil
id -> Chiya.Channels.get_channel!(id) |> Chiya.Channels.preload_channel_public()
nil ->
[nil, nil]
id ->
channel = Chiya.Channels.get_channel!(id)
updated = Chiya.Notes.list_notes_by_channel_updated(channel)
published = Chiya.Notes.list_notes_by_channel_published(channel)
[updated, published]
end
render(conn, :wiki,
channel: channel,
notes_updated: notes_updated,
notes_published: notes_published,
page_title: "Wiki"
)
end

View file

@ -2,8 +2,18 @@
<:title>Wiki</:title>
</.header>
<section class="prose prose-gruvbox">
<%= Markdown.render(@channel.content) |> raw %>
</section>
<%= if @channel do %>
<div class="w-full mt-6 sm:w-auto flex flex-col gap-1.5">
<.note_list notes={@channel.notes} layout={@channel.layout} />
</div>
<section class="flex flex-col md:col-row">
<div class="w-full mt-6 sm:w-auto flex flex-1 flex-col gap-1.5">
<.note_list notes={@notes_updated} layout={@channel.layout} />
</div>
<div class="w-full mt-6 sm:w-auto flex flex-1 flex-col gap-1.5">
<.note_list notes={@notes_published} layout={@channel.layout} />
</div>
</section>
<% end %>