feat: Show timeline
This commit is contained in:
parent
3a9c23da95
commit
a4af27e5b7
5 changed files with 27 additions and 5 deletions
|
|
@ -1,7 +1,12 @@
|
|||
## Backend
|
||||
|
||||
- [ ] Posting
|
||||
- [x] Making posts locally
|
||||
- [ ] Figuring out follower list
|
||||
- [ ] Sending to followers
|
||||
- [ ] Timeline
|
||||
- [x] My posts
|
||||
- [ ] Posts from accounts you follow
|
||||
- [ ] Deleting posts
|
||||
- [x] Following
|
||||
- [ ] Unfollowing
|
||||
|
|
@ -13,8 +18,10 @@
|
|||
|
||||
## UX
|
||||
|
||||
- [ ] Posting
|
||||
- [x] Posting
|
||||
- [ ] Timeline
|
||||
- [~] My posts
|
||||
- [ ] Posts from accounts you follow
|
||||
- [ ] Deleting posts
|
||||
- [~] Following
|
||||
- [ ] Unfollowing
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ defmodule Postland.Activity do
|
|||
field :actor_id, :string
|
||||
field :type, :string
|
||||
field :data, :map
|
||||
|
||||
timestamps()
|
||||
end
|
||||
|
||||
def changeset(attrs) do
|
||||
|
|
|
|||
|
|
@ -1,4 +1,9 @@
|
|||
defmodule Postland.Post do
|
||||
defmodule Postland.Timeline do
|
||||
alias Postland.Activity
|
||||
alias Postland.Repo
|
||||
|
||||
import Ecto.Query
|
||||
|
||||
def html_content(activity) do
|
||||
case Map.get(activity.data, "object") do
|
||||
map when is_map(map) ->
|
||||
|
|
@ -13,4 +18,11 @@ defmodule Postland.Post do
|
|||
""
|
||||
end
|
||||
end
|
||||
|
||||
def timeline do
|
||||
from(a in Activity, where: a.type == "Create", order_by: [desc: a.inserted_at])
|
||||
# Only accounts I'm following + myself
|
||||
# Only notes
|
||||
|> Repo.all()
|
||||
end
|
||||
end
|
||||
|
|
@ -36,6 +36,7 @@ defmodule PostlandWeb.CoreComponents do
|
|||
id="post-body"
|
||||
class="block w-full resize-none border-0 bg-transparent py-1.5 text-gray-900 placeholder:text-gray-400 focus:ring-0 sm:text-sm sm:leading-6"
|
||||
placeholder="post body"
|
||||
value={@post_content}
|
||||
></textarea>
|
||||
<!-- Spacer element to match the height of the toolbar -->
|
||||
<div class="py-2" aria-hidden="true">
|
||||
|
|
@ -67,7 +68,7 @@ defmodule PostlandWeb.CoreComponents do
|
|||
~H"""
|
||||
<div class="divide-y divide-gray-200 overflow-hidden rounded-lg bg-white shadow">
|
||||
<div class="px-4 py-5 sm:p-6">
|
||||
<%= {:safe, Postland.Post.html_content(@post)} %>
|
||||
<%= {:safe, Postland.Timeline.html_content(@post)} %>
|
||||
</div>
|
||||
<div class="px-4 py-4 sm:px-6">
|
||||
<!-- Content goes here -->
|
||||
|
|
|
|||
|
|
@ -13,13 +13,13 @@ defmodule PostlandWeb.TimelineLive do
|
|||
end
|
||||
|
||||
def mount(_params, _session, socket) do
|
||||
{:ok, socket |> assign(:post, "") |> stream(:posts, [])}
|
||||
{:ok, socket |> assign(:post, "") |> stream(:posts, Postland.Timeline.timeline())}
|
||||
end
|
||||
|
||||
def handle_event("create_post", %{"post" => post}, socket) do
|
||||
{:ok, post} = Postland.Activities.record_markdown_post(post)
|
||||
|
||||
{:noreply, socket |> assign(:post, "") |> stream_insert(:posts, post)}
|
||||
{:noreply, socket |> assign(:post, "") |> stream_insert(:posts, post, at: 0)}
|
||||
end
|
||||
|
||||
def handle_event("change_post", %{"post" => post}, socket) do
|
||||
|
|
|
|||
Loading…
Reference in a new issue