Create bar controller

This commit is contained in:
Stanko K.R.
2025-08-18 15:06:12 +02:00
parent ff48f8a301
commit 9a6fc1f54a
6 changed files with 85 additions and 22 deletions
@@ -1,4 +1,8 @@
class ConversationsController < ApplicationController
def create
Conversation.create_or_find_by(user: Current.user)
end
def show
@conversation = Current.user.conversation
end
@@ -0,0 +1,29 @@
import { Controller } from "@hotwired/stimulus"
import { post } from "@rails/request.js"
export default class extends Controller {
static targets = [ "modalTurboFrame" ]
static outlets = [ "dialog" ]
static values = {
searchUrl: String,
searchTurboFrameName: String,
askUrl: String,
askTurboFrameName: String
}
search() {
this.#openInTurboFrame(this.searchTurboFrameNameValue, this.searchUrlValue)
this.dialogOutlet.open()
}
async ask() {
post(this.askUrlValue)
this.#openInTurboFrame(this.askTurboFrameNameValue, this.askUrlValue)
this.dialogOutlet.open()
}
#openInTurboFrame(name, url) {
this.modalTurboFrameTarget.id = name
this.modalTurboFrameTarget.src = url
}
}
+1 -1
View File
@@ -20,7 +20,7 @@
<% if Current.user && !@hide_footer_frames %>
<div id="footer_frames" data-turbo-permanent="true">
<%= render "my/pins/tray" %>
<%= render "commands/terminal" %>
<%= render "shared/bar" %>
<%= render "notifications/tray" %>
</div>
<% end %>
+22 -20
View File
@@ -12,27 +12,29 @@
</nav>
<% end %>
<%= auto_submit_form_with url: searches_queries_path(q: @query_terms), method: :post %>
<%= turbo_frame_tag "search", target: :_top do %>
<%= auto_submit_form_with url: searches_queries_path(q: @query_terms), method: :post %>
<section class="search">
<%= render "searches/form", query_terms: @query_terms %>
<section class="search">
<%= render "searches/form", query_terms: @query_terms %>
<div class="search__results">
<% if @query_terms.present? && @search_results.none? %>
<div class="search__empty">
No search results
</div>
<% end %>
<div class="search__results">
<% if @query_terms.present? && @search_results.none? %>
<div class="search__empty">
No search results
</div>
<% end %>
<ul class="search__list">
<%= render partial: "searches/result", collection: @search_results %>
</ul>
</div>
<ul class="search__list">
<%= render partial: "searches/result", collection: @search_results %>
</ul>
</div>
<aside class="search__history">
<h3>Your recent searches…</h3>
<ul class="search__list">
<%= render partial: "searches/search_query", collection: @recent_search_queries.first(10) %>
</ul>
</aside>
</section>
<aside class="search__history">
<h3>Your recent searches…</h3>
<ul class="search__list">
<%= render partial: "searches/search_query", collection: @recent_search_queries.first(10) %>
</ul>
</aside>
</section>
<% end %>
+28
View File
@@ -0,0 +1,28 @@
<%= tag.div \
class: "terminal full-width flex flex-column justify-end",
data: {
controller: "bar",
bar_dialog_outlet: "#bar-modal",
bar_search_url_value: search_path,
bar_search_turbo_frame_name_value: "search",
bar_ask_url_value: conversation_path,
bar_ask_turbo_frame_name_value: "conversation",
action: "
keydown.meta+k@document->bar#search:prevent keydown.ctrl+k@document->bar#search:prevent
keydown.meta+a@document->bar#ask:prevent keydown.ctrl+a@document->bar#ask:prevent"
} do %>
<div>
Search [<%= hotkey_label(["ctrl", "K"]) %>] or Ask [<%= hotkey_label(["ctrl", "A"]) %>]
</div>
<%= tag.dialog \
id: "bar-modal",
class: "bar__modal panel shadow",
data: {
controller: "dialog",
dialog_target: "dialog",
dialog_modal_value: "true",
action: "keydown.esc->dialog#close click@document->dialog#closeOnClickOutside" } do %>
<%= turbo_frame_tag nil, data: { bar_target: "modalTurboFrame" }, target: "_top" %>
<% end %>
<% end %>
+1 -1
View File
@@ -111,7 +111,7 @@ Rails.application.routes.draw do
resources :commands
resource :conversation, only: %i[ show ] do
resource :conversation, only: %i[ show create ] do
scope module: :conversations do
resources :messages, only: %i[ index create ]
end