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