landing desktop
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
import { computed } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { useAuthStore } from '@/stores/auth';
|
||||
import { loginRouteWithRedirect } from '@/utils/auth-redirect';
|
||||
|
||||
export type LandingNavItem = {
|
||||
key: string;
|
||||
label: string;
|
||||
hash?: string;
|
||||
path?: string;
|
||||
requiresAuth?: boolean;
|
||||
};
|
||||
|
||||
export function useLandingNav() {
|
||||
const auth = useAuthStore();
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
|
||||
const items: LandingNavItem[] = [
|
||||
{ key: 'home', label: 'خانه', path: '/app' },
|
||||
{ key: 'services', label: 'خدمات', hash: '#services' },
|
||||
{ key: 'bookings', label: 'رزروها', path: '/app/bookings', requiresAuth: true },
|
||||
{ key: 'club', label: 'باشگاه مشتریان', hash: '#club' },
|
||||
{ key: 'about', label: 'درباره ما', hash: '#about' },
|
||||
{ key: 'contact', label: 'تماس با ما', hash: '#contact' },
|
||||
];
|
||||
|
||||
const navItems = computed(() => items);
|
||||
|
||||
function isActive(item: LandingNavItem): boolean {
|
||||
if (item.path === '/app' && !item.hash) {
|
||||
return route.path === '/app' && !route.hash;
|
||||
}
|
||||
if (item.hash) {
|
||||
return route.path === '/app' && route.hash === item.hash;
|
||||
}
|
||||
return route.path === item.path;
|
||||
}
|
||||
|
||||
function goTo(item: LandingNavItem) {
|
||||
if (item.requiresAuth && !auth.isLoggedIn) {
|
||||
void router.push(loginRouteWithRedirect(item.path ?? '/app/bookings'));
|
||||
return;
|
||||
}
|
||||
if (item.path && item.hash) {
|
||||
void router.push({ path: item.path, hash: item.hash.replace('#', '') });
|
||||
return;
|
||||
}
|
||||
if (item.path) {
|
||||
void router.push(item.path);
|
||||
return;
|
||||
}
|
||||
if (item.hash) {
|
||||
void router.push({ path: '/app', hash: item.hash.replace('#', '') });
|
||||
}
|
||||
}
|
||||
|
||||
return { navItems, isActive, goTo, auth, route, router };
|
||||
}
|
||||
Reference in New Issue
Block a user