Skip to content

Commit 84488ca

Browse files
committed
Use Turbo for search results page
1 parent 9ceb09b commit 84488ca

File tree

8 files changed

+119
-3
lines changed

8 files changed

+119
-3
lines changed

apps/components_guide_web/assets/js/app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import "phoenix_html";
1313
import { Socket } from "phoenix";
1414
import NProgress from "nprogress";
1515
import LiveSocket from "phoenix_live_view";
16+
import * as Turbo from "@hotwired/turbo";
1617

1718
let csrfToken = document
1819
.querySelector("meta[name='csrf-token']")

apps/components_guide_web/assets/package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/components_guide_web/assets/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"watch": "webpack --mode development --watch"
77
},
88
"dependencies": {
9+
"@hotwired/turbo": "^7.0.0-beta.4",
910
"nprogress": "^0.2.0",
1011
"phoenix": "file:../../../deps/phoenix",
1112
"phoenix_html": "file:../../../deps/phoenix_html",

apps/components_guide_web/lib/components_guide_web/controllers/research_controller.ex

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ defmodule ComponentsGuideWeb.ResearchController do
55
alias ComponentsGuide.Research.Spec
66
alias ComponentsGuideWeb.ResearchView, as: View
77

8-
def index(conn, %{"q" => query}) do
8+
def index(conn, %{"q" => query, "turbo" => _}) do
99
query = query |> String.trim()
1010

1111
case query do
@@ -14,10 +14,35 @@ defmodule ComponentsGuideWeb.ResearchController do
1414

1515
query ->
1616
results = load_results(query)
17-
render(conn, "index.html", %{query: query, results: results})
17+
render(conn, "turbo-results.html", %{query: query, results: results})
1818
end
1919
end
2020

21+
def index(conn, %{"q" => query}) do
22+
query = query |> String.trim()
23+
24+
case query do
25+
"" ->
26+
render(conn, "empty.html")
27+
28+
query ->
29+
render(conn, "turbo-initial.html", %{query: query})
30+
end
31+
end
32+
33+
# def index(conn, %{"q" => query}) do
34+
# query = query |> String.trim()
35+
#
36+
# case query do
37+
# "" ->
38+
# render(conn, "empty.html")
39+
#
40+
# query ->
41+
# results = load_results(query)
42+
# render(conn, "index.html", %{query: query, results: results})
43+
# end
44+
# end
45+
2146
def index(conn, _params) do
2247
index(conn, %{"q" => ""})
2348
end
@@ -43,7 +68,8 @@ defmodule ComponentsGuideWeb.ResearchController do
4368
content_tag(
4469
:article,
4570
children,
46-
class: "mb-4 text-xl spacing-y-4 p-4 text-white bg-blue-900 border border-blue-700 rounded shadow-lg"
71+
class:
72+
"mb-4 text-xl spacing-y-4 p-4 text-white bg-blue-900 border border-blue-700 rounded shadow-lg"
4773
)
4874
end
4975
end

apps/components_guide_web/lib/components_guide_web/templates/layout/_contentinfo.html.eex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
<div class="X pt-8 pb-12">
33
<%= render ComponentsGuideWeb.IntegrationsView, "convertkit_form.html", [] %>
44
</div>
5+
6+
<turbo-frame id="footer" src="/random">
7+
</turbo-frame>
58

69
<ul class="list-none text-xs mt-4 leading-loose text-gray-500">
710
<li>Copyright © 2020 Patrick Smith
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<%
2+
heading = "Research 🔍 specs and implementations"
3+
heading = "Search across Can I Use, BundlePhobia, W3 & WhatWG specs"
4+
%>
5+
6+
<header class="text-white bg-gray-900">
7+
<div class="bg-indigo-900">
8+
<h2 class="mx-auto max-w-4xl py-4 text-2xl text-center italic leading-tight text-indigo-100">
9+
<%= heading %>
10+
</h2>
11+
</div>
12+
<section class="container px-6 pb-8">
13+
<form role=search action="/research" class="flex h-full pt-8 items-center">
14+
<input type=text name=q placeholder="Search" class="w-full py-1 px-6 text-3xl bg-white text-black border rounded-full" value="<%= @query %>">
15+
</form>
16+
<dl
17+
class="text-xl grid gap-2 items-center pt-4 px-6"
18+
style="
19+
grid-template-columns: auto 1fr;
20+
--link-color: #76a9fa;
21+
--hover\:link-decoration: underline;"
22+
>
23+
<dt>HTML & Roles</dt>
24+
<dd>
25+
<ul class="list-none flex flex-wrap italic" style="--link-padding: 0.75em">
26+
<li><%= link("form", to: "?q=form") %>
27+
<li><%= link("button", to: "?q=button") %>
28+
<li><%= link("contentinfo", to: "?q=contentinfo") %>
29+
<li><%= link("dialog", to: "?q=dialog") %>
30+
<li><%= link("menu", to: "?q=menu") %>
31+
</ul>
32+
</dd>
33+
<dt>Third-party</dt>
34+
<dd>
35+
<ul class="list-none flex flex-wrap italic" style="--link-padding: 0.75em">
36+
<li><%= link("react-dom", to: "?q=react-dom") %>
37+
<li><%= link("preact", to: "?q=preact") %>
38+
<li><%= link("vue", to: "?q=vue") %>
39+
<li><%= link("lit-html", to: "?q=lit-html") %>
40+
<li><%= link("xstate", to: "?q=xstate") %>
41+
<li><%= link("mobx", to: "?q=mobx") %>
42+
<li><%= link("lodash", to: "?q=lodash") %>
43+
<li><%= link("wonka", to: "?q=wonka") %>
44+
</ul>
45+
</dd>
46+
<dt>Concepts</dt>
47+
<dd>
48+
<ul class="list-none flex flex-wrap italic" style="--link-padding: 0.75em">
49+
<li><%= link("error", to: "?q=error") %>
50+
</ul>
51+
</dd>
52+
</dl>
53+
</section>
54+
</header>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<turbo-frame id=search src="/research?q=<%= @query %>&turbo=1" target=_top>
2+
3+
<%= render @view_module, "_header.html", query: @query %>
4+
5+
<div class="text-white bg-gray-900 py-8">
6+
<div class="container">
7+
<div class="px-6">
8+
<div>Loading…</div>
9+
</div>
10+
</div>
11+
</div>
12+
13+
</turbo-frame>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<turbo-frame id=search target=_top>
2+
3+
<%= render @view_module, "_header.html", query: @query %>
4+
5+
<div class="text-white bg-gray-900 py-8">
6+
<div class="container">
7+
<div class="px-6">
8+
<%= @results %>
9+
</div>
10+
</div>
11+
</div>
12+
13+
</turbo-frame>

0 commit comments

Comments
 (0)