From 96d8f720c0dca0f3b186c394661a3999173ebfab Mon Sep 17 00:00:00 2001 From: Afonso Martins Date: Wed, 18 Sep 2024 21:48:22 +0100 Subject: [PATCH 01/17] Feat: update list_unarchived_links_by_index --- lib/cesium_link/links.ex | 6 +++++- lib/cesium_link/links/link.ex | 3 ++- .../migrations/20240918181533_add_link_scheduling.exs | 9 +++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 priv/repo/migrations/20240918181533_add_link_scheduling.exs diff --git a/lib/cesium_link/links.ex b/lib/cesium_link/links.ex index 9d05aa4..5d32da7 100644 --- a/lib/cesium_link/links.ex +++ b/lib/cesium_link/links.ex @@ -64,7 +64,11 @@ defmodule CesiumLink.Links do """ def list_unarchived_links_by_index do - Repo.all(from l in Link, where: l.archived == false, order_by: [asc: l.index]) + Link + |> where([l], fragment("? > now()", l.publish_at)) + |> where([l], l.archived == false ) + |> order_by([l], asc: l.index) + |> Repo.all() end @doc """ diff --git a/lib/cesium_link/links/link.ex b/lib/cesium_link/links/link.ex index e30d9d5..c9f8d39 100644 --- a/lib/cesium_link/links/link.ex +++ b/lib/cesium_link/links/link.ex @@ -5,7 +5,7 @@ defmodule CesiumLink.Links.Link do use CesiumLink.Schema @required_fields ~w(name emoji url attention edited_at)a - @optional_fields ~w(index archived visits)a + @optional_fields ~w(index archived visits publish_at)a schema "links" do field :archived, :boolean, default: false @@ -16,6 +16,7 @@ defmodule CesiumLink.Links.Link do field :url, :string field :visits, :integer, default: 0 field :edited_at, :utc_datetime + field :publish_at, :utc_datetime timestamps(type: :utc_datetime) end diff --git a/priv/repo/migrations/20240918181533_add_link_scheduling.exs b/priv/repo/migrations/20240918181533_add_link_scheduling.exs new file mode 100644 index 0000000..2fd3685 --- /dev/null +++ b/priv/repo/migrations/20240918181533_add_link_scheduling.exs @@ -0,0 +1,9 @@ +defmodule CesiumLink.Repo.Migrations.AddLinkScheduling do + use Ecto.Migration + + def change do + alter table(:links) do + add :publish_at, :utc_datetime + end + end +end From 994214819f68954534b444bf69663341e084a5e8 Mon Sep 17 00:00:00 2001 From: Afonso Martins Date: Wed, 18 Sep 2024 21:51:14 +0100 Subject: [PATCH 02/17] Code Format --- lib/cesium_link/links.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cesium_link/links.ex b/lib/cesium_link/links.ex index 5d32da7..edab53a 100644 --- a/lib/cesium_link/links.ex +++ b/lib/cesium_link/links.ex @@ -66,7 +66,7 @@ defmodule CesiumLink.Links do def list_unarchived_links_by_index do Link |> where([l], fragment("? > now()", l.publish_at)) - |> where([l], l.archived == false ) + |> where([l], l.archived == false) |> order_by([l], asc: l.index) |> Repo.all() end From 3f115897703978f5f61c679c1a8fb654054ef286 Mon Sep 17 00:00:00 2001 From: Afonso Martins Date: Wed, 18 Sep 2024 22:48:14 +0100 Subject: [PATCH 03/17] Feat:fregment update --- lib/cesium_link/links.ex | 2 +- lib/cesium_link_web/live/link_live/form_component.ex | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/cesium_link/links.ex b/lib/cesium_link/links.ex index edab53a..b194f77 100644 --- a/lib/cesium_link/links.ex +++ b/lib/cesium_link/links.ex @@ -65,7 +65,7 @@ defmodule CesiumLink.Links do """ def list_unarchived_links_by_index do Link - |> where([l], fragment("? > now()", l.publish_at)) + |> where([l], fragment("? <= now() OR ? IS NULL", l.publish_at, l.publish_at)) |> where([l], l.archived == false) |> order_by([l], asc: l.index) |> Repo.all() diff --git a/lib/cesium_link_web/live/link_live/form_component.ex b/lib/cesium_link_web/live/link_live/form_component.ex index dff7386..ec75d1d 100644 --- a/lib/cesium_link_web/live/link_live/form_component.ex +++ b/lib/cesium_link_web/live/link_live/form_component.ex @@ -19,6 +19,7 @@ defmodule CesiumLinkWeb.LinkLive.FormComponent do <.input field={@form[:emoji]} type="emoji" label="Emoji" /> <.input field={@form[:url]} type="text" label="URL" /> <.input field={@form[:attention]} type="checkbox" label="Attention" /> + <.input field={@form[:publish_at]} type="datetime-local" label="Publish At" /> <:actions> <.button phx-disable-with="Saving...">Save Link From 4c774262d919507edc4070a9ab42ab9b4a49fc9f Mon Sep 17 00:00:00 2001 From: Afonso Martins Date: Sun, 22 Sep 2024 20:24:41 +0100 Subject: [PATCH 04/17] requested changes links.ex --- lib/cesium_link/links.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cesium_link/links.ex b/lib/cesium_link/links.ex index b194f77..b2c8e13 100644 --- a/lib/cesium_link/links.ex +++ b/lib/cesium_link/links.ex @@ -66,7 +66,7 @@ defmodule CesiumLink.Links do def list_unarchived_links_by_index do Link |> where([l], fragment("? <= now() OR ? IS NULL", l.publish_at, l.publish_at)) - |> where([l], l.archived == false) + |> where([l], not l.archived) |> order_by([l], asc: l.index) |> Repo.all() end From 426dc0f4155d39ae4032bdddc08dd060f4bc8c70 Mon Sep 17 00:00:00 2001 From: Afonso Martins Date: Sun, 22 Sep 2024 20:47:13 +0100 Subject: [PATCH 05/17] Fix:time input shows up when link is going to be created --- lib/cesium_link_web/live/link_live/form_component.ex | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/cesium_link_web/live/link_live/form_component.ex b/lib/cesium_link_web/live/link_live/form_component.ex index ec75d1d..9f1e0a7 100644 --- a/lib/cesium_link_web/live/link_live/form_component.ex +++ b/lib/cesium_link_web/live/link_live/form_component.ex @@ -19,7 +19,9 @@ defmodule CesiumLinkWeb.LinkLive.FormComponent do <.input field={@form[:emoji]} type="emoji" label="Emoji" /> <.input field={@form[:url]} type="text" label="URL" /> <.input field={@form[:attention]} type="checkbox" label="Attention" /> - <.input field={@form[:publish_at]} type="datetime-local" label="Publish At" /> + <%= if @action == :new do %> + <.input field={@form[:publish_at]} type="datetime-local" label="Publish At" /> + <% end %> <:actions> <.button phx-disable-with="Saving...">Save Link From 5a1be77f5c2b674bb8fef5b063b90b27c19f9e7c Mon Sep 17 00:00:00 2001 From: Afonso Martins Date: Fri, 27 Sep 2024 23:16:37 +0100 Subject: [PATCH 06/17] feat: opacity in schedul link --- .../live/link_live/index.html.heex | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/lib/cesium_link_web/live/link_live/index.html.heex b/lib/cesium_link_web/live/link_live/index.html.heex index 3be9618..f80fb76 100644 --- a/lib/cesium_link_web/live/link_live/index.html.heex +++ b/lib/cesium_link_web/live/link_live/index.html.heex @@ -15,30 +15,46 @@ <.table id="links" rows={@streams.links} phx-hook="Sorting"> - <:col :let={{_id, _link}}><.icon name="hero-bars-3 cursor-pointer ml-4" class="handle w-5 h-5" /> + <:col :let={{_id, _link}}> + <% publish_future = _link.publish_at && DateTime.compare(_link.publish_at, DateTime.utc_now()) == :gt %> + <.icon name="hero-bars-3 cursor-pointer ml-4" class={"handle w-5 h-5 #{if publish_future, do: "opacity-50"}"} /> + <:col :let={{_id, link}} label="Name"> -

<%= link.name %>

+ <% publish_future = link.publish_at && DateTime.compare(link.publish_at, DateTime.utc_now()) == :gt %> +

<%= link.name %>

<:col :let={{_id, link}} label="Emoji"> - <.emoji code={link.emoji} /> + <% publish_future = link.publish_at && DateTime.compare(link.publish_at, DateTime.utc_now()) == :gt %> + + <.emoji code={link.emoji} /> + <:col :let={{_id, link}} label="URL"> - <.link target="_blank" class="hover:text-brand hover:underline" navigate={link.url}> + <% publish_future = link.publish_at && DateTime.compare(link.publish_at, DateTime.utc_now()) == :gt %> + <.link target="_blank" class={"hover:text-brand hover:underline #{if publish_future, do: "opacity-50"}"} navigate={link.url}> <%= truncate_elipsis(link.url, 50) %> - <:col :let={{_id, link}} label="Clicks"><%= link.visits %> +<:col :let={{_id, link}} label="Clicks"> + <% publish_future = link.publish_at && DateTime.compare(link.publish_at, DateTime.utc_now()) == :gt %> +

+ <%= link.visits %> +

+ <:col :let={{_id, link}} label="Attention"> - + <% publish_future = link.publish_at && DateTime.compare(link.publish_at, DateTime.utc_now()) == :gt %> + <:action :let={{_id, link}}> + <% publish_future = link.publish_at && DateTime.compare(link.publish_at, DateTime.utc_now()) == :gt %> <.link patch={~p"/admin/links/#{link}/edit"}> - <.icon name="hero-pencil" class="w-5 h-5" /> + <.icon name="hero-pencil" class={"w-5 h-5 #{if publish_future, do: "opacity-50"}"} /> <:action :let={{_id, link}}> + <% publish_future = link.publish_at && DateTime.compare(link.publish_at, DateTime.utc_now()) == :gt %> <.link patch={~p"/admin/links/#{link}/archive"}> - <.icon name="hero-archive-box" class="w-5 h-5" /> + <.icon name="hero-archive-box" class={"w-5 h-5 #{if publish_future, do: "opacity-50"}"} /> From e5227e0d7756f0633ca8a611c815a330d682e1e4 Mon Sep 17 00:00:00 2001 From: Afonso Martins Date: Fri, 27 Sep 2024 23:19:42 +0100 Subject: [PATCH 07/17] format code --- lib/cesium_link_web/live/link_live/index.html.heex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cesium_link_web/live/link_live/index.html.heex b/lib/cesium_link_web/live/link_live/index.html.heex index f80fb76..7c5d6f1 100644 --- a/lib/cesium_link_web/live/link_live/index.html.heex +++ b/lib/cesium_link_web/live/link_live/index.html.heex @@ -35,7 +35,7 @@ <%= truncate_elipsis(link.url, 50) %> -<:col :let={{_id, link}} label="Clicks"> + <:col :let={{_id, link}} label="Clicks"> <% publish_future = link.publish_at && DateTime.compare(link.publish_at, DateTime.utc_now()) == :gt %>

<%= link.visits %> From 740c13607b7e8d07e5134690817c53ffce1e65ea Mon Sep 17 00:00:00 2001 From: AfonsoMartins26 Date: Tue, 7 Jan 2025 23:45:20 +0000 Subject: [PATCH 08/17] feat: timer working --- assets/js/app.js | 2 + assets/js/hooks/timer.js | 35 ++++++++++++++ lib/cesium_link_web/live/link_live/index.ex | 11 +++++ .../live/link_live/index.html.heex | 46 ++++++++++++++----- 4 files changed, 82 insertions(+), 12 deletions(-) create mode 100644 assets/js/hooks/timer.js diff --git a/assets/js/app.js b/assets/js/app.js index 9e122be..faede14 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -24,12 +24,14 @@ import topbar from "../vendor/topbar" import { Sorting } from "./hooks/sorting" import { EmojiPicker } from "./hooks/emoji" import { QRCodeGenerator } from "./hooks/qrcode-generator" +import { Timer } from "./hooks/timer" // JS Hooks let Hooks = {} Hooks.Sorting = Sorting; Hooks.EmojiPicker = EmojiPicker; Hooks.QRCodeGenerator = QRCodeGenerator; +Hooks.Timer = Timer; let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content") let liveSocket = new LiveSocket("/live", Socket, { diff --git a/assets/js/hooks/timer.js b/assets/js/hooks/timer.js new file mode 100644 index 0000000..8c6cf1c --- /dev/null +++ b/assets/js/hooks/timer.js @@ -0,0 +1,35 @@ +export const Timer = { + mounted() { + const finishTime = parseInt(this.el.dataset.finishTime, 10); + const timerElement = this.el; + + const updateTimer = () => { + const now = Math.floor(Date.now() / 1000); + const remainingTime = Math.max(0, finishTime - now); + + if (remainingTime <= 0) { + clearInterval(timerInterval); + timerElement.textContent = "00:00:00"; + this.pushEvent("end-time", {}); + return; + } + + const hours = Math.floor(remainingTime / 3600); + const minutes = Math.floor((remainingTime % 3600) / 60); + const seconds = remainingTime % 60; + + timerElement.textContent = `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`; + }; + + const timerInterval = setInterval(updateTimer, 1000); + updateTimer(); + + this.cleanup = () => { + clearInterval(timerInterval); + }; + }, + + destroyed() { + this.cleanup(); + }, +}; diff --git a/lib/cesium_link_web/live/link_live/index.ex b/lib/cesium_link_web/live/link_live/index.ex index a1fa7c3..5b6a800 100644 --- a/lib/cesium_link_web/live/link_live/index.ex +++ b/lib/cesium_link_web/live/link_live/index.ex @@ -66,4 +66,15 @@ defmodule CesiumLinkWeb.LinkLive.Index do {:noreply, socket} end + + def handle_event("end-time",_, socket) do + {:noreply, socket |> push_navigate(to: ~p"/admin/links")} + end + + def publish_in_future?(link) do + case link.publish_at do + nil -> false + publish_at -> DateTime.compare(publish_at, DateTime.utc_now()) == :gt + end + end end diff --git a/lib/cesium_link_web/live/link_live/index.html.heex b/lib/cesium_link_web/live/link_live/index.html.heex index 7c5d6f1..df17f2b 100644 --- a/lib/cesium_link_web/live/link_live/index.html.heex +++ b/lib/cesium_link_web/live/link_live/index.html.heex @@ -15,50 +15,72 @@ <.table id="links" rows={@streams.links} phx-hook="Sorting"> - <:col :let={{_id, _link}}> - <% publish_future = _link.publish_at && DateTime.compare(_link.publish_at, DateTime.utc_now()) == :gt %> + <:col :let={{_id, link}} > + <% publish_future = publish_in_future?(link) %> <.icon name="hero-bars-3 cursor-pointer ml-4" class={"handle w-5 h-5 #{if publish_future, do: "opacity-50"}"} /> + <:col :let={{_id, link}} label="Name"> - <% publish_future = link.publish_at && DateTime.compare(link.publish_at, DateTime.utc_now()) == :gt %> + <% publish_future = publish_in_future?(link) %>

<%= link.name %>

+ <:col :let={{_id, link}} label="Emoji"> - <% publish_future = link.publish_at && DateTime.compare(link.publish_at, DateTime.utc_now()) == :gt %> + <% publish_future = publish_in_future?(link) %> <.emoji code={link.emoji} /> + <:col :let={{_id, link}} label="URL"> - <% publish_future = link.publish_at && DateTime.compare(link.publish_at, DateTime.utc_now()) == :gt %> + <% publish_future = publish_in_future?(link) %> <.link target="_blank" class={"hover:text-brand hover:underline #{if publish_future, do: "opacity-50"}"} navigate={link.url}> <%= truncate_elipsis(link.url, 50) %> + + <:col :let={{_id, link}} label="Time Left"> + <% publish_future = publish_in_future?(link) %> + <%= if publish_future do %> +
+ 00:00:00 +
+ <% else %> +

No time

+ <% end %> + + <:col :let={{_id, link}} label="Clicks"> - <% publish_future = link.publish_at && DateTime.compare(link.publish_at, DateTime.utc_now()) == :gt %> + <% publish_future = publish_in_future?(link) %>

<%= link.visits %>

+ <:col :let={{_id, link}} label="Attention"> - <% publish_future = link.publish_at && DateTime.compare(link.publish_at, DateTime.utc_now()) == :gt %> + <% publish_future = publish_in_future?(link) %> - - <:action :let={{_id, link}}> - <% publish_future = link.publish_at && DateTime.compare(link.publish_at, DateTime.utc_now()) == :gt %> + + + <:action :let={{_id, link}} > + <% publish_future = publish_in_future?(link) %> <.link patch={~p"/admin/links/#{link}/edit"}> <.icon name="hero-pencil" class={"w-5 h-5 #{if publish_future, do: "opacity-50"}"} /> - <:action :let={{_id, link}}> - <% publish_future = link.publish_at && DateTime.compare(link.publish_at, DateTime.utc_now()) == :gt %> + + <:action :let={{_id, link}} > + <% publish_future = publish_in_future?(link) %> <.link patch={~p"/admin/links/#{link}/archive"}> <.icon name="hero-archive-box" class={"w-5 h-5 #{if publish_future, do: "opacity-50"}"} /> + <.modal :if={@live_action in [:new, :edit]} id="link-modal" show on_cancel={JS.patch(~p"/admin/links")}> <.live_component module={CesiumLinkWeb.LinkLive.FormComponent} id={@link.id || :new} title={@page_title} action={@live_action} link={@link} patch={~p"/admin/links"} /> From cd4ee0d9823fa66f4e88b853b661605fa0b61398 Mon Sep 17 00:00:00 2001 From: AfonsoMartins26 Date: Wed, 8 Jan 2025 21:41:44 +0000 Subject: [PATCH 09/17] code format --- lib/cesium_link_web/live/link_live/index.ex | 2 +- .../live/link_live/index.html.heex | 32 ++++++++----------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/lib/cesium_link_web/live/link_live/index.ex b/lib/cesium_link_web/live/link_live/index.ex index 5b6a800..7815347 100644 --- a/lib/cesium_link_web/live/link_live/index.ex +++ b/lib/cesium_link_web/live/link_live/index.ex @@ -67,7 +67,7 @@ defmodule CesiumLinkWeb.LinkLive.Index do {:noreply, socket} end - def handle_event("end-time",_, socket) do + def handle_event("end-time", _, socket) do {:noreply, socket |> push_navigate(to: ~p"/admin/links")} end diff --git a/lib/cesium_link_web/live/link_live/index.html.heex b/lib/cesium_link_web/live/link_live/index.html.heex index df17f2b..915847f 100644 --- a/lib/cesium_link_web/live/link_live/index.html.heex +++ b/lib/cesium_link_web/live/link_live/index.html.heex @@ -15,23 +15,23 @@ <.table id="links" rows={@streams.links} phx-hook="Sorting"> - <:col :let={{_id, link}} > + <:col :let={{_id, link}}> <% publish_future = publish_in_future?(link) %> <.icon name="hero-bars-3 cursor-pointer ml-4" class={"handle w-5 h-5 #{if publish_future, do: "opacity-50"}"} /> - + <:col :let={{_id, link}} label="Name"> <% publish_future = publish_in_future?(link) %>

<%= link.name %>

- + <:col :let={{_id, link}} label="Emoji"> <% publish_future = publish_in_future?(link) %> <.emoji code={link.emoji} /> - + <:col :let={{_id, link}} label="URL"> <% publish_future = publish_in_future?(link) %> <.link target="_blank" class={"hover:text-brand hover:underline #{if publish_future, do: "opacity-50"}"} navigate={link.url}> @@ -42,37 +42,34 @@ <:col :let={{_id, link}} label="Time Left"> <% publish_future = publish_in_future?(link) %> <%= if publish_future do %> -
- 00:00:00 -
+
+ 00:00:00 +
<% else %>

No time

<% end %> - + <:col :let={{_id, link}} label="Clicks"> <% publish_future = publish_in_future?(link) %>

<%= link.visits %>

- + <:col :let={{_id, link}} label="Attention"> <% publish_future = publish_in_future?(link) %> - - - <:action :let={{_id, link}} > + + + <:action :let={{_id, link}}> <% publish_future = publish_in_future?(link) %> <.link patch={~p"/admin/links/#{link}/edit"}> <.icon name="hero-pencil" class={"w-5 h-5 #{if publish_future, do: "opacity-50"}"} /> - - <:action :let={{_id, link}} > + + <:action :let={{_id, link}}> <% publish_future = publish_in_future?(link) %> <.link patch={~p"/admin/links/#{link}/archive"}> <.icon name="hero-archive-box" class={"w-5 h-5 #{if publish_future, do: "opacity-50"}"} /> @@ -80,7 +77,6 @@ - <.modal :if={@live_action in [:new, :edit]} id="link-modal" show on_cancel={JS.patch(~p"/admin/links")}> <.live_component module={CesiumLinkWeb.LinkLive.FormComponent} id={@link.id || :new} title={@page_title} action={@live_action} link={@link} patch={~p"/admin/links"} /> From 13cef73ee29352e74d53db3e0897ed6bfefea148 Mon Sep 17 00:00:00 2001 From: AfonsoMartins26 Date: Wed, 8 Jan 2025 22:09:09 +0000 Subject: [PATCH 10/17] feat: resolve requestes --- lib/cesium_link_web/live/link_live/index.ex | 12 +++---- .../live/link_live/index.html.heex | 31 +++++++------------ 2 files changed, 17 insertions(+), 26 deletions(-) diff --git a/lib/cesium_link_web/live/link_live/index.ex b/lib/cesium_link_web/live/link_live/index.ex index 7815347..4e8bd86 100644 --- a/lib/cesium_link_web/live/link_live/index.ex +++ b/lib/cesium_link_web/live/link_live/index.ex @@ -71,10 +71,10 @@ defmodule CesiumLinkWeb.LinkLive.Index do {:noreply, socket |> push_navigate(to: ~p"/admin/links")} end - def publish_in_future?(link) do - case link.publish_at do - nil -> false - publish_at -> DateTime.compare(publish_at, DateTime.utc_now()) == :gt - end - end + def published?(%Link{publish_at: nil}), do: true + + def published?(%Link{publish_at: publish_at}), + do: DateTime.compare(publish_at, DateTime.utc_now()) == :lt + + defp publish_in_future?(link), do: not published?(link) end diff --git a/lib/cesium_link_web/live/link_live/index.html.heex b/lib/cesium_link_web/live/link_live/index.html.heex index 915847f..06a46e9 100644 --- a/lib/cesium_link_web/live/link_live/index.html.heex +++ b/lib/cesium_link_web/live/link_live/index.html.heex @@ -16,63 +16,54 @@ <.table id="links" rows={@streams.links} phx-hook="Sorting"> <:col :let={{_id, link}}> - <% publish_future = publish_in_future?(link) %> - <.icon name="hero-bars-3 cursor-pointer ml-4" class={"handle w-5 h-5 #{if publish_future, do: "opacity-50"}"} /> + <.icon name="hero-bars-3 cursor-pointer ml-4" class={"handle w-5 h-5 #{if publish_in_future?(link), do: "opacity-50"}"} /> <:col :let={{_id, link}} label="Name"> - <% publish_future = publish_in_future?(link) %> -

<%= link.name %>

+

<%= link.name %>

<:col :let={{_id, link}} label="Emoji"> - <% publish_future = publish_in_future?(link) %> - + <.emoji code={link.emoji} /> <:col :let={{_id, link}} label="URL"> - <% publish_future = publish_in_future?(link) %> - <.link target="_blank" class={"hover:text-brand hover:underline #{if publish_future, do: "opacity-50"}"} navigate={link.url}> + <.link target="_blank" class={"hover:text-brand hover:underline #{if publish_in_future?(link), do: "opacity-50"}"} navigate={link.url}> <%= truncate_elipsis(link.url, 50) %> <:col :let={{_id, link}} label="Time Left"> - <% publish_future = publish_in_future?(link) %> - <%= if publish_future do %> -
+ <%= if publish_in_future?(link) do %> +
00:00:00
<% else %> -

No time

+

No time set

<% end %> <:col :let={{_id, link}} label="Clicks"> - <% publish_future = publish_in_future?(link) %> -

+

<%= link.visits %>

<:col :let={{_id, link}} label="Attention"> - <% publish_future = publish_in_future?(link) %> - + <:action :let={{_id, link}}> - <% publish_future = publish_in_future?(link) %> <.link patch={~p"/admin/links/#{link}/edit"}> - <.icon name="hero-pencil" class={"w-5 h-5 #{if publish_future, do: "opacity-50"}"} /> + <.icon name="hero-pencil" class={"w-5 h-5 #{if publish_in_future?(link), do: "opacity-50"}"} /> <:action :let={{_id, link}}> - <% publish_future = publish_in_future?(link) %> <.link patch={~p"/admin/links/#{link}/archive"}> - <.icon name="hero-archive-box" class={"w-5 h-5 #{if publish_future, do: "opacity-50"}"} /> + <.icon name="hero-archive-box" class={"w-5 h-5 #{if publish_in_future?(link), do: "opacity-50"}"} /> From 37154cc585e65fdfe1fc42843baf90cc3b2ca91c Mon Sep 17 00:00:00 2001 From: AfonsoMartins26 Date: Sat, 11 Jan 2025 02:46:01 +0000 Subject: [PATCH 11/17] feat: reqeusted changes working --- lib/cesium_link/links/link.ex | 1 + lib/cesium_link_web/live/link_live/index.ex | 9 ++++++++- .../live/link_live/index.html.heex | 19 ++++++++++--------- .../20240418234531_create_links.exs | 1 + 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/lib/cesium_link/links/link.ex b/lib/cesium_link/links/link.ex index c9f8d39..fbfdd7e 100644 --- a/lib/cesium_link/links/link.ex +++ b/lib/cesium_link/links/link.ex @@ -17,6 +17,7 @@ defmodule CesiumLink.Links.Link do field :visits, :integer, default: 0 field :edited_at, :utc_datetime field :publish_at, :utc_datetime + field :in_future, :boolean, default: false timestamps(type: :utc_datetime) end diff --git a/lib/cesium_link_web/live/link_live/index.ex b/lib/cesium_link_web/live/link_live/index.ex index 4e8bd86..971b40b 100644 --- a/lib/cesium_link_web/live/link_live/index.ex +++ b/lib/cesium_link_web/live/link_live/index.ex @@ -6,9 +6,16 @@ defmodule CesiumLinkWeb.LinkLive.Index do @impl true def mount(_params, _session, socket) do - {:ok, stream(socket, :links, Links.list_unarchived_links())} + links = Links.list_unarchived_links() + enriched_links = Enum.map(links, fn link -> + in_future = publish_in_future?(link) + %{link | in_future: in_future} + end) + + {:ok, stream(socket, :links, enriched_links)} end + @impl true def handle_params(params, _url, socket) do {:noreply, apply_action(socket, socket.assigns.live_action, params)} diff --git a/lib/cesium_link_web/live/link_live/index.html.heex b/lib/cesium_link_web/live/link_live/index.html.heex index 06a46e9..dbf405a 100644 --- a/lib/cesium_link_web/live/link_live/index.html.heex +++ b/lib/cesium_link_web/live/link_live/index.html.heex @@ -16,27 +16,27 @@ <.table id="links" rows={@streams.links} phx-hook="Sorting"> <:col :let={{_id, link}}> - <.icon name="hero-bars-3 cursor-pointer ml-4" class={"handle w-5 h-5 #{if publish_in_future?(link), do: "opacity-50"}"} /> + <.icon name="hero-bars-3 cursor-pointer ml-4" class={"handle w-5 h-5 #{if link.in_future, do: "opacity-50"}"} /> <:col :let={{_id, link}} label="Name"> -

<%= link.name %>

+

<%= link.name %>

<:col :let={{_id, link}} label="Emoji"> - + <.emoji code={link.emoji} /> <:col :let={{_id, link}} label="URL"> - <.link target="_blank" class={"hover:text-brand hover:underline #{if publish_in_future?(link), do: "opacity-50"}"} navigate={link.url}> + <.link target="_blank" class={"hover:text-brand hover:underline #{if link.in_future, do: "opacity-50"}"} navigate={link.url}> <%= truncate_elipsis(link.url, 50) %> <:col :let={{_id, link}} label="Time Left"> - <%= if publish_in_future?(link) do %> + <%= if link.in_future do %>
00:00:00
@@ -46,28 +46,29 @@ <:col :let={{_id, link}} label="Clicks"> -

+

<%= link.visits %>

<:col :let={{_id, link}} label="Attention"> - + <:action :let={{_id, link}}> <.link patch={~p"/admin/links/#{link}/edit"}> - <.icon name="hero-pencil" class={"w-5 h-5 #{if publish_in_future?(link), do: "opacity-50"}"} /> + <.icon name="hero-pencil" class={"w-5 h-5 #{if link.in_future, do: "opacity-50"}"} /> <:action :let={{_id, link}}> <.link patch={~p"/admin/links/#{link}/archive"}> - <.icon name="hero-archive-box" class={"w-5 h-5 #{if publish_in_future?(link), do: "opacity-50"}"} /> + <.icon name="hero-archive-box" class={"w-5 h-5 #{if link.in_future, do: "opacity-50"}"} /> + <.modal :if={@live_action in [:new, :edit]} id="link-modal" show on_cancel={JS.patch(~p"/admin/links")}> <.live_component module={CesiumLinkWeb.LinkLive.FormComponent} id={@link.id || :new} title={@page_title} action={@live_action} link={@link} patch={~p"/admin/links"} /> diff --git a/priv/repo/migrations/20240418234531_create_links.exs b/priv/repo/migrations/20240418234531_create_links.exs index 20ece26..72dfc3a 100644 --- a/priv/repo/migrations/20240418234531_create_links.exs +++ b/priv/repo/migrations/20240418234531_create_links.exs @@ -12,6 +12,7 @@ defmodule CesiumLink.Repo.Migrations.CreateLinks do add :attention, :boolean, default: false, null: false add :archived, :boolean, default: false, null: false add :edited_at, :utc_datetime + add :in_future, :boolean, default: false, null: false timestamps(type: :utc_datetime) end From 2dc76bfbe1909e50c83adb1f00b3dc3eb5cbcf40 Mon Sep 17 00:00:00 2001 From: AfonsoMartins26 Date: Sat, 11 Jan 2025 02:47:00 +0000 Subject: [PATCH 12/17] format code --- lib/cesium_link_web/live/link_live/index.ex | 11 ++++++----- lib/cesium_link_web/live/link_live/index.html.heex | 1 - 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/cesium_link_web/live/link_live/index.ex b/lib/cesium_link_web/live/link_live/index.ex index 971b40b..380ffb1 100644 --- a/lib/cesium_link_web/live/link_live/index.ex +++ b/lib/cesium_link_web/live/link_live/index.ex @@ -7,15 +7,16 @@ defmodule CesiumLinkWeb.LinkLive.Index do @impl true def mount(_params, _session, socket) do links = Links.list_unarchived_links() - enriched_links = Enum.map(links, fn link -> - in_future = publish_in_future?(link) - %{link | in_future: in_future} - end) + + enriched_links = + Enum.map(links, fn link -> + in_future = publish_in_future?(link) + %{link | in_future: in_future} + end) {:ok, stream(socket, :links, enriched_links)} end - @impl true def handle_params(params, _url, socket) do {:noreply, apply_action(socket, socket.assigns.live_action, params)} diff --git a/lib/cesium_link_web/live/link_live/index.html.heex b/lib/cesium_link_web/live/link_live/index.html.heex index dbf405a..561846c 100644 --- a/lib/cesium_link_web/live/link_live/index.html.heex +++ b/lib/cesium_link_web/live/link_live/index.html.heex @@ -68,7 +68,6 @@ - <.modal :if={@live_action in [:new, :edit]} id="link-modal" show on_cancel={JS.patch(~p"/admin/links")}> <.live_component module={CesiumLinkWeb.LinkLive.FormComponent} id={@link.id || :new} title={@page_title} action={@live_action} link={@link} patch={~p"/admin/links"} /> From 72248c5edd339e2b88a72498051a0c5b28dc0c09 Mon Sep 17 00:00:00 2001 From: AfonsoMartins26 Date: Mon, 13 Jan 2025 00:01:29 +0000 Subject: [PATCH 13/17] feat: resuqeted change and some push_navigate --- lib/cesium_link_web/live/link_live/form_component.ex | 5 +++-- lib/cesium_link_web/live/link_live/index.ex | 3 +-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/cesium_link_web/live/link_live/form_component.ex b/lib/cesium_link_web/live/link_live/form_component.ex index 9f1e0a7..ce9c0bc 100644 --- a/lib/cesium_link_web/live/link_live/form_component.ex +++ b/lib/cesium_link_web/live/link_live/form_component.ex @@ -65,7 +65,7 @@ defmodule CesiumLinkWeb.LinkLive.FormComponent do {:noreply, socket |> put_flash(:info, "Link updated successfully") - |> push_patch(to: socket.assigns.patch)} + |> push_navigate(to: ~p"/admin/links")} {:error, %Ecto.Changeset{} = changeset} -> {:noreply, assign_form(socket, changeset)} @@ -84,13 +84,14 @@ defmodule CesiumLinkWeb.LinkLive.FormComponent do {:noreply, socket |> put_flash(:info, "Link created successfully") - |> push_patch(to: socket.assigns.patch)} + |> push_navigate(to: ~p"/admin/links")} {:error, %Ecto.Changeset{} = changeset} -> {:noreply, assign_form(socket, changeset)} end end + defp assign_form(socket, %Ecto.Changeset{} = changeset) do assign(socket, :form, to_form(changeset)) end diff --git a/lib/cesium_link_web/live/link_live/index.ex b/lib/cesium_link_web/live/link_live/index.ex index 380ffb1..467161e 100644 --- a/lib/cesium_link_web/live/link_live/index.ex +++ b/lib/cesium_link_web/live/link_live/index.ex @@ -11,9 +11,8 @@ defmodule CesiumLinkWeb.LinkLive.Index do enriched_links = Enum.map(links, fn link -> in_future = publish_in_future?(link) - %{link | in_future: in_future} + Map.put(link, :in_future, in_future) end) - {:ok, stream(socket, :links, enriched_links)} end From 55b082d0569db8af1984a4b57acaa75bab1e89c7 Mon Sep 17 00:00:00 2001 From: AfonsoMartins26 Date: Mon, 13 Jan 2025 00:01:51 +0000 Subject: [PATCH 14/17] format code --- lib/cesium_link_web/live/link_live/form_component.ex | 1 - lib/cesium_link_web/live/link_live/index.ex | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cesium_link_web/live/link_live/form_component.ex b/lib/cesium_link_web/live/link_live/form_component.ex index ce9c0bc..33adef4 100644 --- a/lib/cesium_link_web/live/link_live/form_component.ex +++ b/lib/cesium_link_web/live/link_live/form_component.ex @@ -91,7 +91,6 @@ defmodule CesiumLinkWeb.LinkLive.FormComponent do end end - defp assign_form(socket, %Ecto.Changeset{} = changeset) do assign(socket, :form, to_form(changeset)) end diff --git a/lib/cesium_link_web/live/link_live/index.ex b/lib/cesium_link_web/live/link_live/index.ex index 467161e..319977d 100644 --- a/lib/cesium_link_web/live/link_live/index.ex +++ b/lib/cesium_link_web/live/link_live/index.ex @@ -13,6 +13,7 @@ defmodule CesiumLinkWeb.LinkLive.Index do in_future = publish_in_future?(link) Map.put(link, :in_future, in_future) end) + {:ok, stream(socket, :links, enriched_links)} end From 055d9b98135acfce02d9dadcb2dc8231dfe90045 Mon Sep 17 00:00:00 2001 From: AfonsoMartins26 Date: Mon, 13 Jan 2025 00:21:42 +0000 Subject: [PATCH 15/17] feat: requested changes working --- lib/cesium_link/links/link.ex | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/cesium_link/links/link.ex b/lib/cesium_link/links/link.ex index fbfdd7e..c9f8d39 100644 --- a/lib/cesium_link/links/link.ex +++ b/lib/cesium_link/links/link.ex @@ -17,7 +17,6 @@ defmodule CesiumLink.Links.Link do field :visits, :integer, default: 0 field :edited_at, :utc_datetime field :publish_at, :utc_datetime - field :in_future, :boolean, default: false timestamps(type: :utc_datetime) end From b1940bb26c3e39c4ebc33fff77ecca41e7a7ef15 Mon Sep 17 00:00:00 2001 From: AfonsoMartins26 Date: Mon, 27 Jan 2025 23:16:07 +0000 Subject: [PATCH 16/17] feat: remove useless field --- priv/repo/migrations/20240418234531_create_links.exs | 1 - 1 file changed, 1 deletion(-) diff --git a/priv/repo/migrations/20240418234531_create_links.exs b/priv/repo/migrations/20240418234531_create_links.exs index 72dfc3a..20ece26 100644 --- a/priv/repo/migrations/20240418234531_create_links.exs +++ b/priv/repo/migrations/20240418234531_create_links.exs @@ -12,7 +12,6 @@ defmodule CesiumLink.Repo.Migrations.CreateLinks do add :attention, :boolean, default: false, null: false add :archived, :boolean, default: false, null: false add :edited_at, :utc_datetime - add :in_future, :boolean, default: false, null: false timestamps(type: :utc_datetime) end From 5356ee040f3e4c6f71d4e26d07499d4a50fbb523 Mon Sep 17 00:00:00 2001 From: AfonsoMartins26 Date: Mon, 24 Feb 2025 23:47:38 +0000 Subject: [PATCH 17/17] feat: remove else --- lib/cesium_link_web/live/link_live/index.html.heex | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/cesium_link_web/live/link_live/index.html.heex b/lib/cesium_link_web/live/link_live/index.html.heex index 561846c..be0d9a1 100644 --- a/lib/cesium_link_web/live/link_live/index.html.heex +++ b/lib/cesium_link_web/live/link_live/index.html.heex @@ -35,13 +35,11 @@ - <:col :let={{_id, link}} label="Time Left"> + <:col :let={{_id, link}} label="Time to publish"> <%= if link.in_future do %>
00:00:00
- <% else %> -

No time set

<% end %>