devel #228
9 changed files with 59 additions and 20 deletions
|
@ -31,6 +31,7 @@ defmodule ChiyaWeb.CoreComponents do
|
||||||
end
|
end
|
||||||
|
|
||||||
attr :class, :string, default: nil
|
attr :class, :string, default: nil
|
||||||
|
|
||||||
def darkmode_toggle(assigns) do
|
def darkmode_toggle(assigns) do
|
||||||
~H"""
|
~H"""
|
||||||
<.link href="#" id="dark-mode-toggle" class={["text-sm leading-6", @class]}>
|
<.link href="#" id="dark-mode-toggle" class={["text-sm leading-6", @class]}>
|
||||||
|
|
|
@ -4,12 +4,7 @@
|
||||||
</.error>
|
</.error>
|
||||||
|
|
||||||
<.input field={f[:name]} type="text" />
|
<.input field={f[:name]} type="text" />
|
||||||
<.input field={f[:content]}
|
<.input field={f[:content]} type="textarea" label="Content" rows="15" class="font-mono" />
|
||||||
type="textarea"
|
|
||||||
label="Content"
|
|
||||||
rows="15"
|
|
||||||
class="font-mono"
|
|
||||||
/>
|
|
||||||
<.input field={f[:slug]} type="text" label="Slug" />
|
<.input field={f[:slug]} type="text" label="Slug" />
|
||||||
<.input field={f[:published_at]} type="datetime-local" label="Published at" />
|
<.input field={f[:published_at]} type="datetime-local" label="Published at" />
|
||||||
<.input
|
<.input
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
<section class="max-w-2xl mx-auto">
|
<section class="max-w-2xl mx-auto">
|
||||||
<article class="h-card hcard">
|
<article class="h-card hcard">
|
||||||
|
|
||||||
<section class="flex gap-3">
|
<section class="flex gap-3">
|
||||||
<img
|
<img
|
||||||
class="rounded-lg block text-center w-28 h-28 | u-photo"
|
class="rounded-lg block text-center w-28 h-28 | u-photo"
|
||||||
|
@ -10,7 +9,6 @@
|
||||||
<span class="p-name"><%= @user.name %></span>
|
<span class="p-name"><%= @user.name %></span>
|
||||||
<:subtitle><%= @user.bio %></:subtitle>
|
<:subtitle><%= @user.bio %></:subtitle>
|
||||||
</.header>
|
</.header>
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<%= if @note do %>
|
<%= if @note do %>
|
||||||
|
|
|
@ -6,8 +6,11 @@
|
||||||
<%= if @current_user do %>
|
<%= if @current_user do %>
|
||||||
<section class="max-w-2xl mx-auto mt-8">
|
<section class="max-w-2xl mx-auto mt-8">
|
||||||
<ul class="flex gap-3">
|
<ul class="flex gap-3">
|
||||||
<li><a href={~p"/admin/notes/#{@note}/edit"} class="button">
|
<li>
|
||||||
<.icon name="hero-pencil-square" /> Edit</a></li>
|
<a href={~p"/admin/notes/#{@note}/edit"} class="button">
|
||||||
|
<.icon name="hero-pencil-square" /> Edit
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
<li><a href={~p"/admin/notes/#{@note}"} class="button">Show in Admin</a></li>
|
<li><a href={~p"/admin/notes/#{@note}"} class="button">Show in Admin</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</section>
|
</section>
|
||||||
|
|
|
@ -11,8 +11,8 @@ defmodule ChiyaWeb.Indie.Micropub do
|
||||||
with {:ok, note_attrs} <- get_attrs(type, properties, channel_id),
|
with {:ok, note_attrs} <- get_attrs(type, properties, channel_id),
|
||||||
{:ok, note} <- Chiya.Notes.create_note(note_attrs) do
|
{:ok, note} <- Chiya.Notes.create_note(note_attrs) do
|
||||||
create_photos(note, properties)
|
create_photos(note, properties)
|
||||||
Logger.info("Note created!")
|
|
||||||
|
|
||||||
|
Logger.info("Note created!")
|
||||||
{:ok, :created, Chiya.Notes.Note.note_url(note)}
|
{:ok, :created, Chiya.Notes.Note.note_url(note)}
|
||||||
else
|
else
|
||||||
error ->
|
error ->
|
||||||
|
@ -23,6 +23,33 @@ defmodule ChiyaWeb.Indie.Micropub do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def find_note(note_url) do
|
||||||
|
slug = Chiya.Notes.Note.note_slug(note_url)
|
||||||
|
Chiya.Notes.get_note_preloaded_by_slug(slug)
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_note(note, replace, add, _delete) do
|
||||||
|
settings = Chiya.Site.get_settings()
|
||||||
|
channel_id = settings.micropub_channel_id
|
||||||
|
|
||||||
|
properties =
|
||||||
|
%{}
|
||||||
|
|> Enum.into(replace)
|
||||||
|
|> Enum.into(add)
|
||||||
|
|
||||||
|
with {:ok, note_attrs} <- get_attrs("entry", properties, channel_id),
|
||||||
|
{:ok, note} <- Chiya.Notes.update_note(note, note_attrs) do
|
||||||
|
Logger.info("Note updated!")
|
||||||
|
{:ok, note}
|
||||||
|
else
|
||||||
|
error ->
|
||||||
|
Logger.error("Error occurred while creating note from micropub:")
|
||||||
|
Logger.error(inspect(error))
|
||||||
|
|
||||||
|
{:error, :invalid_request}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
defp create_photos(note, properties) do
|
defp create_photos(note, properties) do
|
||||||
properties
|
properties
|
||||||
|> Props.get_photos()
|
|> Props.get_photos()
|
||||||
|
|
|
@ -41,8 +41,14 @@ defmodule ChiyaWeb.Indie.MicropubHandler do
|
||||||
end
|
end
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def handle_update(_, _, _, _, _) do
|
def handle_update(url, replace, add, delete, access_token) do
|
||||||
{:error, :insufficient_scope}
|
with :ok <- Micropub.verify_token(access_token),
|
||||||
|
{:ok, note} <- Micropub.find_note(url),
|
||||||
|
{:ok, note} <- Micropub.update_note(note, replace, add, delete) do
|
||||||
|
:ok
|
||||||
|
else
|
||||||
|
error -> error
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
|
|
|
@ -4,6 +4,7 @@ defmodule ChiyaWeb.MicropubTest do
|
||||||
alias ChiyaWeb.Indie.Micropub
|
alias ChiyaWeb.Indie.Micropub
|
||||||
alias Chiya.Notes.Note
|
alias Chiya.Notes.Note
|
||||||
alias Chiya.Channels.Channel
|
alias Chiya.Channels.Channel
|
||||||
|
import Chiya.NoteFixtures
|
||||||
|
|
||||||
@valid_props %{
|
@valid_props %{
|
||||||
"content" => ["this is a test"]
|
"content" => ["this is a test"]
|
||||||
|
@ -22,6 +23,14 @@ defmodule ChiyaWeb.MicropubTest do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "update_note" do
|
||||||
|
test "updates a note" do
|
||||||
|
note = note_fixture()
|
||||||
|
|
||||||
|
assert :ok = Micropub.update_note(note, %{"content" => ["replaced content"]})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
{:ok, channel} =
|
{:ok, channel} =
|
||||||
Chiya.Channels.create_channel(%{
|
Chiya.Channels.create_channel(%{
|
||||||
|
|
Loading…
Reference in a new issue