Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate tabs for pending and downloaded in media history #508

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ defmodule Pinchflat.Pages.HistoryTableLive do
"""
end

def mount(_params, _session, socket) do
def mount(_params, session, socket) do
page = 1
base_query = generate_base_query()
media_state = session["media_state"]
base_query = generate_base_query(media_state)
pagination_attrs = fetch_pagination_attributes(base_query, page)

{:ok, assign(socket, Map.merge(pagination_attrs, %{base_query: base_query}))}
{:ok, assign(socket, Map.merge(pagination_attrs, %{base_query: base_query, media_state: media_state}))}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: you don't need to pass media_state in the new assigns since we're not currently doing anything with that outside of the mount function.

Since that's the case, I figure you can also save the intermediate variable and just use:

base_query = generate_base_query(session["media_state"])
# ...
{:ok, assign(socket, Map.merge(pagination_attrs, %{base_query: base_query}))}

end

def handle_event("page_change", %{"direction" => direction}, %{assigns: assigns} = socket) do
Expand Down Expand Up @@ -97,13 +98,20 @@ defmodule Pinchflat.Pages.HistoryTableLive do
|> Repo.preload(:source)
end

defp generate_base_query do
defp generate_base_query("pending") do
MediaQuery.new()
|> MediaQuery.require_assoc(:media_profile)
|> where(^dynamic(^MediaQuery.downloaded() or ^MediaQuery.pending()))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is just for pending media items, could you please remove the MediaQuery.downloaded() from this query?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah shoot, forgot to change it. First i was thinking about a "All" tab. Then i realized there are also the "other" entries.

|> order_by(desc: :id)
end

defp generate_base_query("downloaded") do
MediaQuery.new()
|> MediaQuery.require_assoc(:media_profile)
|> where(^dynamic(^MediaQuery.downloaded()))
|> order_by(desc: :id)
end

defp format_datetime(nil), do: ""

defp format_datetime(datetime) do
Expand Down
19 changes: 16 additions & 3 deletions lib/pinchflat_web/controllers/pages/page_html/home.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,22 @@

<div class="rounded-sm border shadow-default border-strokedark bg-boxdark mt-4 p-5">
<span class="text-2xl font-medium mb-4">Media History</span>
<section class="mt-6">
{live_render(@conn, Pinchflat.Pages.HistoryTableLive)}
</section>
<.tabbed_layout>
<:tab title="Downloaded" id="downloaded">
{live_render(
@conn,
Pinchflat.Pages.HistoryTableLive,
session: %{"media_state" => "downloaded"}
)}
</:tab>
<:tab title="Pending" id="pending">
{live_render(
@conn,
Pinchflat.Pages.HistoryTableLive,
session: %{"media_state" => "pending"}
)}
</:tab>
</.tabbed_layout>
</div>

<div class="rounded-sm border shadow-default border-strokedark bg-boxdark mt-4 p-5">
Expand Down