Skip to content

Commit

Permalink
Merge branch 'main' into feat/show-news
Browse files Browse the repository at this point in the history
  • Loading branch information
zoedsoupe authored Jan 19, 2025
2 parents 0a24a24 + 16474d4 commit 4dd1206
Show file tree
Hide file tree
Showing 33 changed files with 295 additions and 244 deletions.
44 changes: 44 additions & 0 deletions lib/pescarte/storage.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
defmodule Pescarte.Storage do
@moduledoc "Módulo que centraliza operações de gerenciamento de arquivos"

# bucket padrão onde as imagens da parte pública são
# guardadas de forma comprimida, geralmente em formato webp
@public_image_bucket "static"
@public_image_folder "reduced_images"

@one_year :timer.hours(24) * 365

@doc """
Recupera a URL de uma imagem guardada no Storage (atualmente Supabase),
para renderizar ela na parte pública da plataforma.
## Params
- `path`: O caminho até a imagem a ser renderizada, a desconsiderar o bucket, por exemplo, se o caminho no Supabase Storage é `reduced_images/aplicativos/card_censo.webp` então o argumento dessa função será `aplicativos/card_censo.webp`.
- `expires_in`: Tempo de expiração da URL, opcional, valor padrão de 1 ano.
- `opts`: Argumento opcional de configuração, por exemplo para usar a API de transformação de imagens da Supabase, passando a opção `:transform` onde o valor são parâmetros válidos de `Supabase.Storage.TransformOptions`
- `bucket`: O nome do bucket a ser usado, opcional pois o valor padrão é `static`, já com a pasta `reduced_images` adicionada ao caminho.
## Examples
iex> Pescarte.Storage.get_public_area_image_url("aplicativos/card_censo.webp")
{:ok, "https://supabase-url"}
iex> Pescarte.Storage.get_public_area_image_url("arquivo-nao-existe")
{:error, :file_not_found}
"""
def get_public_area_image_url(
path,
expires_in \\ @one_year,
opts \\ [],
bucket \\ @public_image_bucket
)
when is_binary(path) and is_binary(bucket) do
with {:ok, client} <- Pescarte.Supabase.get_client() do
path = Path.join(@public_image_folder, path)
storage = Supabase.Storage.from(client, bucket)
opts = [{:expires_in, expires_in} | opts]
Supabase.Storage.File.create_signed_url(storage, path, opts)
end
end
end
7 changes: 7 additions & 0 deletions lib/pescarte_web/auth.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ defmodule PescarteWeb.Auth do
Módulo responsável por controlar tanto autenticação quanto
autorização das "dead views" e live views, além de autenticação via API.
"""

# apenas um hotfix, pra forçar esse módulo
# ser compilado antes e portanto o bytecode vai existir
# quando a macro abaixo for executada
# isso deve ser resolvido na próxima release de `supabase_gotrue`
require Pescarte.Supabase

use Supabase.GoTrue.Plug,
client: Pescarte.Supabase,
endpoint: PescarteWeb.Endpoint,
Expand Down
44 changes: 22 additions & 22 deletions lib/pescarte_web/design_system.ex
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ defmodule PescarteWeb.DesignSystem do
def text(%{size: "h" <> _} = assigns) do
~H"""
<%= content_tag @size, class: get_text_style(@size, @color, @class), style: @style do %>
<%= render_slot(@inner_block) %>
{render_slot(@inner_block)}
<% end %>
"""
end

def text(assigns) do
~H"""
<p class={get_text_style(@size, @color, @class)} style={@style}>
<%= render_slot(@inner_block) %>
{render_slot(@inner_block)}
</p>
"""
end
Expand Down Expand Up @@ -136,11 +136,11 @@ defmodule PescarteWeb.DesignSystem do
{@rest}
>
<.text :if={@style == "primary"} size="base" color="text-white-100">
<%= render_slot(@inner_block) %>
{render_slot(@inner_block)}
</.text>
<.text :if={@style != "primary"} size="base" color="text-blue-80">
<%= render_slot(@inner_block) %>
{render_slot(@inner_block)}
</.text>
</button>
"""
Expand Down Expand Up @@ -249,7 +249,7 @@ defmodule PescarteWeb.DesignSystem do
required={@required}
/>
<label for={@name}>
<.text size="base"><%= @label %></.text>
<.text size="base">{@label}</.text>
</label>
</div>
"""
Expand Down Expand Up @@ -297,7 +297,7 @@ defmodule PescarteWeb.DesignSystem do
class="radio-input"
/>
<label for={@id} class="radio-label">
<.text size="base"><%= render_slot(@label) %></.text>
<.text size="base">{render_slot(@label)}</.text>
</label>
</div>
"""
Expand Down Expand Up @@ -350,7 +350,7 @@ defmodule PescarteWeb.DesignSystem do
~H"""
<fieldset class="text-input-container">
<label :if={@label} for={@name}>
<.text size="h4"><%= @label %></.text>
<.text size="h4">{@label}</.text>
</label>
<div class="input-space">
<input
Expand Down Expand Up @@ -408,11 +408,11 @@ defmodule PescarteWeb.DesignSystem do
~H"""
<fieldset class="select-input-container">
<label :if={@label} for={@name}>
<.text size="h4"><%= @label %></.text>
<.text size="h4">{@label}</.text>
</label>
<select id={@id} name={@name} class="select-input" multiple={@multiple} {@rest}>
<option :if={@prompt} value=""><%= @prompt %></option>
<%= Phoenix.HTML.Form.options_for_select(@options, @value) %>
<option :if={@prompt} value="">{@prompt}</option>
{Phoenix.HTML.Form.options_for_select(@options, @value)}
</select>
</fieldset>
"""
Expand All @@ -438,7 +438,7 @@ defmodule PescarteWeb.DesignSystem do
def text_area(assigns) do
~H"""
<fieldset class={@class}>
<.text size="base"><%= render_slot(@label) %></.text>
<.text size="base">{render_slot(@label)}</.text>
<div class="textarea-grow-wrapper">
<textarea
id={@id}
Expand Down Expand Up @@ -595,7 +595,7 @@ defmodule PescarteWeb.DesignSystem do
phx-click={Map.get(assigns, :"on-click")}
target={if Map.get(assigns, :"target-blank"), do: "_blank", else: "_self"}
>
<%= render_slot(@inner_block) %>
{render_slot(@inner_block)}
</Phoenix.Component.link>
"""
end
Expand Down Expand Up @@ -626,9 +626,9 @@ defmodule PescarteWeb.DesignSystem do
def simple_form(assigns) do
~H"""
<.form :let={f} for={@for} as={@as} {@rest}>
<%= render_slot(@inner_block, f) %>
{render_slot(@inner_block, f)}
<%= for action <- @actions do %>
<%= render_slot(action, f) %>
{render_slot(action, f)}
<% end %>
</.form>
"""
Expand Down Expand Up @@ -665,7 +665,7 @@ defmodule PescarteWeb.DesignSystem do
<Lucideicons.circle_check :if={@kind == :success} class="flash-icon" />
<Lucideicons.info :if={@kind == :warning} class="flash-icon" />
<Lucideicons.circle_x :if={@kind == :error} class="flash-icon" />
<.text size="lg"><%= msg %></.text>
<.text size="lg">{msg}</.text>
</div>
</div>
"""
Expand Down Expand Up @@ -705,7 +705,7 @@ defmodule PescarteWeb.DesignSystem do
~H"""
<Flop.Phoenix.table items={@items} meta={@meta} path={@path}>
<:col :let={data} :for={col <- @column} label={col.label} field={col.field}>
<%= render_slot(col, data) %>
{render_slot(col, data)}
</:col>
</Flop.Phoenix.table>
"""
Expand All @@ -727,7 +727,7 @@ defmodule PescarteWeb.DesignSystem do
def label(assigns) do
~H"""
<div class="label_component">
<.text size="base" color="text-white-100"><%= @message %></.text>
<.text size="base" color="text-white-100">{@message}</.text>
</div>
"""
end
Expand All @@ -739,12 +739,12 @@ defmodule PescarteWeb.DesignSystem do
~H"""
<div class="profile-menu-link">
<span class="flex items-center justify-center bg-white-100">
<%= render_slot(@inner_block) %>
{render_slot(@inner_block)}
</span>
<.button style="link" class="whitespace-nowrap" click={@click} phx-target=".profile-menu-link">
<.text size="base" color="text-blue-80">
<Lucideicons.credit_card class="text-blue-100" />
<%= @label %>
{@label}
</.text>
</.button>
</div>
Expand Down Expand Up @@ -819,7 +819,7 @@ defmodule PescarteWeb.DesignSystem do
style="top: 1.25rem; align-items: center; max-width: 442px;"
>
<.text size="h2" color="black-80">
<%= @title %>
{@title}
</.text>
<button
phx-click={JS.exec("data-cancel", to: "##{@id}")}
Expand All @@ -832,15 +832,15 @@ defmodule PescarteWeb.DesignSystem do
</button>
</div>
<div id={"#{@id}-content"} style="margin: 64px 0;">
<%= render_slot(@inner_block) %>
{render_slot(@inner_block)}
</div>
<div
:for={footer <- @footer}
id={"#{@id}-footer"}
class={Map.get(footer, :class)}
style={Map.get(footer, :style)}
>
<%= render_slot(footer) %>
{render_slot(footer)}
</div>
</.focus_wrap>
</div>
Expand Down
4 changes: 2 additions & 2 deletions lib/pescarte_web/design_system/authenticated_navbar.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ defmodule PescarteWeb.DesignSystem.AuthenticatedNavbar do
<DesignSystem.link :for={{menu_name, path, icon} <- @menus} navigate={path}>
<li class={"nav-item #{if should_activate_menu_item(path, @current_path), do: "active"}"}>
<.icon name={icon} class="text-black-60" />
<.text :if={@open} size="base" color="text-black-60"><%= menu_name %></.text>
<.text :if={@open} size="base" color="text-black-60">{menu_name}</.text>
</li>
</DesignSystem.link>
</ul>
<a class="user-info" href={~p"/app/pesquisa/perfil"} style="cursor: pointer;">
<Lucideicons.user :if={[email protected]_avatar} class="text-black-60" />
<img :if={@user.link_avatar} src={@user.link_avatar} class="text-black-60" />
<.text :if={@open} size="base" color="text-black-80">
<%= Usuario.build_usuario_name(@user) %>
{Usuario.build_usuario_name(@user)}
</.text>
</a>
</nav>
Expand Down
10 changes: 5 additions & 5 deletions lib/pescarte_web/design_system/multiple_select_input.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ defmodule PescarteWeb.DesignSystem.MultipleSelectInput do
phx-target={@myself}
>
<label :if={@label} for={@name}>
<.text size="h4"><%= @label %></.text>
<.text size="h4">{@label}</.text>
</label>
<div phx-click="toggle_dropdown" phx-target={@myself} class="dropdown-button">
<%= if Enum.any?(@options, & &1.selected) do %>
<span class="selection">
<%= Enum.map_join(Enum.filter(@options, & &1.selected), ", ", & &1.label) %>
{Enum.map_join(Enum.filter(@options, & &1.selected), ", ", & &1.label)}
</span>
<% else %>
<%= @prompt %>
{@prompt}
<% end %>
<div class="icon">
<Lucideicons.chevron_down :if={!@open} />
Expand All @@ -50,12 +50,12 @@ defmodule PescarteWeb.DesignSystem.MultipleSelectInput do
phx-value-content={opt.value}
class={opt.selected && "selected"}
>
<%= opt.label %>
{opt.label}
</li>
</ul>
<select id={@id} name={@name} multiple>
<option :for={opt <- @options} value={opt.value} selected={opt.selected}>
<%= opt.label %>
{opt.label}
</option>
</select>
</fieldset>
Expand Down
2 changes: 1 addition & 1 deletion lib/pescarte_web/design_system/navbar.ex
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ defmodule PescarteWeb.DesignSystem.Navbar do
<DesignSystem.link navigate={@navigate}>
<li class={["nav-link ", if(@current_path == @navigate, do: "active")]} aria-expanded="false">
<.text size="h4" color="text-blue-100" class="flex" style="gap: 8px;">
<%= @label %>
{@label}
</.text>
</li>
</DesignSystem.link>
Expand Down
2 changes: 1 addition & 1 deletion lib/pescarte_web/layouts/app.html.heex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<PescarteWeb.DesignSystem.Navbar.render current_path="{@current_path}" />
<main class="w-full h-full z-0">
<.flash_group flash={@flash} /> <%= @inner_content %>
<.flash_group flash={@flash} /> {@inner_content}
</main>
<.footer />
2 changes: 1 addition & 1 deletion lib/pescarte_web/layouts/authenticated.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
/>
<main>
<.flash_group flash={@flash} />
<%= @inner_content %>
{@inner_content}
</main>
<.footer />
4 changes: 2 additions & 2 deletions lib/pescarte_web/layouts/root.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@
<meta name="theme-color" content="#ffffff" />
<meta name="csrf-token" content={get_csrf_token()} />
<.live_title>
<%= assigns[:page_title] || "Plataforma PEA Pescarte" %>
{assigns[:page_title] || "Plataforma PEA Pescarte"}
</.live_title>
<link phx-track-static rel="stylesheet" href={~p"/assets/app.css"} />
<script defer phx-track-static type="text/javascript" src={~p"/assets/app.js"}>
</script>
</head>
<body class={if !Map.get(assigns, :current_usuario), do: "grid", else: ""}>
<%= @inner_content %>
{@inner_content}
</body>
<script>
if (navigator.serviceWorker) {
Expand Down
4 changes: 2 additions & 2 deletions lib/pescarte_web/live/blog/post_live/show.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ defmodule PescarteWeb.Blog.PostLive.Show do
def render(assigns) do
~H"""
<div class="noticia">
<h1 class="text-4xl leading-10 font-bold text-blue-100"><%= @post.titulo %></h1>
<div class="noticia-descricao"><%= raw(Markdown.to_html(@post.conteudo)) %></div>
<h1 class="text-4xl leading-10 font-bold text-blue-100">{@post.titulo}</h1>
<div class="noticia-descricao">{raw(Markdown.to_html(@post.conteudo))}</div>
<DesignSystem.link href="/noticias" class="text-sm font-semibold">
<.button style="primary">
<Lucideicons.arrow_left class="text-white-100" /> Voltar para Notícias
Expand Down
2 changes: 1 addition & 1 deletion lib/pescarte_web/live/navbar.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule PescarteWeb.NavbarLive do
socket =
assign(socket,
menus: [
{"Home", ~p"/", :home},
{"Home", ~p"/", :house},
{"Pesquisadores", ~p"/app/pesquisa/pesquisadores", :users},
{"Relatórios", ~p"/app/pesquisa/relatorios", :file_text}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ defmodule PescarteWeb.Pesquisa.PesquisadorLive.FormComponent do
~H"""
<div class="researcher-wrapper">
<.text size="h1" color="text-blue-100">
<%= @title %>
{@title}
</.text>
<.form
:let={f}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@

<.table items={@pesquisadores} meta={@meta} path={~p"/app/pesquisa/pesquisadores"}>
<:column :let={pesquisador} label="Nome" field={:nome}>
<%= pesquisador.nome %>
{pesquisador.nome}
</:column>
<:column :let={pesquisador} label="CPF" field={:cpf}>
<%= pesquisador.cpf %>
{pesquisador.cpf}
</:column>
<:column :let={pesquisador} label="E-mail" field={:email}>
<DesignSystem.link href={"mailto:" <> pesquisador.email}>
<%= pesquisador.email %>
{pesquisador.email}
</DesignSystem.link>
</:column>
<:column :let={pesquisador} label="Participação" field={:participacao}>
<%= humanize_bolsa(pesquisador.participacao) %>
{humanize_bolsa(pesquisador.participacao)}
</:column>
</.table>
</div>
Expand Down
4 changes: 2 additions & 2 deletions lib/pescarte_web/live/pesquisa/pesquisador_live/show.ex
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ defmodule PescarteWeb.Pesquisa.PesquisadorLive.Show do
~H"""
<div class="flex items-center profile-link">
<span class="rounded-full bg-blue-80 h-12 w-12 flex-center">
<%= render_slot(@inner_block) %>
{render_slot(@inner_block)}
</span>
<DesignSystem.link href={@href} class="w-12 text-left link">
<.text size="base" color="text-blue-80">
<%= @label %>
{@label}
</.text>
</DesignSystem.link>
</div>
Expand Down
Loading

0 comments on commit 4dd1206

Please sign in to comment.