Skip to content

Commit 87260a5

Browse files
authored
Merge pull request #784 from Path-of-Modifiers/783-fix-url-load-input-store-after-captcha
#777 frontend: Redirect now works after captcha
2 parents dbf35c2 + af6bda7 commit 87260a5

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/frontend/src/routes/_layout.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,19 @@ import { Outlet, createFileRoute, redirect } from "@tanstack/react-router";
44
import useTurnstileValidation, {
55
hasCompletedCaptcha,
66
} from "../hooks/validation/turnstileValidation";
7+
import { useGraphInputStore } from "../store/GraphInputStore";
78

89
const security_ip = localStorage.getItem("security_ip");
910

1011
export const Route = createFileRoute("/_layout")({
1112
component: Layout,
1213
beforeLoad: async () => {
14+
try {
15+
const searchParams = new URLSearchParams(location.hash.slice(1));
16+
useGraphInputStore.getState().getStoreFromHash(searchParams);
17+
} catch (error) {
18+
console.log("Coulnd't get url hash to store properly")
19+
}
1320
if (!hasCompletedCaptcha()) {
1421
throw redirect({
1522
to: "/captcha",

src/frontend/src/utils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,18 @@ const validateLeagues = (searchParams: URLSearchParams) => {
9797
};
9898

9999
export const validateAndSetSearchParams = (searchParams: URLSearchParams) => {
100+
const graphState = useGraphInputStore.getState();
100101
try {
102+
graphState.setHashFromStore();
101103
validateLeagues(searchParams);
102104
} catch (error) {
103105
const graphState = useGraphInputStore.getState();
104106
graphState.removeAllLeagues();
105107
graphState.addLeague(DEFAULT_LEAGUES[0]);
106108
const searchParams = new URLSearchParams();
107109
searchParams.set("league", DEFAULT_LEAGUES[0]);
108-
location.hash = searchParams.toString();
110+
graphState.setHashFromStore();
111+
} finally {
112+
graphState.setStateHash(undefined);
109113
}
110114
};

0 commit comments

Comments
 (0)