1
0
mirror of https://github.com/algora-io/tv.git synced 2025-10-30 23:07:56 +02:00

implement add show to calendar

This commit is contained in:
zafer
2024-05-25 17:12:19 +03:00
parent ab796918a3
commit 464049b33d
6 changed files with 68 additions and 0 deletions

View File

@@ -225,6 +225,13 @@ const Hooks = {
}
},
},
TimezoneDetector: {
mounted() {
this.pushEvent("get_timezone", {
tz: Intl.DateTimeFormat().resolvedOptions().timeZone,
});
},
},
NavBar: {
mounted() {
const offset = 16;

View File

@@ -0,0 +1,45 @@
defmodule AlgoraWeb.ShowCalendarController do
use AlgoraWeb, :controller
alias Algora.{Shows, Accounts, Library}
def export(conn, %{"slug" => slug} = params) do
case Shows.get_show_by_fields!(slug: slug) do
nil ->
send_resp(conn, 404, "Not found")
show when show.scheduled_for == nil ->
send_resp(conn, 404, "Not found")
show ->
channel = Accounts.get_user!(show.user_id) |> Library.get_channel!()
url = show.url || "#{AlgoraWeb.Endpoint.url()}/#{channel.handle}/latest"
start_date =
show.scheduled_for
|> Timex.to_datetime("Etc/UTC")
|> Timex.Timezone.convert(params["tz"] || "Etc/UTC")
end_date = DateTime.add(start_date, 3600)
events = [
%ICalendar.Event{
summary: show.title,
dtstart: start_date,
dtend: end_date,
description: show.description,
location: url,
url: url,
organizer: channel.name
}
]
ics = %ICalendar{events: events} |> ICalendar.to_ics()
conn
|> put_resp_content_type("text/calendar")
|> put_resp_header("content-disposition", "attachment; filename=#{show.slug}.ics")
|> Plug.Conn.send_resp(:ok, ics)
end
end
end

View File

@@ -153,6 +153,13 @@ defmodule AlgoraWeb.ShowLive.Show do
|> Timex.Timezone.convert("America/New_York")
|> Timex.format!("{h12}:{m} {am}, Eastern Time") %>
</div>
<.link
phx-hook="TimezoneDetector"
class="text-sm underline"
href={~p"/shows/#{@show.slug}/event.ics?tz=#{@current_user_tz}"}
>
Add to calendar
</.link>
</div>
</div>
<.button :if={@current_user && !@rsvpd?} phx-click="toggle_rsvp">
@@ -269,6 +276,7 @@ defmodule AlgoraWeb.ShowLive.Show do
{:ok,
socket
|> assign_attendees(show)
|> assign(:current_user_tz, "Etc/UTC")
|> assign(:show, show)
|> assign(:owns_show?, current_user && show.user_id == current_user.id)
|> assign(:channel, channel)
@@ -308,6 +316,10 @@ defmodule AlgoraWeb.ShowLive.Show do
|> assign(:rsvpd?, !socket.assigns.rsvpd?)}
end
def handle_event("get_timezone", %{"tz" => tz}, socket) do
{:noreply, socket |> assign(:current_user_tz, tz)}
end
@impl true
def handle_info({AlgoraWeb.ShowLive.FormComponent, {:saved, show}}, socket) do
{:noreply, socket |> assign(:show, show)}

View File

@@ -102,6 +102,8 @@ defmodule AlgoraWeb.Router do
live "/:channel_handle", ChannelLive, :show
live "/:channel_handle/:video_id", VideoLive, :show
get "/shows/:slug/event.ics", ShowCalendarController, :export
get "/gh/:user_id/thumbnail", GithubController, :get_thumbnail
get "/gh/:user_id/channel", GithubController, :get_channel
end

View File

@@ -52,6 +52,7 @@ defmodule Algora.MixProject do
{:gettext, "~> 0.18"},
{:heroicons, "~> 0.5.0"},
{:hnswlib, "~> 0.1.0"},
{:icalendar, "~> 1.1.0"},
{:image, "~> 0.37"},
{:jason, "~> 1.2"},
{:libcluster, "~> 3.3.1"},

View File

@@ -49,6 +49,7 @@
"hnswlib": {:hex, :hnswlib, "0.1.5", "750bea8627ea60dfdea67421aef34478c31bf1254495ebd43a6a100aaf0523c0", [:make, :mix], [{:cc_precompiler, "~> 0.1.0", [hex: :cc_precompiler, repo: "hexpm", optional: false]}, {:elixir_make, "~> 0.7.0", [hex: :elixir_make, repo: "hexpm", optional: false]}, {:nx, "~> 0.5", [hex: :nx, repo: "hexpm", optional: false]}], "hexpm", "833a3dcfd917236a4e3dd1917725c32d68f65cbf37888cb2af8d38a4e547f8f3"},
"hpax": {:hex, :hpax, "0.1.2", "09a75600d9d8bbd064cdd741f21fc06fc1f4cf3d0fcc335e5aa19be1a7235c84", [:mix], [], "hexpm", "2c87843d5a23f5f16748ebe77969880e29809580efdaccd615cd3bed628a8c13"},
"httpoison": {:hex, :httpoison, "2.2.1", "87b7ed6d95db0389f7df02779644171d7319d319178f6680438167d7b69b1f3d", [:mix], [{:hackney, "~> 1.17", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "51364e6d2f429d80e14fe4b5f8e39719cacd03eb3f9a9286e61e216feac2d2df"},
"icalendar": {:hex, :icalendar, "1.1.2", "5d0afff5d0143c5bd43f18ae32a777bf0fb9a724543ab05229a460d368f0a5e7", [:mix], [{:timex, "~> 3.4", [hex: :timex, repo: "hexpm", optional: false]}], "hexpm", "2060f8e353fdf3047e95a3f012583dc3c0bbd7ca1010e32ed9e9fc5760ad4292"},
"idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"},
"image": {:hex, :image, "0.45.0", "4cd463b89b4a0db011ab542dd1599d5822f224b96099ce8f5b749176c74f33a7", [:mix], [{:bumblebee, "~> 0.3", [hex: :bumblebee, repo: "hexpm", optional: true]}, {:evision, "~> 0.1.33", [hex: :evision, repo: "hexpm", optional: true]}, {:exla, "~> 0.5", [hex: :exla, repo: "hexpm", optional: true]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: true]}, {:kino, "~> 0.11", [hex: :kino, repo: "hexpm", optional: true]}, {:nx, "~> 0.5", [hex: :nx, repo: "hexpm", optional: true]}, {:nx_image, "~> 0.1", [hex: :nx_image, repo: "hexpm", optional: true]}, {:phoenix_html, "~> 2.1 or ~> 3.2 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:plug, "~> 1.13", [hex: :plug, repo: "hexpm", optional: true]}, {:req, "~> 0.4", [hex: :req, repo: "hexpm", optional: true]}, {:rustler, "> 0.0.0", [hex: :rustler, repo: "hexpm", optional: true]}, {:sweet_xml, "~> 0.7", [hex: :sweet_xml, repo: "hexpm", optional: false]}, {:vix, "~> 0.23", [hex: :vix, repo: "hexpm", optional: false]}], "hexpm", "4d0aeed0236ed28d54f3835a6c99010425f72c3d44a03b8c631292788f3598d8"},
"jason": {:hex, :jason, "1.4.1", "af1504e35f629ddcdd6addb3513c3853991f694921b1b9368b0bd32beb9f1b63", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fbb01ecdfd565b56261302f7e1fcc27c4fb8f32d56eab74db621fc154604a7a1"},