Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianthedev committed Aug 20, 2024
1 parent 5314b8c commit c4b25cc
Show file tree
Hide file tree
Showing 8 changed files with 386 additions and 315 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ PATH
literal (~> 0.2)
meta-tags
pagy (>= 7.0.0)
turbo-rails (>= 2.0.0)
turbo-rails (>= 2.0.6)
turbo_power (>= 0.6.0)
view_component (>= 3.7.0)
zeitwerk (>= 2.6.12)
Expand Down
28 changes: 24 additions & 4 deletions app/components/avo/views/resource_index_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<%= content_tag :div,
<%= turbo_frame_tag "index_view",
target: :_top,
refresh: :morph,
class: class_names("index-#{@index_params[:view_type]}-view", {"has-record-selector": @resource.record_selector}),
data: {
component_name: self.class.to_s.underscore,
Expand Down Expand Up @@ -37,9 +39,27 @@
<div class="flex items-center px-4 w-64">
<% if show_search_input %>
<%= render partial: "avo/partials/resource_search", locals: {resource: @resource.route_key, via_reflection: via_reflection} %>
<label for="resource_search">
<input type="text" name="search" id="resource_search">
</label>

<label class="Xhidden" for="resource_search" data-controller="resource-search">
<a href="/admin/resources/projects?q=strong" data-resource-search-target="link" xdata-turbo-frame="index_view" data-turbo-frame="navigation" data-turbo-action="advance" data-refresh="morph" autofocus>visit</a>
<input type="text" name="search" id="resource_search" data-action="resource-search#submit" value="<%= params[:q] %>">
</label>
<%= form_with url: "/admin/resources/projects",
method: :get,
id: :resource_search,
class: "hidden",
data: {
# turbo_frame: "#{@resource.model_key}_list",
turbo_frame: :index_view,
controller: :"resource-search",
morph: true
} do |f| %>
<%= f.text_field :q, value: params[:q], placeholder: "Search", class: "w-full", data:
{
action: "resource-search#submit"
} %>
<%= f.submit "Search"%>
<% end %>
<% else %>
<%# Offset for the space-y-2 property when the search is missing %>
<div class="-mb-2"></div>
Expand Down
11 changes: 10 additions & 1 deletion app/javascript/avo.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,19 @@ document.addEventListener('turbo:before-fetch-response', async (e) => {
}
})

document.addEventListener('turbo:visit', () => {
document.addEventListener('turbo:visit', (e) => {
console.log('turbo:visit', e.detail)

document.body.classList.add('turbo-loading')
})
document.addEventListener('turbo:submit-start', () => document.body.classList.add('turbo-loading'))
document.addEventListener('turbo:submit-start', (event) => console.log('turbo:submit-start', event, event.detail.renderMethod))
document.addEventListener('turbo:submit-end', (event) => console.log('turbo:submit-end', event, event.detail.renderMethod))
document.addEventListener('turbo:before-render', (event) => console.log('turbo:before-render', event.detail.renderMethod))
document.addEventListener('turbo:before-frame-render', (event) => console.log('turbo:before-frame-render', event.detail))
document.addEventListener('turbo:before-frame', (event) => console.log('turbo:before-frame', event.detail))
document.addEventListener('turbo:frame-load', (event) => console.log('turbo:frame-load', event.detail))
document.addEventListener('turbo:render', (event) => console.log('turbo:render', event.detail.renderMethod))
document.addEventListener('turbo:submit-end', () => document.body.classList.remove('turbo-loading'))
document.addEventListener('turbo:before-cache', () => {
document.querySelectorAll('[data-turbo-remove-before-cache]').forEach((element) => element.remove())
Expand Down
Loading

0 comments on commit c4b25cc

Please sign in to comment.