first implementation of tamagui mobile pages
This commit is contained in:
28
resources/js/admin/mobile/hooks/useAlertsBadge.ts
Normal file
28
resources/js/admin/mobile/hooks/useAlertsBadge.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import React from 'react';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useEventContext } from '../../context/EventContext';
|
||||
import { listGuestNotifications } from '../../api';
|
||||
|
||||
/**
|
||||
* Lightweight badge count for alerts tab.
|
||||
* Fetches guest notifications for the active event and returns count.
|
||||
*/
|
||||
export function useAlertsBadge() {
|
||||
const { activeEvent } = useEventContext();
|
||||
const slug = activeEvent?.slug;
|
||||
|
||||
const { data: count = 0 } = useQuery<number>({
|
||||
queryKey: ['mobile', 'alerts', 'badge', slug],
|
||||
enabled: Boolean(slug),
|
||||
staleTime: 60_000,
|
||||
queryFn: async () => {
|
||||
if (!slug) {
|
||||
return 0;
|
||||
}
|
||||
const alerts = await listGuestNotifications(slug);
|
||||
return Array.isArray(alerts) ? alerts.length : 0;
|
||||
},
|
||||
});
|
||||
|
||||
return React.useMemo(() => ({ count }), [count]);
|
||||
}
|
||||
38
resources/js/admin/mobile/hooks/useMobileNav.ts
Normal file
38
resources/js/admin/mobile/hooks/useMobileNav.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import React from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { adminPath } from '../../constants';
|
||||
import { useEventContext } from '../../context/EventContext';
|
||||
import { NavKey } from '../components/BottomNav';
|
||||
|
||||
export function useMobileNav(currentSlug?: string | null) {
|
||||
const navigate = useNavigate();
|
||||
const { activeEvent } = useEventContext();
|
||||
const slug = currentSlug ?? activeEvent?.slug ?? null;
|
||||
|
||||
const go = React.useCallback(
|
||||
(key: NavKey) => {
|
||||
if (key === 'events') {
|
||||
navigate(adminPath('/mobile/events'));
|
||||
return;
|
||||
}
|
||||
if (key === 'tasks') {
|
||||
if (slug) {
|
||||
navigate(adminPath(`/mobile/events/${slug}/tasks`));
|
||||
} else {
|
||||
navigate(adminPath('/mobile/events'));
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (key === 'alerts') {
|
||||
navigate(adminPath('/mobile/alerts'));
|
||||
return;
|
||||
}
|
||||
if (key === 'profile') {
|
||||
navigate(adminPath('/mobile/profile'));
|
||||
}
|
||||
},
|
||||
[navigate, slug]
|
||||
);
|
||||
|
||||
return { go, slug };
|
||||
}
|
||||
Reference in New Issue
Block a user