-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1820 from MushroomObserver/nimmo-cache-try2
Cache the sidebar nav
- Loading branch information
Showing
7 changed files
with
112 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Controller } from "@hotwired/stimulus" | ||
|
||
// Connects to data-controller="nav-active" | ||
// Adds CSS class "active" to a nav link if it matches the current location | ||
export default class extends Controller { | ||
static targets = ['link'] | ||
|
||
connect() { | ||
this.element.dataset.stimulus = "connected"; | ||
this.pickActive(); | ||
} | ||
|
||
pickActive() { | ||
this.linkTargets.forEach((link) => { | ||
if ((link.pathname + link.search) == | ||
(location.pathname + location.search)) { | ||
link.classList.add('active') | ||
} | ||
}) | ||
} | ||
|
||
navigate(e) { | ||
const activeButton = this.element.querySelector('.active') | ||
|
||
if (activeButton) { | ||
activeButton.classList.remove('active') | ||
} | ||
|
||
e.target.classList.add('active') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 12 additions & 9 deletions
21
app/views/controllers/application/sidebar/_latest.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
<%= tag.div("#{:app_latest.t}:", class: classes[:heading]) %> | ||
<%= active_link_to(:NEWS.t, articles_path, | ||
class: classes[:indent], id: "nav_articles_link") %> | ||
<%= | ||
[ | ||
active_link_to(:NEWS.t, articles_path, | ||
class: classes[:indent], id: "nav_articles_link"), | ||
active_link_to(:app_latest_changes.t, activity_logs_path, | ||
class: classes[:indent], id: "nav_activity_logs_link"), | ||
active_link_to(:app_newest_images.t, images_path, | ||
class: classes[:indent], id: "nav_images_link"), | ||
active_link_to(:app_comments.t, comments_path, | ||
class: classes[:indent], id: "nav_comments_link") | ||
].safe_join | ||
active_link_to(:app_latest_changes.t, activity_logs_path, | ||
class: classes[:indent], | ||
id: "nav_activity_logs_link"), | ||
active_link_to(:app_newest_images.t, images_path, | ||
class: classes[:indent], | ||
id: "nav_images_link"), | ||
active_link_to(:app_comments.t, comments_path, | ||
class: classes[:indent], | ||
id: "nav_comments_link") | ||
].safe_join if @user | ||
%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters