Performer/Studio/Tag/Gallery Create compnent has default name as search query (#2701)

* feat: Closes #2618
fix: New button is now available even if pathname ends with '/'
This commit is contained in:
TgSeed
2022-09-16 01:05:33 +00:00
committed by GitHub
parent 781a767fb6
commit 593477cbe1
8 changed files with 70 additions and 20 deletions

View File

@@ -217,8 +217,14 @@ export const MainNavbar: React.FC = () => {
[history]
);
const { pathname } = location;
const newPath = newPathsList.includes(pathname) ? `${pathname}/new` : null;
const pathname = location.pathname.replace(/\/$/, "");
let newPath = newPathsList.includes(pathname) ? `${pathname}/new` : null;
if (newPath != null) {
let queryParam = new URLSearchParams(location.search).get("q");
if (queryParam != null) {
newPath += "?name=" + encodeURIComponent(queryParam);
}
}
// set up hotkeys
useEffect(() => {
@@ -230,7 +236,7 @@ export const MainNavbar: React.FC = () => {
);
if (newPath) {
Mousetrap.bind("n", () => history.push(newPath));
Mousetrap.bind("n", () => history.push(String(newPath)));
}
return () => {