return url factory function for useAccountsUrl

This commit is contained in:
Karol Wypchlo 2022-02-02 19:05:30 +01:00
parent 75e7844c9d
commit e2dfc8a36f
No known key found for this signature in database
GPG Key ID: B515DE9EEBE241E1
3 changed files with 9 additions and 8 deletions

View File

@ -26,7 +26,7 @@ const Navigation = ({ mode, uri }) => {
const windowSize = useWindowSize(); const windowSize = useWindowSize();
const isWindowTop = useWindowTop(); const isWindowTop = useWindowTop();
const { data: accounts } = useAccounts(); const { data: accounts } = useAccounts();
const accountsUrl = useAccountsUrl(); const createAccountsUrl = useAccountsUrl();
React.useEffect(() => { React.useEffect(() => {
setOpen(false); setOpen(false);
@ -90,11 +90,11 @@ const Navigation = ({ mode, uri }) => {
{showLoginNavigation && ( {showLoginNavigation && (
<> <>
<Link href={`${accountsUrl}auth/login`} className="button-link-primary"> <Link href={createAccountsUrl("/auth/login")} className="button-link-primary">
Log in Log in
</Link> </Link>
<Link href={`${accountsUrl}auth/registration`} className="button-primary"> <Link href={createAccountsUrl("/auth/registration")} className="button-primary">
Sign up Sign up
</Link> </Link>
</> </>

View File

@ -22,11 +22,11 @@ const getRootDirectory = (file) => {
}; };
const RegistrationLink = () => { const RegistrationLink = () => {
const accountsUrl = useAccountsUrl(); const createAccountsUrl = useAccountsUrl();
return ( return (
<Link <Link
href={`${accountsUrl}auth/registration`} href={createAccountsUrl("auth/registration")}
className="uppercase underline-primary hover:text-primary transition-colors duration-200" className="uppercase underline-primary hover:text-primary transition-colors duration-200"
> >
Sign up Sign up
@ -35,11 +35,11 @@ const RegistrationLink = () => {
}; };
const LogInLink = () => { const LogInLink = () => {
const accountsUrl = useAccountsUrl(); const createAccountsUrl = useAccountsUrl();
return ( return (
<Link <Link
href={`${accountsUrl}auth/login`} href={createAccountsUrl("auth/login")}
className="uppercase underline-primary hover:text-primary transition-colors duration-200" className="uppercase underline-primary hover:text-primary transition-colors duration-200"
> >
Log in Log in

View File

@ -3,6 +3,7 @@ import skynetClient from "./skynetClient";
export default function useAccountsUrl() { export default function useAccountsUrl() {
const [url, setUrl] = React.useState(""); const [url, setUrl] = React.useState("");
const createAccountsUrl = React.useCallback((path = "") => new URL(path, url).toString(), [url]);
React.useEffect(() => { React.useEffect(() => {
(async function resolve() { (async function resolve() {
@ -14,5 +15,5 @@ export default function useAccountsUrl() {
})(); })();
}, [setUrl]); }, [setUrl]);
return url; return createAccountsUrl;
} }