Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions src/frontend/src/routes/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import useTurnstileValidation, {
hasCompletedCaptcha,
} from "../hooks/validation/turnstileValidation";

import { useGraphInputStore } from "../store/GraphInputStore";

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

export const Route = createFileRoute("/_layout")({
Expand All @@ -17,14 +15,6 @@ export const Route = createFileRoute("/_layout")({
to: "/captcha",
});
}
try {
const searchParams = new URLSearchParams(location.hash.slice(1));
useGraphInputStore.getState().getStoreFromHash(searchParams);
} catch (err) {
throw redirect({
to: "/"
})
}
},
});

Expand Down
10 changes: 2 additions & 8 deletions src/frontend/src/routes/_layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,12 @@ import { MainPage } from '../../components/Common/MainPage'
import { useGraphInputStore } from '../../store/GraphInputStore'
import { useGetGroupedModifiers } from '../../hooks/getData/prefetchGroupedModifiers'
import { useGetItemBaseTypes } from '../../hooks/getData/getBaseTypeCategories'
import { validateAndSetSearchParams } from '../../utils'

export const Route = createFileRoute("/_layout/")({
beforeLoad: async () => {
const searchParams = new URLSearchParams(location.hash.slice(1))
const state = useGraphInputStore.getState()
if (searchParams.size > 0) {
state.getStoreFromHash(searchParams)
} else {
// This happens when being redirected from login
state.setHashFromStore()
state.setStateHash(undefined)
}
validateAndSetSearchParams(searchParams)
},
component: Index,
})
Expand Down
4 changes: 4 additions & 0 deletions src/frontend/src/store/GraphInputStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ export const useGraphInputStore = create<GraphInputState>((set) => ({
[] as string[])
]
})),
removeAllLeagues: () =>
set(() => ({
leagues: []
})),

setItemSpec: (itemSpec: ItemSpecState) => set(() => ({ itemSpec: itemSpec })),

Expand Down
1 change: 1 addition & 0 deletions src/frontend/src/store/StateInterface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export interface GraphInputState {

addLeague: (league: string) => void;
removeLeague: (league: string) => void;
removeAllLeagues: () => void;


setItemName: (name: string | undefined) => void;
Expand Down
26 changes: 26 additions & 0 deletions src/frontend/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { ApiError } from "./client";
import { Toast } from "./hooks/useCustomToast";
import { DEFAULT_LEAGUES } from "./config";
import { useGraphInputStore } from "./store/GraphInputStore";

export const emailPattern = {
value: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i,
Expand Down Expand Up @@ -82,3 +84,27 @@ export const setupHourlyUpdate = (setCurrentTime: SetDateFunction) => {

return () => clearTimeout(timeoutId);
};

const validateLeagues = (searchParams: URLSearchParams) => {
const leagues = searchParams.get("league");
if (searchParams.size === 1 && leagues) {
if (leagues.length > 1 || !leagues.includes(DEFAULT_LEAGUES[0])) {
throw "default league not in simple url";
}
} else if (!leagues || leagues.length === 0) {
throw "leagues not set in url";
}
};

export const validateAndSetSearchParams = (searchParams: URLSearchParams) => {
try {
validateLeagues(searchParams);
} catch (error) {
const graphState = useGraphInputStore.getState();
graphState.removeAllLeagues();
graphState.addLeague(DEFAULT_LEAGUES[0]);
const searchParams = new URLSearchParams();
searchParams.set("league", DEFAULT_LEAGUES[0]);
location.hash = searchParams.toString();
}
};
Loading