fixed redirect after action
This commit is contained in:
parent
ba7bdd2726
commit
70d1f786d9
7 changed files with 15 additions and 19 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
import { useState } from "preact/hooks";
|
import { useState } from "preact/hooks";
|
||||||
import { api } from "../lib/api";
|
import { api } from "../lib/api";
|
||||||
import { navigateBackAndReload, logout } from "./Util";
|
import { navigateBack, logout } from "./Util";
|
||||||
import type { JSX } from "preact/jsx-runtime";
|
import type { JSX } from "preact/jsx-runtime";
|
||||||
|
|
||||||
export default function DeleteUser() {
|
export default function DeleteUser() {
|
||||||
|
|
@ -20,7 +20,7 @@ export default function DeleteUser() {
|
||||||
} finally {
|
} finally {
|
||||||
if (!hasError) {
|
if (!hasError) {
|
||||||
logout()
|
logout()
|
||||||
navigateBackAndReload()
|
navigateBack()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { useEffect, useState } from 'preact/hooks';
|
import { useEffect, useState } from 'preact/hooks';
|
||||||
import { api, AUTH_TOKEN_KEY } from '../lib/api';
|
import { api, AUTH_TOKEN_KEY } from '../lib/api';
|
||||||
import { getUser, navigateBackAndReload, navigatePathAndReload, saveUser } from './Util';
|
import { navigateBack, navigatePath, saveUser } from './Util';
|
||||||
|
|
||||||
export default function LoginForm() {
|
export default function LoginForm() {
|
||||||
const [userCode, setUserCode] = useState('');
|
const [userCode, setUserCode] = useState('');
|
||||||
|
|
@ -33,7 +33,7 @@ export default function LoginForm() {
|
||||||
}
|
}
|
||||||
hasError = true
|
hasError = true
|
||||||
} finally {
|
} finally {
|
||||||
if (!hasError) navigateBackAndReload()
|
if (!hasError) navigatePath("/")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
import { navigateBackAndReload } from "./Util";
|
import { navigateBack } from "./Util";
|
||||||
|
|
||||||
export default function NavBack() {
|
export default function NavBack() {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<button class="back-btn" onClick={navigateBackAndReload}>Zurück</button>
|
<button class="back-btn" onClick={navigateBack}>Zurück</button>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { useEffect, useState } from 'preact/hooks';
|
import { useEffect, useState } from 'preact/hooks';
|
||||||
import { api, type User } from '../lib/api';
|
import { api, type User } from '../lib/api';
|
||||||
import React from 'preact/compat';
|
import React from 'preact/compat';
|
||||||
import { navigateBackAndReload, isEmailValid } from './Util';
|
import { navigateBack, isEmailValid } from './Util';
|
||||||
|
|
||||||
export default function RegisterForm() {
|
export default function RegisterForm() {
|
||||||
const [user, setUser] = React.useState<User>({ 'email': '', 'name': '', 'subscription': true });
|
const [user, setUser] = React.useState<User>({ 'email': '', 'name': '', 'subscription': true });
|
||||||
|
|
@ -31,7 +31,7 @@ export default function RegisterForm() {
|
||||||
}
|
}
|
||||||
hasError = true
|
hasError = true
|
||||||
} finally {
|
} finally {
|
||||||
if (!hasError) navigateBackAndReload()
|
if (!hasError) navigateBack()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { useEffect, useState } from 'preact/hooks';
|
import { useEffect, useState } from 'preact/hooks';
|
||||||
import { api, type User } from '../lib/api';
|
import { api, type User } from '../lib/api';
|
||||||
import React from 'preact/compat';
|
import React from 'preact/compat';
|
||||||
import { getUser, navigateBackAndReload, navigatePathAndReload, saveUser } from './Util';
|
import { getUser, navigateBack, navigatePath, saveUser } from './Util';
|
||||||
|
|
||||||
export default function ToggleSubscription() {
|
export default function ToggleSubscription() {
|
||||||
const [subscription, setSubscription] = React.useState<boolean>(false);
|
const [subscription, setSubscription] = React.useState<boolean>(false);
|
||||||
|
|
@ -10,7 +10,7 @@ export default function ToggleSubscription() {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
user = getUser()
|
user = getUser()
|
||||||
if (!user) navigatePathAndReload("/login")
|
if (!user) navigatePath("/login")
|
||||||
else setSubscription(user.subscription)
|
else setSubscription(user.subscription)
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|
@ -28,7 +28,7 @@ export default function ToggleSubscription() {
|
||||||
if (user) {
|
if (user) {
|
||||||
user = {...user, subscription: false }
|
user = {...user, subscription: false }
|
||||||
saveUser(user)
|
saveUser(user)
|
||||||
navigateBackAndReload()
|
navigateBack()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,18 +42,14 @@ export function isTokenExpired(token: string): boolean {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const navigateBackAndReload = () => {
|
export const navigateBack = () => {
|
||||||
console.log(document.referrer);
|
|
||||||
// TODO: funzt nicht immer!
|
|
||||||
if (document.referrer) {
|
if (document.referrer) {
|
||||||
navigate(document.referrer, { history: 'replace' });
|
navigate(document.referrer, { history: 'replace' })
|
||||||
setTimeout(() => window.location.reload(), 50);
|
|
||||||
} else {
|
} else {
|
||||||
navigate('/');
|
navigate('/');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const navigatePathAndReload = (path: string) => {
|
export const navigatePath = (path: string) => {
|
||||||
navigate(path, { history: 'replace' });
|
navigate(path, { history: 'replace' });
|
||||||
setTimeout(() => window.location.reload(), 50);
|
|
||||||
}
|
}
|
||||||
|
|
@ -9,7 +9,7 @@ image:
|
||||||
author: Tim
|
author: Tim
|
||||||
date: 2026-10-09
|
date: 2026-10-09
|
||||||
slug: bootssuche-travemünde
|
slug: bootssuche-travemünde
|
||||||
time2read: 0
|
time2read: 5
|
||||||
---
|
---
|
||||||
import BlogLink from '../../components/blog/BlogLink.astro'
|
import BlogLink from '../../components/blog/BlogLink.astro'
|
||||||
import SingleImage from '../../components/blog/SingleImage.astro'
|
import SingleImage from '../../components/blog/SingleImage.astro'
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue