Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/unfinal_web/live/editor_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ defmodule UnfinalWeb.EditorLive do
writer? = writer?(segments, session, claimed_namespace)

if connected?(socket) and writer?,
do: UnfinalWeb.Presence.track(self(), "editing", storage_path, %{path: storage_path})
do: UnfinalWeb.Presence.track(self(), "editing", storage_path, %{path: storage_path, joined_at: System.system_time(:second)})

if connected?(socket) and not writer?,
do: Phoenix.PubSub.subscribe(Unfinal.PubSub, Documents.topic(storage_path))
Expand Down
14 changes: 12 additions & 2 deletions lib/unfinal_web/live/live_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ defmodule UnfinalWeb.LiveLive do
{:ok,
assign(socket,
active_paths: active_paths,
sorted_paths: sorted_paths(),
excerpts: excerpts(active_paths, %{}),
authenticated: authenticated,
user: user,
Expand All @@ -34,6 +35,7 @@ defmodule UnfinalWeb.LiveLive do
{:ok,
assign(socket,
active_paths: MapSet.new(),
sorted_paths: [],
excerpts: %{},
authenticated: authenticated,
user: user,
Expand All @@ -59,7 +61,7 @@ defmodule UnfinalWeb.LiveLive do

excerpts = excerpts(active_paths, socket.assigns.excerpts)

{:noreply, assign(socket, active_paths: active_paths, excerpts: excerpts)}
{:noreply, assign(socket, active_paths: active_paths, sorted_paths: sorted_paths(), excerpts: excerpts)}
end

def handle_info({:content_updated, path, %{content: content}}, socket) do
Expand Down Expand Up @@ -88,6 +90,14 @@ defmodule UnfinalWeb.LiveLive do
@topic |> Presence.list() |> Map.keys() |> MapSet.new()
end

defp sorted_paths do
@topic
|> Presence.list()
|> Enum.map(fn {_key, %{metas: [meta | _]}} -> {meta.path, meta.joined_at} end)
|> Enum.sort_by(fn {_, ts} -> -ts end)
|> Enum.map(fn {path, _} -> path end)
end

defp excerpts(active_paths, current_excerpts) do
active_paths
|> Enum.map(fn path -> {path, initial_content(path, current_excerpts)} end)
Expand Down Expand Up @@ -137,7 +147,7 @@ defmodule UnfinalWeb.LiveLive do

<div :if={!Enum.empty?(@active_paths)} class="space-y-3">
<a
:for={path <- Enum.sort(@active_paths)}
:for={path <- @sorted_paths}
href={document_href(path)}
class="block rounded-2xl border border-stone-200 bg-white px-5 py-4 shadow-sm shadow-stone-200/40 transition hover:border-stone-300 hover:shadow-md"
>
Expand Down
Loading