Files
AthenaFE/hooks/useDocumentTitle.ts
T
2025-11-05 20:11:34 +01:00

43 lines
1.2 KiB
TypeScript

import { usePathname } from "expo-router";
import { useEffect } from "react";
import { Platform } from "react-native";
export const useDocumentTitle = () => {
const pathname = usePathname();
const getSectionFromPath = (path: string): string => {
if (path.includes("/dashboard") || path === "/(tabs)" || path === "/") {
return "Dashboard";
} else if (path.includes("/accounts")) {
return "Accounts";
} else if (path.includes("/logs")) {
return "Logs";
} else if (path.includes("/reports")) {
return "Reports";
} else if (path.includes("/data-protection")) {
return "Data Protection";
} else if (path.includes("/settings")) {
return "Settings";
} else {
return "Bird Eye View";
}
};
const currentSection = getSectionFromPath(pathname);
useEffect(() => {
if (Platform.OS === "web") {
const isAuthRoute =
pathname.includes("/(auth)/") ||
pathname.includes("/sign-in") ||
pathname.includes("/forgot-password") ||
pathname.includes("/reset-password");
document.title = isAuthRoute
? "Bird Eye View"
: `Bird Eye View | ${currentSection}`;
}
}, [currentSection, pathname]);
return currentSection;
};