refactor(routing): migrate to directory-based board routing

This commit is contained in:
plebeius
2025-11-07 12:50:58 +01:00
parent e7e2a2fda7
commit d78fed1fda
22 changed files with 332 additions and 163 deletions
+13 -6
View File
@@ -6,7 +6,8 @@ export const DISCLAIMER_ACCEPTED_KEY = '5chan-disclaimer-accepted';
interface DisclaimerModalState {
showModal: boolean;
targetAddress: string | null;
showDisclaimerModal: (address: string, navigate: NavigateFunction) => void;
targetBoardPath: string | null;
showDisclaimerModal: (address: string, navigate: NavigateFunction, boardPath?: string) => void;
closeDisclaimerModal: () => void;
acceptDisclaimer: (navigate: NavigateFunction) => void;
}
@@ -30,12 +31,14 @@ const setDisclaimerAccepted = (): void => {
const useDisclaimerModalStore = create<DisclaimerModalState>((set) => ({
showModal: false,
targetAddress: null,
targetBoardPath: null,
showDisclaimerModal: (address: string, navigate: NavigateFunction) => {
showDisclaimerModal: (address: string, navigate: NavigateFunction, boardPath?: string) => {
// Check if user has already accepted the disclaimer
if (hasAcceptedDisclaimer()) {
// Navigate directly without showing modal
navigate(`/p/${address}`);
const path = boardPath || address;
navigate(`/${path}`);
return;
}
@@ -43,6 +46,7 @@ const useDisclaimerModalStore = create<DisclaimerModalState>((set) => ({
set({
showModal: true,
targetAddress: address,
targetBoardPath: boardPath || null,
});
},
@@ -50,6 +54,7 @@ const useDisclaimerModalStore = create<DisclaimerModalState>((set) => ({
set({
showModal: false,
targetAddress: null,
targetBoardPath: null,
});
},
@@ -59,15 +64,17 @@ const useDisclaimerModalStore = create<DisclaimerModalState>((set) => ({
// Save acceptance to localStorage
setDisclaimerAccepted();
// Navigate to the target address
if (state.targetAddress) {
navigate(`/p/${state.targetAddress}`);
// Navigate to the target board path (or address if no path)
const path = state.targetBoardPath || state.targetAddress;
if (path) {
navigate(`/${path}`);
}
// Close the modal
set({
showModal: false,
targetAddress: null,
targetBoardPath: null,
});
},
}));