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
|
## Backend
|
||||||
|
|
||||||
- [ ] Posting
|
- [ ] Posting
|
||||||
|
- [x] Making posts locally
|
||||||
|
- [ ] Figuring out follower list
|
||||||
|
- [ ] Sending to followers
|
||||||
- [ ] Timeline
|
- [ ] Timeline
|
||||||
|
- [x] My posts
|
||||||
|
- [ ] Posts from accounts you follow
|
||||||
- [ ] Deleting posts
|
- [ ] Deleting posts
|
||||||
- [x] Following
|
- [x] Following
|
||||||
- [ ] Unfollowing
|
- [ ] Unfollowing
|
||||||
|
|
@ -13,8 +18,10 @@
|
||||||
|
|
||||||
## UX
|
## UX
|
||||||
|
|
||||||
- [ ] Posting
|
- [x] Posting
|
||||||
- [ ] Timeline
|
- [ ] Timeline
|
||||||
|
- [~] My posts
|
||||||
|
- [ ] Posts from accounts you follow
|
||||||
- [ ] Deleting posts
|
- [ ] Deleting posts
|
||||||
- [~] Following
|
- [~] Following
|
||||||
- [ ] Unfollowing
|
- [ ] Unfollowing
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@ defmodule Postland.Activity do
|
||||||
field :actor_id, :string
|
field :actor_id, :string
|
||||||
field :type, :string
|
field :type, :string
|
||||||
field :data, :map
|
field :data, :map
|
||||||
|
|
||||||
|
timestamps()
|
||||||
end
|
end
|
||||||
|
|
||||||
def changeset(attrs) do
|
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
|
def html_content(activity) do
|
||||||
case Map.get(activity.data, "object") do
|
case Map.get(activity.data, "object") do
|
||||||
map when is_map(map) ->
|
map when is_map(map) ->
|
||||||
|
|
@ -13,4 +18,11 @@ defmodule Postland.Post do
|
||||||
""
|
""
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
@ -36,6 +36,7 @@ defmodule PostlandWeb.CoreComponents do
|
||||||
id="post-body"
|
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"
|
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"
|
placeholder="post body"
|
||||||
|
value={@post_content}
|
||||||
></textarea>
|
></textarea>
|
||||||
<!-- Spacer element to match the height of the toolbar -->
|
<!-- Spacer element to match the height of the toolbar -->
|
||||||
<div class="py-2" aria-hidden="true">
|
<div class="py-2" aria-hidden="true">
|
||||||
|
|
@ -67,7 +68,7 @@ defmodule PostlandWeb.CoreComponents do
|
||||||
~H"""
|
~H"""
|
||||||
<div class="divide-y divide-gray-200 overflow-hidden rounded-lg bg-white shadow">
|
<div class="divide-y divide-gray-200 overflow-hidden rounded-lg bg-white shadow">
|
||||||
<div class="px-4 py-5 sm:p-6">
|
<div class="px-4 py-5 sm:p-6">
|
||||||
<%= {:safe, Postland.Post.html_content(@post)} %>
|
<%= {:safe, Postland.Timeline.html_content(@post)} %>
|
||||||
</div>
|
</div>
|
||||||
<div class="px-4 py-4 sm:px-6">
|
<div class="px-4 py-4 sm:px-6">
|
||||||
<!-- Content goes here -->
|
<!-- Content goes here -->
|
||||||
|
|
|
||||||
|
|
@ -13,13 +13,13 @@ defmodule PostlandWeb.TimelineLive do
|
||||||
end
|
end
|
||||||
|
|
||||||
def mount(_params, _session, socket) do
|
def mount(_params, _session, socket) do
|
||||||
{:ok, socket |> assign(:post, "") |> stream(:posts, [])}
|
{:ok, socket |> assign(:post, "") |> stream(:posts, Postland.Timeline.timeline())}
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_event("create_post", %{"post" => post}, socket) do
|
def handle_event("create_post", %{"post" => post}, socket) do
|
||||||
{:ok, post} = Postland.Activities.record_markdown_post(post)
|
{: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
|
end
|
||||||
|
|
||||||
def handle_event("change_post", %{"post" => post}, socket) do
|
def handle_event("change_post", %{"post" => post}, socket) do
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue