forked from processing/p5.js-web-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuseWhatPage.js
31 lines (26 loc) · 1021 Bytes
/
useWhatPage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { useMemo } from 'react';
import { useSelector } from 'react-redux';
import { useLocation } from 'react-router-dom';
/**
*
* @returns {"home" | "myStuff" | "login" | "signup" | "account" | "examples"}
*/
const useWhatPage = () => {
const username = useSelector((state) => state.user.username);
const project = useSelector((state) => state.project);
const { pathname } = useLocation();
const pageName = useMemo(() => {
const myStuffPattern = new RegExp(
`(/${username}/(sketches/?$|collections|assets)/?)`
);
if (myStuffPattern.test(pathname)) return 'My Stuff';
else if (pathname === '/login') return 'LoginView.Login';
else if (pathname === '/signup') return 'LoginView.SignUp';
else if (pathname === '/account') return 'AccountView.Settings';
else if (pathname === '/p5/collections' || pathname === '/p5/sketches')
return 'Nav.File.Examples';
return project.name || 'home';
}, [pathname, username]);
return pageName;
};
export default useWhatPage;