M lib/shop_local/cache_provider.ex => lib/shop_local/cache_provider.ex +2 -6
@@ 16,17 16,13 @@ defmodule ShopLocal.CacheProvider do
defp search_map(cache, s_params) do
Enum.filter_map(cache,
fn ({ key, value }) ->
- Enum.all?(s_params, &(
- String.contains?(String.downcase(value.search), &1)
- || String.contains?(String.downcase(value.desc), &1)
- || String.contains?(String.downcase(value.name), &1)
- ))
+ Enum.all?(s_params, &(String.contains?(String.downcase(value.search), &1)))
end,
fn ({ key, value }) -> value end)
end
# If we miss x number of searches, stop asking for a while
- @no_search_threshold 2
+ @no_search_threshold 1
defp missed?(missed, s_params) do
missed
M lib/shop_local/clothing_tree_search_provider.ex => lib/shop_local/clothing_tree_search_provider.ex +7 -0
@@ 18,6 18,8 @@ defmodule ShopLocal.ClothingTreeSearchProvider do
link = k
|> Floki.find("a.product-item__link")
|> Floki.attribute("href")
+ |> List.first
+
image_src = k
|> Floki.find("img.product-item__image")
|> Floki.attribute("src")
@@ 37,6 39,11 @@ defmodule ShopLocal.ClothingTreeSearchProvider do
_ -> nil
end
+ link = case String.starts_with?(link, "http") do
+ false -> "https://www.clothes-tree.com/" <> link
+ true -> link
+ end
+
%{
provider: "Clothes Tree",
name: name,
M lib/shop_local_web/templates/page/index.html.eex => lib/shop_local_web/templates/page/index.html.eex +33 -29
@@ 42,32 42,39 @@
<% end %>
</section>
<section class="row results">
- <ul>
<%= if Map.has_key?(assigns, :results) do %>
- <%= for i <- @results do %>
- <li>
- <a href="<%= i.link %>">
- <b><%= i.name %></b>
- <i><%= view_price(i.price) %></i>
- — <%= i.provider %>
- <div class="product-content">
- <div class="product-image-container">
- <%= if i.image_src != "" do %>
- <img
- class="product-image"
- loading="lazy"
- alt="Product Image"
- src="<%= i.image_src %>"
- >
- <% end %>
- </div>
- <p><%= i.desc %></p>
- </div>
- </a>
- </li>
+ <%= if Enum.empty?(@results) do %>
+ <div class="no-results">
+ <h1 >Sorry, no results found.</h1>
+ <p>It could help to try changing the search options, or to use different keywords.</p>
+ </div>
+ <%= else %>
+ <ul>
+ <%= for i <- @results do %>
+ <li>
+ <a href="<%= i.link %>">
+ <b><%= i.name %></b>
+ <i><%= view_price(i.price) %></i>
+ — <%= i.provider %>
+ <div class="product-content">
+ <div class="product-image-container">
+ <%= if i.image_src != "" do %>
+ <img
+ class="product-image"
+ loading="lazy"
+ alt="Product Image"
+ src="<%= i.image_src %>"
+ >
+ <% end %>
+ </div>
+ <p><%= i.desc %></p>
+ </div>
+ </a>
+ </li>
+ <% end %>
+ </ul>
<% end %>
<% end %>
- </ul>
</section>
@@ 96,18 103,15 @@
<a href="https://www.browsersbookstore.com/">Browsers Bookstore (Corvallis)</a>
</li>
<li>
- <a href="https://grassrootsbookstore.com/">Grassroots Bookstore</a>
- </li>
- <li>
- <a href="https://merriartist.com/">The Merri Artist</a>
- </li>
- <li>
<a href="https://www.clothes-tree.com/">The Clothes Tree</a>
</li>
<li>
<a href="https://conundrum.house/">Conundrum House</a>
</li>
<li>
+ <a href="https://grassrootsbookstore.com/">Grassroots Bookstore</a>
+ </li>
+ <li>
<a href="https://merriartist.com/">The Merri Artist</a>
</li>
<li>
M priv/static/css/app.css => priv/static/css/app.css +6 -0
@@ 70,3 70,9 @@ form {
.product-image {
width: 100%;
}
+
+.no-results {
+ text-align: center;
+ width: 100%;
+ padding-bottom: 50px;
+}