Skip to content

Commit

Permalink
feat: improve spotlight and file uploader (#522)
Browse files Browse the repository at this point in the history
  • Loading branch information
nunom27 authored Feb 11, 2025
1 parent e5f8fc3 commit 9468715
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/safira_web/components/banner.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule SafiraWeb.Components.Banner do
<div
id="banner"
phx-hook="Banner"
class="relative w-full bg-white text-center p-4 text-black font-bold shadow-lg z-10 transition-transform transform"
class="relative w-full bg-gradient-to-b from-accent to-transparent from-85% text-center pt-2 pb-3 text-primary/70 font-bold z-10 transition-transform transform"
data-end={@end_time}
>
<p><%= @text %></p>
Expand Down
24 changes: 20 additions & 4 deletions lib/safira_web/components/cv_upload.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ defmodule SafiraWeb.Components.CVUpload do
</div>
</:placeholder>
</.image_uploader>
<div :if={@current_user.cv} class="pt-2">
<p class="text-sm text-lightSahde dark:text-darkMuted">
<%= gettext("Current CV: ") %><span class="text-lightMuted"><%= @current_user.cv.file_name %></span>
</p>
<p class="text-sm text-lightMuted dark:text-darkMuted">
<%= gettext("You can replace your current CV by uploading again.") %>
</p>
</div>
</div>
</div>
<:actions>
Expand Down Expand Up @@ -81,10 +89,11 @@ defmodule SafiraWeb.Components.CVUpload do
case Accounts.update_user(socket.assigns.current_user, user_params) do
{:ok, user} ->
case consume_pdf_data(user, socket) do
{:ok, _user} ->
{:ok, user} ->
{:noreply,
socket
|> put_flash(:info, "CV uploaded successfully.")
|> assign(current_user: Map.put(socket.assigns.current_user, :cv, user.cv))
|> push_patch(to: socket.assigns.patch)}

{:error, reason} ->
Expand All @@ -106,15 +115,22 @@ defmodule SafiraWeb.Components.CVUpload do
path: path
}
})
|> case do
{:ok, user} ->
{:ok, user}

{:error, _changeset} ->
{:error, "An error occurred while updating the user."}
end
end)
|> case do
[] ->
{:error, "Select a file to upload."}

[{:ok, user}] ->
{:ok, user}
[error: _message] ->
{:error, "An error occurred while uploading the file."}

_errors ->
[user] ->
{:ok, user}
end
end
Expand Down
19 changes: 15 additions & 4 deletions lib/safira_web/components/image_uploader.ex
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,17 @@ defmodule SafiraWeb.Components.ImageUploader do
<%= for entry <- @upload.entries do %>
<article class="h-full">
<figure class="h-full flex items-center justify-center">
<.live_img_preview
class={[@rounded && "p-0", not @rounded && "p-4", @image_class]}
entry={entry}
/>
<%= if image_file?(entry) do %>
<.live_img_preview
class={[@rounded && "p-0", not @rounded && "p-4", @image_class]}
entry={entry}
/>
<% else %>
<div class="select-none flex flex-col gap-2 items-center text-lightMuted dark:text-darkMuted">
<.icon name="hero-document" class="w-12 h-12" />
<p class="px-4 text-center"><%= entry.client_name %></p>
</div>
<% end %>
</figure>
<%= for err <- upload_errors(@upload, entry) do %>
<p class="alert alert-danger"><%= Phoenix.Naming.humanize(err) %></p>
Expand All @@ -66,4 +73,8 @@ defmodule SafiraWeb.Components.ImageUploader do
</section>
"""
end

defp image_file?(entry) do
entry.client_type in ["image/jpeg", "image/png", "image/gif"]
end
end

0 comments on commit 9468715

Please sign in to comment.