-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* add a button * remove button * delete mode * del mode * fixed routes * fix logo missing at /editor/command * extract routing logic to a hook --------- Co-authored-by: madmaxieee <[email protected]>
- Loading branch information
1 parent
94704f1
commit e84fdfe
Showing
11 changed files
with
3,031 additions
and
231 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { useCallback, useMemo } from "react"; | ||
|
||
import { useNavigate, useLocation } from "react-router-dom"; | ||
|
||
import { ROUTES } from "@/constants"; | ||
|
||
export type PageName = keyof typeof ROUTES | "UNKNOWN"; | ||
|
||
export default function useRoute() { | ||
const location = useLocation(); | ||
const navigate = useNavigate(); | ||
|
||
const page: PageName = useMemo(() => { | ||
const path = location.pathname; | ||
if (path === ROUTES.EDITOR) { | ||
return "EDITOR"; | ||
} else if (path === ROUTES.COMMAND_CENTER) { | ||
return "COMMAND_CENTER"; | ||
} else if (path === ROUTES.LOGIN) { | ||
return "LOGIN"; | ||
} else if (path === ROUTES.ROOT) { | ||
return "ROOT"; | ||
} else { | ||
return "UNKNOWN"; | ||
} | ||
}, [location.pathname]); | ||
|
||
const toEditor = useCallback(() => { | ||
navigate(ROUTES.EDITOR); | ||
}, [navigate]); | ||
|
||
const toCommandCenter = useCallback(() => { | ||
navigate(ROUTES.COMMAND_CENTER); | ||
}, [navigate]); | ||
|
||
const toLogin = useCallback(() => { | ||
navigate(ROUTES.LOGIN); | ||
}, [navigate]); | ||
|
||
return { | ||
location, | ||
page, | ||
navigate: { toEditor, toCommandCenter, toLogin }, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.