Skip to content
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
28 changes: 14 additions & 14 deletions desk/src/components/layouts/AppSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
:id="item.id"
:label="__(item.label)"
:active="item.isActive"
:to="item.to"
:class="item.spacedTop && 'mt-4'"
@click="item.onClick && item.onClick()"
>
Expand Down Expand Up @@ -127,8 +128,7 @@ import {
} from "frappe-ui";
import { storeToRefs } from "pinia";
import { computed, ref, watch } from "vue";
import type { RouteLocationRaw } from "vue-router";
import { useRoute, useRouter } from "vue-router";
import { useRoute } from "vue-router";
import LucideBell from "~icons/lucide/bell";
import LucideSearch from "~icons/lucide/search";
import {
Expand All @@ -142,7 +142,6 @@ const props = defineProps<{
}>();

const route = useRoute();
const router = useRouter();
const device = useDevice();
const notificationStore = useNotificationStore();
const sidebarStore = useSidebarStore();
Expand Down Expand Up @@ -188,10 +187,12 @@ function currentRouteKey(): string | null {
return (route.query.view as string) || (route.name as string) || null;
}

function selectItem(key: string, to: RouteLocationRaw, onSelect?: () => void) {
// Items that carry a `to` are rendered as real links by SidebarItem, so the
// router handles navigation. This only keeps the side effects: highlight the
// item immediately (before the route settles) and let callers hook in.
function selectItem(key: string, onSelect?: () => void) {
activeItem.value = key;
onSelect?.();
router.push(to);
}

const navItems = computed(() => {
Expand All @@ -204,7 +205,8 @@ const navItems = computed(() => {
label: option.label,
icon: option.icon,
isActive: activeItem.value === option.to,
onClick: () => selectItem(option.to, { name: option.to }),
to: { name: option.to },
onClick: () => selectItem(option.to),
// Separate the nav group from the search/notification tools above it.
spacedTop: index === 0 && !isCustomerPortal.value,
key: option.label,
Expand All @@ -227,7 +229,8 @@ const notificationItem = computed(() =>
label: __("Notifications"),
icon: LucideBell,
isActive: activeItem.value === "Notifications",
onClick: () => selectItem("Notifications", { name: "Notifications" }),
to: { name: "Notifications" },
onClick: () => selectItem("Notifications"),
badge: notificationStore.unread,
key: "notifications",
id: "notifications-btn",
Expand Down Expand Up @@ -274,14 +277,11 @@ function parseViews(views: any[]) {
label: view.label,
icon: getIcon(view.icon),
isActive: activeItem.value === view.name,
to: { name: view.route_name, query: { view: view.name } },
onClick: () =>
selectItem(
view.name,
{ name: view.route_name, query: { view: view.name } },
() => {
currentView.value = { label: view.label, icon: view.icon };
}
),
selectItem(view.name, () => {
currentView.value = { label: view.label, icon: view.icon };
}),
key: view.name,
view,
}));
Expand Down