mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
moved some repeated code
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import { useNavigate, useLocation } from "react-router-dom";
|
||||
import useAppStore from "../useAppStore";
|
||||
|
||||
const useClickForm = () => {
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
const { setShowPostForm, setShowPostFormLink } = useAppStore.getState();
|
||||
|
||||
const handleClickForm = () => {
|
||||
setShowPostForm(true);
|
||||
setShowPostFormLink(false);
|
||||
|
||||
const subplebbitAddress = location.pathname.split("/")[1];
|
||||
const threadCid = location.pathname.split("/")[3];
|
||||
|
||||
if (location.pathname === "/") {
|
||||
navigate("/post");
|
||||
} else if (location.pathname.endsWith("/catalog")) {
|
||||
navigate(`/${subplebbitAddress}/catalog/post`);
|
||||
} else if (location.pathname.endsWith("/thread")) {
|
||||
navigate(`/${subplebbitAddress}/thread/post`);
|
||||
} else if (threadCid) {
|
||||
navigate(`/${subplebbitAddress}/thread/${threadCid}/post`);
|
||||
} else {
|
||||
navigate(`/${subplebbitAddress}/post`);
|
||||
}
|
||||
};
|
||||
|
||||
return handleClickForm;
|
||||
};
|
||||
|
||||
export default useClickForm;
|
||||
Reference in New Issue
Block a user