Skip to content

Commit

Permalink
hide own studio commissions in My Commissions page
Browse files Browse the repository at this point in the history
Fixes: #592
  • Loading branch information
zkat committed Aug 12, 2023
1 parent 66c3e5f commit c4f0c72
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
19 changes: 19 additions & 0 deletions lib/banchan/commissions/commissions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ defmodule Banchan.Commissions do
* `page` - The page number to return. Defaults to 1.
* `page_size` - The number of items to return per page. Defaults to 24.
* `exclude_member` - Exclude commissions where the current user is a
member of the studio.
* `order_by` - Sort order, and in some cases, filters. Defaults to
`:recently_updated`. Supports the following values:
* `:recently_updated` - List by most recently updated commissions (with
Expand All @@ -102,6 +104,7 @@ defmodule Banchan.Commissions do
opts \\ []
) do
main_dashboard_query(user)
|> dashboard_exclude_member(opts)
|> dashboard_query_filter(filter)
|> dashboard_order_by(opts)
|> Repo.paginate(
Expand Down Expand Up @@ -153,6 +156,22 @@ defmodule Banchan.Commissions do
end
end

defp dashboard_exclude_member(q, opts) do
if Keyword.get(opts, :exclude_member, false) do
q
|> join(
:left,
[current_user: u, studio: s],
current_member in assoc(s, :artists),
on: current_member.id == u.id,
as: :current_member
)
|> where([current_member: current_member], is_nil(current_member.id))
else
q
end
end

defp dashboard_order_by(q, opts) do
case Keyword.fetch(opts, :order_by) do
{:ok, :recently_updated} ->
Expand Down
15 changes: 8 additions & 7 deletions lib/banchan_web/live/commission_live/index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,6 @@ defmodule BanchanWeb.CommissionLive do
|> assign(status_options: @status_options)
|> assign(filter_open: Map.get(socket.assigns, :filter_open, false))

socket =
socket
|> assign(
:results,
list_comms(socket)
)

socket =
case params do
%{"commission_id" => commission_id} ->
Expand Down Expand Up @@ -124,6 +117,13 @@ defmodule BanchanWeb.CommissionLive do
end
)

socket =
socket
|> assign(
:results,
list_comms(socket)
)

socket =
Context.put(socket,
commission: socket.assigns.commission,
Expand Down Expand Up @@ -335,6 +335,7 @@ defmodule BanchanWeb.CommissionLive do
Commissions.list_commissions(
socket.assigns.current_user,
Ecto.Changeset.apply_changes(socket.assigns.filter),
exclude_member: is_nil(socket.assigns.studio),
page: page,
page_size: 10,
order_by: socket.assigns.order_by
Expand Down

0 comments on commit c4f0c72

Please sign in to comment.