Skip to content

Commit

Permalink
feat: some of the requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
AfonsoMartins26 committed Oct 9, 2024
1 parent e8a47ff commit 46c0b6e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 26 deletions.
42 changes: 23 additions & 19 deletions lib/atomic_web/components/socials.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,32 @@ defmodule AtomicWeb.Components.Socials do
@moduledoc false
use Phoenix.Component

attr :socials, :map, required: true

def socials(assigns) do
~H"""
<%= if @entity.socials do %>
<div class="mt-4 flex gap-4">
<%= for {social, icon, url_base} <- [
{:tiktok, "tiktok.svg", "https://tiktok.com/"},
{:instagram, "instagram.svg", "https://instagram.com/"},
{:facebook, "facebook.svg", "https://facebook.com/"},
{:x, "x.svg", "https://x.com/"}
] do %>
<% social_value = Map.get(@entity.socials, social) %>
<%= if social_value do %>
<div class="flex flex-row items-center gap-x-1">
<img src={"/images/" <> icon} class="h-5 w-5" alt={social |> Atom.to_string() |> String.capitalize()} />
<.link class="text-blue-500" target="_blank" href={url_base <> social_value}>
<%= social |> Atom.to_string() |> String.capitalize() %>
</.link>
</div>
<% end %>
<div class="mt-4 flex gap-4">
<%= for {social, icon, url_base} <- get_socials() do %>
<% social_value = Map.get(@entity, social) %>
<%= if social_value do %>
<div class="flex flex-row items-center gap-x-1">
<img src={"/images/" <> icon} class="h-5 w-5" alt={social |> Atom.to_string() |> String.capitalize()} />
<.link class="text-blue-500" target="_blank" href={url_base <> social_value}>
<%= social |> Atom.to_string() |> String.capitalize() %>
</.link>
</div>
<% end %>
</div>
<% end %>
<% end %>
</div>
"""
end

def get_socials do
[
{:tiktok, "tiktok.svg", "https://tiktok.com/"},
{:instagram, "instagram.svg", "https://instagram.com/"},
{:facebook, "facebook.svg", "https://facebook.com/"},
{:x, "x.svg", "https://x.com/"}
]
end
end
3 changes: 2 additions & 1 deletion lib/atomic_web/live/partner_live/form_component.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ defmodule AtomicWeb.PartnerLive.FormComponent do
<.field field={location_form[:name]} label="Address" type="text" placeholder="Address" help_text={gettext("Address of the partner")} required />
</.inputs_for>
<h2 class="mt-8 mb-2 w-full border-b pb-2 text-lg font-semibold text-gray-900"><%= gettext("Socials") %></h2>
<div class="grid w-full gap-x-4 sm:grid-cols-1 md:grid-cols-4 lg:grid-cols-4">
<div class="grid w-full gap-x-4 sm:grid-cols-1 md:grid-cols-5 lg:grid-cols-5">
<.inputs_for :let={socials_form} field={f[:socials]}>
<.field field={socials_form[:instagram]} type="text" class="w-full" />
<.field field={socials_form[:facebook]} type="text" class="w-full" />
<.field field={socials_form[:x]} type="text" class="w-full" />
<.field field={socials_form[:tiktok]} type="text" class="w-full" />
<.field field={socials_form[:website]} type="text" class="w-full" />
</.inputs_for>
</div>
Expand Down
3 changes: 1 addition & 2 deletions lib/atomic_web/live/partner_live/show.ex
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
defmodule AtomicWeb.PartnerLive.Show do
use AtomicWeb, :live_view

import AtomicWeb.Components.Avatar
import AtomicWeb.Components.Socials
import AtomicWeb.Components.{Avatar, Socials}

alias Atomic.Accounts
alias Atomic.Organizations
Expand Down
10 changes: 6 additions & 4 deletions lib/atomic_web/live/partner_live/show.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</h1>
</div>
<%= if @partner.location do %>
<!-- Localização -->
<!-- Location -->
<div class="flex flex-row items-center gap-x-1 text-md leading-6">
<.icon name="hero-map-pin" class="h-5 w-5 text-zinc-400" />
<.link class="text-blue-500" href={"https://www.google.com/maps/search/?api=1&query=#{@partner.location.name}"}>
Expand All @@ -31,7 +31,7 @@
<% end %>

<%= if @partner.socials do %>
<!-- Redes Sociais e Website -->
<!-- Socials and Website -->
<div class="flex flex-wrap gap-x-4 items-center mt-2">
<!-- Website -->
<%= if @partner.socials.website do %>
Expand All @@ -40,8 +40,10 @@
<.link class="text-blue-500" href={@partner.socials.website}>Website</.link>
</div>
<% end %>
<!-- Redes Sociais -->
<.socials entity={@partner} />
<!-- Socials -->
<%= if @partner.socials do %>
<.socials entity={@partner.socials} />

Check warning on line 45 in lib/atomic_web/live/partner_live/show.html.heex

View workflow job for this annotation

GitHub Actions / Code Quality (26.x, 1.14.x)

missing required attribute "socials" for component AtomicWeb.Components.Socials.socials/1

Check warning on line 45 in lib/atomic_web/live/partner_live/show.html.heex

View workflow job for this annotation

GitHub Actions / Code Quality (26.x, 1.14.x)

undefined attribute "entity" for component AtomicWeb.Components.Socials.socials/1

Check warning on line 45 in lib/atomic_web/live/partner_live/show.html.heex

View workflow job for this annotation

GitHub Actions / OTP 26.x / Elixir 1.14.x

missing required attribute "socials" for component AtomicWeb.Components.Socials.socials/1

Check warning on line 45 in lib/atomic_web/live/partner_live/show.html.heex

View workflow job for this annotation

GitHub Actions / OTP 26.x / Elixir 1.14.x

undefined attribute "entity" for component AtomicWeb.Components.Socials.socials/1
<% end %>
</div>
<% end %>
</div>
Expand Down

0 comments on commit 46c0b6e

Please sign in to comment.