Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add event to highlight active menu #51207

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions core/src/components/AppMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,12 @@ export default defineComponent({

mounted() {
subscribe('nextcloud:app-menu.refresh', this.setApps)
subscribe('nextcloud:app-menu.active', this.setActive)
Copy link
Contributor Author

@Koc Koc Mar 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO method in OC namespace is better. This allow us to write more universal apps to support multiple NC versions:

if (OC.setNavigationActive) {
  // we are on newer NC api and can use method
} else {
  // we are on legacy NC api and should do css manipulations to preserve BC
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OC. shall not be used by apps, its private API and might change at any time.
Also OCP. is deprecated as we aim to remove all exposed global states and only provide version agnostic API through packages.

Copy link
Contributor

@susnux susnux Mar 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
subscribe('nextcloud:app-menu.active', this.setActive)
subscribe('nextcloud:app-menu:activate', this.setActive)

https://github.com/nextcloud-libraries/nextcloud-event-bus?tab=readme-ov-file#naming-convention

},

beforeDestroy() {
unsubscribe('nextcloud:app-menu.refresh', this.setApps)
unsubscribe('nextcloud:app-menu.active', this.setActive)
},

methods: {
Expand All @@ -104,6 +106,19 @@ export default defineComponent({
}
},

setActive(id: string) {
this.appList.forEach((app) => {
this.$set(app, 'active', false)
})

const app = this.appList.find(({ id: menuItemId }) => menuItemId === id)
if (app) {
this.$set(app, 'active', true)
} else {
logger.warn(`Could not find app "${id}" for setting navigation count`)
}
},

setApps({ apps }: { apps: INavigationEntry[]}) {
this.appList = apps
},
Expand Down
Loading