refactor(navigation): consolidate navigation with href helpers and extract push device hook
- Migrate all navigation calls from magic strings to centralized href helpers - Extract inline device registration logic into useRegisterPushDevice hook - Remove unused terms and privacy policy routes from profile stack - Add hrefTradeDetail helper for trade detail navigation - Restore routePayloadCache.stashSystemMessage for group request/invite handling - Change desktop shell tab navigation from replace to push
This commit is contained in:
29
src/hooks/useRegisterPushDevice.ts
Normal file
29
src/hooks/useRegisterPushDevice.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { useEffect, useRef } from 'react';
|
||||
import { Platform } from 'react-native';
|
||||
|
||||
import { jpushService } from '../services/notification/jpushService';
|
||||
|
||||
export function useRegisterPushDevice(isAuthenticated: boolean, userID?: string) {
|
||||
const deviceRegistered = useRef(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (Platform.OS === 'web' || !isAuthenticated || !userID) return;
|
||||
|
||||
if (!deviceRegistered.current) {
|
||||
deviceRegistered.current = true;
|
||||
|
||||
jpushService.initialize().then((ok) => {
|
||||
if (ok && userID) {
|
||||
jpushService.setAliasForUser(userID);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return () => {
|
||||
if (!isAuthenticated) {
|
||||
deviceRegistered.current = false;
|
||||
jpushService.cleanup();
|
||||
}
|
||||
};
|
||||
}, [isAuthenticated, userID]);
|
||||
}
|
||||
Reference in New Issue
Block a user