File tree Expand file tree Collapse file tree 5 files changed +78
-3
lines changed Expand file tree Collapse file tree 5 files changed +78
-3
lines changed Original file line number Diff line number Diff line change
1
+ import { Turbo } from '@hotwired/turbo-rails' ;
2
+ import { Controller } from '@hotwired/stimulus' ;
3
+
4
+ import { debug } from '../../utils' ;
5
+
6
+ const console = debug ( 'app:javascript:controllers:forms:select-nav' ) ;
7
+
8
+ export default class extends Controller {
9
+ static values = {
10
+ turboFrame : String ,
11
+ } ;
12
+
13
+ connect ( ) {
14
+ console . log ( 'Connected' ) ;
15
+ }
16
+
17
+ visit ( event ) {
18
+ const [ selectedOption ] = this . element . selectedOptions ;
19
+ const url = selectedOption . value ;
20
+
21
+ // Value is empty for blank option
22
+ if ( url === '' ) {
23
+ return ;
24
+ }
25
+
26
+ console . log ( 'Visiting' , url , event ) ;
27
+
28
+ const opts = {
29
+ action : 'advance' ,
30
+ } ;
31
+
32
+ if ( this . turboFrameValue ) {
33
+ opts . frame = this . turboFrameValue ;
34
+ }
35
+
36
+ Turbo . visit ( url , opts ) ;
37
+ }
38
+ }
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ import TableOfContents from './table-of-contents';
20
20
21
21
import FrameForm from './forms/frame' ;
22
22
import AutosubmitForm from './forms/autosubmit' ;
23
+ import SelectNav from './forms/select-nav' ;
23
24
import SyntaxHighlightPreview from './syntax-highlight/preview' ;
24
25
25
26
import SnippetPreview from './snippets/preview' ;
@@ -44,6 +45,7 @@ application.register('table-of-contents', TableOfContents);
44
45
45
46
application . register ( 'frame-form' , FrameForm ) ;
46
47
application . register ( 'autosubmit-form' , AutosubmitForm ) ;
48
+ application . register ( 'select-nav' , SelectNav ) ;
47
49
application . register ( 'syntax-highlight-preview' , SyntaxHighlightPreview ) ;
48
50
49
51
application . register ( 'snippet-preview' , SnippetPreview ) ;
Original file line number Diff line number Diff line change 5
5
<div class ="column-content container py-gap mb-3xl ">
6
6
< nav class ="sidebar " data-turbo-permanent >
7
7
<%= turbo_frame_tag :topics_sidebar do %>
8
+ <%= render Topics ::Select . new ( topics , class : "lg:hidden" ) %>
8
9
<% topics . each do |topic | %>
9
- <%= tag . div id : dom_id ( topic ) , class : "text-small mb-2" do %>
10
+ <%= tag . div id : dom_id ( topic ) , class : "text-small mb-2 hidden lg:block " do %>
10
11
<%= link_to topic . name , topic_path ( topic ) , data : { turbo_frame : :topics_mainbar } %>
11
12
< span class ="text-faint "> (<%= topic . pages_count %> )</ span >
12
13
<% end %>
16
17
< div class ="mainbar w-full ">
17
18
<%= turbo_frame_tag :topics_mainbar , data : { turbo_action : "advance" } do %>
18
19
< div >
19
- < h2 > Welcome !</ h2 >
20
+ < h3 class =" mb-8 lg:hidden " > Howdy !</ h3 >
20
21
< div >
21
22
< p > Here you‘ll find topics currently covered at Joy of Rails.</ p >
22
23
< p > Choose a topic from the sidebar to view articles.</ p >
Original file line number Diff line number Diff line change
1
+ module Topics
2
+ class Select < ApplicationComponent
3
+ include Phlex ::Rails ::Helpers ::CurrentPage
4
+ include PhlexConcerns ::FlexBlock
5
+
6
+ attr_reader :topics , :attributes
7
+
8
+ def initialize ( topics = [ ] , **attributes )
9
+ @topics = topics
10
+ @attributes = attributes
11
+ end
12
+
13
+ def view_template
14
+ flex_block ( attributes ) do
15
+ label ( for : "topic" , class : "block text-sm font-medium text-gray-700" ) do
16
+ "Select a topic"
17
+ end
18
+ select (
19
+ name : "topic" ,
20
+ data : {
21
+ :controller => "select-nav" ,
22
+ :action => "select-nav#visit" ,
23
+ "select-nav-turbo-frame-value" => "topics_mainbar"
24
+ }
25
+ ) do
26
+ option ( value : "" ) { "Start here" }
27
+ topics . each do |topic |
28
+ option ( value : topic_path ( topic ) , select : current_page? ( topic_path ( topic ) ) ) { topic . name }
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
Original file line number Diff line number Diff line change 17
17
</ div >
18
18
</ div >
19
19
<% else %>
20
- < h3 class ="mb-8 "> Topic: <%= topic . name %> </ h3 >
20
+ < h3 class ="mb-8 hidden lg:block "> Topic: <%= topic . name %> </ h3 >
21
21
< ul >
22
22
<% topic . pages . as_published_articles . each do |page | %>
23
23
<%= tag . li id : dom_id ( page ) do %>
You can’t perform that action at this time.
0 commit comments