Skip to content

Commit

Permalink
Events page (#30)
Browse files Browse the repository at this point in the history
* Add events

Signed-off-by: Oliver Tale-Yazdi <oliver@tasty.limo>

* typo

Signed-off-by: Oliver Tale-Yazdi <oliver@tasty.limo>

* Events

Signed-off-by: Oliver Tale-Yazdi <oliver@tasty.limo>

* build

Signed-off-by: Oliver Tale-Yazdi <oliver@tasty.limo>

* fix merge

Signed-off-by: Oliver Tale-Yazdi <oliver@tasty.limo>

---------

Signed-off-by: Oliver Tale-Yazdi <oliver@tasty.limo>
  • Loading branch information
ggwpez authored Nov 23, 2024
1 parent c674fbb commit 4edb536
Show file tree
Hide file tree
Showing 13 changed files with 303 additions and 46 deletions.
2 changes: 2 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

set -e

rm -rf _build

mix deps.get && MIX_ENV=prod mix compile && MIX_ENV=prod mix assets.deploy && MIX_ENV=prod mix release --overwrite && MIX_ENV=prod mix ecto.drop && MIX_ENV=prod mix ecto.setup
2 changes: 2 additions & 0 deletions lib/phoenix_app/events.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ defmodule PhoenixApp.Events do
def list_events do
Repo.all(from e in Event, order_by: :name)
end

def get_event!(id), do: Repo.get!(Event, id)
end
31 changes: 31 additions & 0 deletions lib/phoenix_app/events/event.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
defmodule PhoenixApp.Events.Event do
use Ecto.Schema
import Ecto.Changeset

schema "events" do
field :name, :string
field :short, :string
field :long, :string
field :links, {:array, :string}
field :learn_more_id, :integer, default: 0
field :contact, {:array, :string}
field :when_from, :date
field :when_to, :date
field :when_est, :string
field :where, :string
field :where_link, :string
field :duration, :string
field :historic, :boolean, default: false

timestamps()
end

@all [:homepage, :name, :contact, :where]

@doc false
def changeset(team, attrs) do
team
|> cast(attrs, @all ++ [:when_to, :when_from, :when_est, :where_link, :duration, :long, :short, :links, :historic, :learn_more_id])
|> validate_required(@all)
end
end
25 changes: 0 additions & 25 deletions lib/phoenix_app/teams/event.ex

This file was deleted.

5 changes: 5 additions & 0 deletions lib/phoenix_app_web/controllers/event_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@ defmodule PhoenixAppWeb.EventController do
num = length(events)
render(conn, "index.html", events: events, num_events: num)
end

def show(conn, %{"id" => id}) do
event = Events.get_event!(id)
render(conn, "show.html", event: event)
end
end
5 changes: 4 additions & 1 deletion lib/phoenix_app_web/controllers/page_controller.ex
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
defmodule PhoenixAppWeb.PageController do
use PhoenixAppWeb, :controller

alias PhoenixApp.Events

def index(conn, _params) do
render(conn, "index.html")
events = Events.list_events()
render(conn, "index.html", events: events)
end

def spec(conn, _params) do
Expand Down
1 change: 1 addition & 0 deletions lib/phoenix_app_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ defmodule PhoenixAppWeb.Router do
get("/", PageController, :index)
get("/spec", PageController, :spec)
get("/tech", PageController, :tech)

resources("/events", EventController, only: [:index, :show])
resources("/clients/json", TeamJsonController, only: [:index])
resources("/clients", TeamController, only: [:index, :show])
Expand Down
28 changes: 24 additions & 4 deletions lib/phoenix_app_web/templates/event/index.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,38 @@
<div class="max-w-4xl mx-auto px-4">
<article class="text-center py-8">
<div class="flex flex-col space-y-4">
<%= for event <- @events do %>
<%= link to: hd(event.links), class: "block w-full" do %>
<%= for event <- Enum.reject(@events, & &1.historic) do %>
<%= link to: Routes.event_path(@conn, :show, event), class: "block w-full" do %>
<div class="bg-gray-800 shadow-lg rounded-lg overflow-hidden border border-gray-700 hover:border-blue-500 transition-all duration-300">
<div class="p-6">
<h2 class="text-xl font-semibold mb-2 text-gray-100"><%= event.name %></h2>
<p class="text-sm text-gray-400 mb-2"><%= event.where %> <%= event.when_from %> - <%= event.when_to %></p>
<p class="text-gray-300"><%= event.description %></p>
<p class="text-sm text-gray-400 mb-2"><%= event.where %> · <%= fmt_when(event) %></p>
<p class="text-gray-300"><%= event.short %></p>
</div>
</div>
<% end %>
<% end %>
</div>
</article>

<%= if Enum.any?(@events, & &1.historic) do %>
<h3 class="text-xl font-semibold text-gray-400 text-center mb-8">Past Events</h3>

<article class="text-center">
<div class="flex flex-col space-y-4">
<%= for event <- Enum.filter(@events, & &1.historic) do %>
<%= link to: Routes.event_path(@conn, :show, event), class: "block w-full" do %>
<div class="bg-gray-800/50 shadow-lg rounded-lg overflow-hidden border border-gray-700 hover:border-blue-500 transition-all duration-300">
<div class="p-6">
<h2 class="text-xl font-semibold mb-2 text-gray-300"><%= event.name %></h2>
<p class="text-sm text-gray-500 mb-2"><%= event.where %> · <%= fmt_when(event) %></p>
<p class="text-gray-400"><%= event.short %></p>
</div>
</div>
<% end %>
<% end %>
</div>
</article>
<% end %>
</div>
</section>
131 changes: 131 additions & 0 deletions lib/phoenix_app_web/templates/event/show.html.heex
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<main class="min-h-screen bg-gray-900">
<section class="w-full bg-gray-800 py-12 px-4">
<div class="max-w-7xl mx-auto">
<div class="flex flex-col md:flex-row gap-8 items-center justify-between">
<div class="space-y-4">
<h1 class="text-4xl font-bold text-white"><%= @event.name %></h1>
<%= if @event.short do %>
<p class="text-xl text-gray-300"><%= @event.short %></p>
<% end %>
</div>
</div>
</div>
</section>

<%= if @event.historic do %>
<div class="w-full bg-amber-900/50 py-3 px-4">
<div class="max-w-7xl mx-auto">
<div class="flex items-center justify-center gap-2 text-amber-200">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
<path fillRule="evenodd" d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z" clipRule="evenodd" />
</svg>
<p>This event already happened and is shown for archival purposes only.</p>
</div>
</div>
</div>
<% end %>

<section class="w-full py-16">
<div class="max-w-7xl mx-auto px-4">
<div class="grid grid-cols-1 md:grid-cols-3 gap-8">
<%# Main Content %>
<div class="md:col-span-2 space-y-8">
<div class="bg-gray-800 rounded-lg p-6 space-y-6">
<div>
<h2 class="text-2xl font-semibold text-white mb-4">About This Event</h2>
<div class="prose prose-invert max-w-none">
<%= raw(fmt_desc(@event)) %>
</div>
</div>
</div>

<%# Contact Information %>
<%= if @event.contact && length(@event.contact) > 0 do %>
<div class="bg-gray-800 rounded-lg p-6">
<h3 class="text-xl font-semibold text-white mb-4">Contact Information</h3>
<div class="space-y-2">
<%= for contact <- @event.contact do %>
<p class="text-gray-300"><%= contact %></p>
<% end %>
</div>
</div>
<% end %>

<%= if @event.links && length(@event.links) > 0 do %>
<div class="bg-gray-800 rounded-lg p-6">
<h3 class="text-xl font-semibold text-white mb-4">Related Links</h3>
<div class="space-y-2">
<%= for {link, index} <- Enum.with_index(@event.links) do %>
<div class="flex items-center gap-2">
<span class="text-gray-400 min-w-[1.5rem]"><%= index + 1 %>:</span>
<%= link link,
to: link,
class: "text-blue-400 hover:text-blue-300",
target: "_blank" %>
</div>
<% end %>
</div>
</div>
<% end %>
</div>

<%# Sidebar %>
<div class="space-y-6">
<div class="bg-gray-800 rounded-lg p-6 space-y-4">
<%# Date Information %>
<div class="flex items-center space-x-3">
<svg class="w-6 h-6 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z" />
</svg>
<div>
<p class="text-gray-400">Date</p>
<%= if @event.when_from do %>
<p class="text-white">
<%= Calendar.strftime(@event.when_from, "%B %d, %Y") %>
<%= if @event.when_to && @event.when_to != @event.when_from do %>
- <%= Calendar.strftime(@event.when_to, "%B %d, %Y") %>
<% end %>
<%= fmt_duration(@event) %>
</p>
<% end %>
<%= if @event.when_est do %>
<p class="text-gray-300 text-sm mt-1">
<%= @event.when_est %> <%= fmt_duration(@event) %>
</p>
<% end %>
</div>
</div>

<%# Location %>
<div class="flex items-center space-x-3">
<svg class="w-6 h-6 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z" />
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 11a3 3 0 11-6 0 3 3 0 016 0z" />
</svg>
<div>
<p class="text-gray-400">Location</p>
<%= if @event.where_link do %>
<%= link to: @event.where_link, class: "text-white hover:text-blue-300" do %>
<%= @event.where %>
<span class="ml-1"></span>
<% end %>
<% else %>
<p class="text-white"><%= @event.where %></p>
<% end %>
</div>
</div>
</div>

<%# Call to Action %>
<%= if @event.links && length(@event.links) > 0 do %>
<div class="bg-gray-800 rounded-lg p-6 text-center">
<%= link "Learn More",
to: Enum.at(@event.links, @event.learn_more_id),
class: "w-full px-6 py-3 bg-blue-500 hover:bg-blue-600 text-white font-semibold rounded-lg transition-colors duration-200" %>
</div>
<% end %>
</div>
</div>
</div>
</section>
</main>
30 changes: 18 additions & 12 deletions lib/phoenix_app_web/templates/page/index.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,24 @@
</p>
</article>

<article class="py-12">
<h2 class="text-2xl font-semibold mb-4 text-white">NEWS</h2>
<div class="grid grid-cols-1 md:grid-cols-1 gap-6">
<div class="mt-4 bg-gray-800 rounded-lg shadow-md p-6">
<h3 class="text-l font-semibold text-white mb-3">
<i>JAM0</i> Meetup Proposal
</h3>
<p class="text-gray-300 mb-4">
An OpenGov proposal is up for vote to decide whether to fund a meetup at Devcon 7, where JAM implementor teams can collaborate.
</p>
<%= link "Read more", to: "https://polkadot.polkassembly.io/referenda/1024", class: "text-indigo-600 hover:text-blue-300", target: "_blank" %>
</div>
<article class="py-12">
<h2 class="text-2xl font-semibold mb-4 text-white">
<%= link "EVENTS", to: Routes.event_path(@conn, :index), class: "text-indigo-600 hover:text-blue-300" %>
</h2>
<div class="flex flex-col space-y-4">
<%= for event <- @events do %>
<%= link to: Routes.event_path(@conn, :show, event), class: "block w-full" do %>
<div class="bg-gray-800 shadow-lg rounded-lg overflow-hidden border border-gray-700 hover:border-blue-500 transition-all duration-300">
<div class="p-6">
<h3 class="text-xl font-semibold mb-2 text-gray-100">
<%= event.name %>
</h3>
<p class="text-sm text-gray-400 mb-2"><%= event.where %> · <%= PhoenixAppWeb.EventView.fmt_when(event) %></p>
<p class="text-gray-300 mb-4"><%= event.short %></p>
</div>
</div>
<% end %>
<% end %>
</div>
</article>
</div>
Expand Down
54 changes: 54 additions & 0 deletions lib/phoenix_app_web/views/event_view.ex
Original file line number Diff line number Diff line change
@@ -1,3 +1,57 @@
defmodule PhoenixAppWeb.EventView do
use PhoenixAppWeb, :view

alias PhoenixApp.Events.Event

def fmt_when(%Event{when_from: from, when_to: to} = event) when not is_nil(from) and not is_nil(to) do
"""
#{event.when_from} - #{event.when_to}
"""
end

def fmt_when(%Event{when_est: est} = event) when not is_nil(est) do
"""
#{event.when_est}
"""
end

def fmt_when(%Event{} = event) do
raise ArgumentError, "Event has no date: #{inspect(event)}"
end

def fmt_duration(%Event{duration: duration} = event) when not is_nil(duration) do
"""
(#{event.duration})
"""
end

def fmt_duration(%Event{}) do
""
end

# Format MD links to HTML links by looking up the links from a list.
# For example:
# >Make sure to join the [1](Matrix chat) for updates.
# becomes:
# >Make sure to join the <a href="Enum.at(event.links, 1)">Matrix chat</a> for updates.
def fmt_desc(%Event{long: desc, links: links} = _event) when not is_nil(desc) and is_list(links) do
matches = Regex.scan(~r/\[([0-9]+)\]\(([^)]+)\)/, desc)
Enum.reduce(matches, desc, fn [full_match, idx_str, name], acc ->
case Integer.parse(idx_str) do
{idx, _} ->
link = Enum.at(links, idx)
if link do
String.replace(acc, full_match,
"<a href=\"#{link}\" class=\"text-blue-400 hover:text-blue-300\">#{name}</a><sup>#{idx + 1}</sup>")
else
acc
end
_ -> acc
end
end)
|> String.replace(~r/\n/, "<br>")
end

def fmt_desc(%Event{long: desc}) when not is_nil(desc), do: desc
def fmt_desc(_), do: ""
end
8 changes: 7 additions & 1 deletion priv/repo/migrations/20240713183346_create_events.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ defmodule PhoenixApp.Repo.Migrations.CreateEvents do
def change do
create table(:events) do
add :name, :string
add :description, :text
add :short, :text
add :long, :text
add :links, {:array, :string}
add :learn_more_id, :integer, default: 0
add :contact, {:array, :string}
add :when_from, :date
add :when_to, :date
add :when_est, :string
add :where, :string
add :where_link, :string
add :duration, :string
add :historic, :boolean, default: false

timestamps()
end
Expand Down
Loading

0 comments on commit 4edb536

Please sign in to comment.