Skip to content

Commit

Permalink
Search
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiotapia committed Jan 18, 2024
1 parent 760a260 commit a09e516
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/magnetissimo/crawlers/yts.ex
Expand Up @@ -11,7 +11,7 @@ defmodule Magnetissimo.Crawlers.Yts do

json = Req.get!("https://yts.mx/api/v2/list_movies.json").body

json["data"]["movies"]
(json["data"]["movies"] || [])
|> Enum.each(fn torrent_json ->
ingest_torrent_json(torrent_json)
end)
Expand All @@ -29,7 +29,7 @@ defmodule Magnetissimo.Crawlers.Yts do
json =
Req.get!("https://yts.mx/api/v2/list_movies.json?query_term=#{search_term}&limit=50").body

json["data"]["movies"]
(json["data"]["movies"] || [])
|> Enum.each(fn torrent_json ->
ingest_torrent_json(torrent_json)
end)
Expand Down
6 changes: 4 additions & 2 deletions lib/magnetissimo/torrents.ex
Expand Up @@ -258,12 +258,14 @@ defmodule Magnetissimo.Torrents do

case Cachex.get(:cache, search_term) do
{:ok, nil} ->
[
crawlers = [
Magnetissimo.Crawlers.Leetx,
Magnetissimo.Crawlers.TorrentDownloads,
Magnetissimo.Crawlers.Yts
]
|> Task.async_stream(

Task.async_stream(
crawlers,
fn crawler_module ->
crawler_module.search(search_term)
end,
Expand Down
2 changes: 1 addition & 1 deletion lib/magnetissimo_web/components/core_components.ex
Expand Up @@ -396,7 +396,7 @@ defmodule MagnetissimoWeb.CoreComponents do

def label(assigns) do
~H"""
<label for={@for} class="block text-sm font-semibold leading-6 text-zinc-800">
<label for={@for} class="block text-sm font-semibold leading-6 text-black dark:text-white">
<%= render_slot(@inner_block) %>
</label>
"""
Expand Down
12 changes: 12 additions & 0 deletions lib/magnetissimo_web/live/search_live.ex
Expand Up @@ -72,6 +72,18 @@ defmodule MagnetissimoWeb.SearchLive do
end
end

def handle_event("filter", params, socket) do
search = params["filter"]["search"] || ""

filter_opts = %{search: search}

socket =
socket
|> assign(:filters, filter_opts)

{:noreply, push_patch(socket, to: ~p"/?#{filter_opts}")}
end

def handle_event("next-page", _, socket) do
{:noreply, paginate_torrents(socket, socket.assigns.page + 1)}
end
Expand Down
21 changes: 21 additions & 0 deletions lib/magnetissimo_web/live/search_live.html.heex
Expand Up @@ -21,6 +21,27 @@
</div>

<div class="lg:w-4/5 w-5/5 relative overflow-x-auto shadow-md sm:rounded-lg">
<.form
:let={f}
for={%{}}
as={:filter}
phx-change="filter"
class="flex flex-col flex-1relative"
id="collection-filter-form"
>
<div class="mb-4">
<.input
field={f[:search]}
type="text"
name="filter[search]"
label="Search"
value={@filters.search}
phx-debounce="400"
placeholder="Try searching for `av1`"
/>
</div>
</.form>

<table class="w-full text-sm text-left rtl:text-right text-gray-500 dark:text-white">
<thead class="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400">
<tr>
Expand Down

0 comments on commit a09e516

Please sign in to comment.