11import { withPluginApi } from "discourse/lib/plugin-api" ;
2- import { getOwner } from "@ember/application" ;
32
43export default {
54 name : "just-chat-home-logo-href" ,
@@ -22,7 +21,7 @@ export default {
2221 } else if ( this . _super ) {
2322 return this . _super ( ...arguments ) ;
2423 }
25- }
24+ } ,
2625 } ) ;
2726
2827 function redirectToChatAndSidebar ( router ) {
@@ -35,14 +34,14 @@ export default {
3534 api . modifyClass ( "route:user-activity-drafts" , {
3635 beforeModel ( ) {
3736 redirectToChatAndSidebar ( this . router ) ;
38- }
37+ } ,
3938 } ) ;
4039
4140 // Block user activity route in Ember
4241 api . modifyClass ( "route:user-activity" , {
4342 beforeModel ( ) {
4443 redirectToChatAndSidebar ( this . router ) ;
45- }
44+ } ,
4645 } ) ;
4746
4847 // Force chat sidebar on preferences/account route
@@ -77,14 +76,7 @@ export default {
7776 } ) ;
7877
7978 // Redirect all common list/user activity routes to /chat
80- [
81- "latest" ,
82- "new" ,
83- "top" ,
84- "hot" ,
85- "unread" ,
86- "unseen" ,
87- ] . forEach ( ( filter ) => {
79+ [ "latest" , "new" , "top" , "hot" , "unread" , "unseen" ] . forEach ( ( filter ) => {
8880 api . modifyClass ( `route:discovery/${ filter } ` , {
8981 beforeModel ( transition ) {
9082 if (
@@ -96,39 +88,49 @@ export default {
9688 } else if ( this . _super ) {
9789 return this . _super ( ...arguments ) ;
9890 }
99- }
91+ } ,
10092 } ) ;
10193 } ) ;
10294
10395 // Intercept category link clicks
10496 api . onPageChange ( ( ) => {
10597 // Handle category list links
106- document . querySelectorAll ( ' .category-title-link' ) . forEach ( link => {
107- link . addEventListener ( ' click' , ( e ) => {
98+ document . querySelectorAll ( " .category-title-link" ) . forEach ( ( link ) => {
99+ link . addEventListener ( " click" , ( e ) => {
108100 e . preventDefault ( ) ;
109- const href = link . getAttribute ( ' href' ) ;
101+ const href = link . getAttribute ( " href" ) ;
110102 if ( href ) {
111103 const router = api . container . lookup ( "service:router" ) ;
112104 // Extract the category path from the href, ignoring IDs
113105 const match = href . match ( / \/ c \/ ( [ ^ \/ ] + (?: \/ [ ^ \/ ] + ) ? ) (?: \/ \d + ) ? $ / ) ;
114106 if ( match ) {
115107 // Remove any trailing ID from the category path
116- const categoryPath = match [ 1 ] . replace ( / \/ \d + $ / , '' ) ;
108+ const categoryPath = match [ 1 ] . replace ( / \/ \d + $ / , "" ) ;
117109 // Check if it's a subcategory
118- const parts = categoryPath . split ( '/' ) ;
110+ const parts = categoryPath . split ( "/" ) ;
119111 if ( parts . length > 1 ) {
120112 // It's a subcategory, use original parent category
121113 const targetUrl = `/c/${ parts [ 0 ] } /${ parts [ 1 ] } /edit/` ;
122- const sidebarState = api . container . lookup ( "service:sidebar-state" ) ;
123- if ( sidebarState && typeof sidebarState . setPanel === "function" ) {
114+ const sidebarState = api . container . lookup (
115+ "service:sidebar-state"
116+ ) ;
117+ if (
118+ sidebarState &&
119+ typeof sidebarState . setPanel === "function"
120+ ) {
124121 sidebarState . setPanel ( "chat" ) ;
125122 }
126123 router . replaceWith ( targetUrl ) ;
127124 } else {
128125 // It's a parent category
129126 const targetUrl = `/c/${ categoryPath } /edit/` ;
130- const sidebarState = api . container . lookup ( "service:sidebar-state" ) ;
131- if ( sidebarState && typeof sidebarState . setPanel === "function" ) {
127+ const sidebarState = api . container . lookup (
128+ "service:sidebar-state"
129+ ) ;
130+ if (
131+ sidebarState &&
132+ typeof sidebarState . setPanel === "function"
133+ ) {
132134 sidebarState . setPanel ( "chat" ) ;
133135 }
134136 router . replaceWith ( targetUrl ) ;
@@ -139,41 +141,55 @@ export default {
139141 } ) ;
140142
141143 // Handle chat interface category links
142- document . querySelectorAll ( '.badge-category__wrapper' ) . forEach ( link => {
143- link . addEventListener ( 'click' , ( e ) => {
144- e . preventDefault ( ) ;
145- const href = link . getAttribute ( 'href' ) ;
146- if ( href ) {
147- const router = api . container . lookup ( "service:router" ) ;
148- // Extract the category path from the href, ignoring IDs
149- const match = href . match ( / \/ c \/ ( [ ^ \/ ] + (?: \/ [ ^ \/ ] + ) ? ) (?: \/ \d + ) ? $ / ) ;
150- if ( match ) {
151- // Remove any trailing ID from the category path
152- const categoryPath = match [ 1 ] . replace ( / \/ \d + $ / , '' ) ;
153- // Check if it's a subcategory
154- const parts = categoryPath . split ( '/' ) ;
155- if ( parts . length > 1 ) {
156- // It's a subcategory, use original parent category
157- const targetUrl = `/c/${ parts [ 0 ] } /${ parts [ 1 ] } /edit/` ;
158- const sidebarState = api . container . lookup ( "service:sidebar-state" ) ;
159- if ( sidebarState && typeof sidebarState . setPanel === "function" ) {
160- sidebarState . setPanel ( "chat" ) ;
161- }
162- router . replaceWith ( targetUrl ) ;
163- } else {
164- // It's a parent category
165- const targetUrl = `/c/${ categoryPath } /edit/` ;
166- const sidebarState = api . container . lookup ( "service:sidebar-state" ) ;
167- if ( sidebarState && typeof sidebarState . setPanel === "function" ) {
168- sidebarState . setPanel ( "chat" ) ;
144+ document
145+ . querySelectorAll ( ".badge-category__wrapper" )
146+ . forEach ( ( link ) => {
147+ link . addEventListener ( "click" , ( e ) => {
148+ e . preventDefault ( ) ;
149+ const href = link . getAttribute ( "href" ) ;
150+ if ( href ) {
151+ const router = api . container . lookup ( "service:router" ) ;
152+ // Extract the category path from the href, ignoring IDs
153+ const match = href . match (
154+ / \/ c \/ ( [ ^ \/ ] + (?: \/ [ ^ \/ ] + ) ? ) (?: \/ \d + ) ? $ /
155+ ) ;
156+ if ( match ) {
157+ // Remove any trailing ID from the category path
158+ const categoryPath = match [ 1 ] . replace ( / \/ \d + $ / , "" ) ;
159+ // Check if it's a subcategory
160+ const parts = categoryPath . split ( "/" ) ;
161+ if ( parts . length > 1 ) {
162+ // It's a subcategory, use original parent category
163+ const targetUrl = `/c/${ parts [ 0 ] } /${ parts [ 1 ] } /edit/` ;
164+ const sidebarState = api . container . lookup (
165+ "service:sidebar-state"
166+ ) ;
167+ if (
168+ sidebarState &&
169+ typeof sidebarState . setPanel === "function"
170+ ) {
171+ sidebarState . setPanel ( "chat" ) ;
172+ }
173+ router . replaceWith ( targetUrl ) ;
174+ } else {
175+ // It's a parent category
176+ const targetUrl = `/c/${ categoryPath } /edit/` ;
177+ const sidebarState = api . container . lookup (
178+ "service:sidebar-state"
179+ ) ;
180+ if (
181+ sidebarState &&
182+ typeof sidebarState . setPanel === "function"
183+ ) {
184+ sidebarState . setPanel ( "chat" ) ;
185+ }
186+ router . replaceWith ( targetUrl ) ;
169187 }
170- router . replaceWith ( targetUrl ) ;
171188 }
172189 }
173- }
190+ } ) ;
174191 } ) ;
175- } ) ;
176192 } ) ;
177193 } ) ;
178- }
194+ } ,
179195} ;
0 commit comments