From 97f4bf6b2f1bca4b017f60db84a13cc2f60d8c13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Tue, 8 Oct 2024 13:13:04 +0100 Subject: [PATCH] fix: Restore loading bar and `FlowEditor` state on Editor-only routes (#3772) --- editor.planx.uk/src/routes/index.tsx | 74 ++++++++++++++++------------ 1 file changed, 42 insertions(+), 32 deletions(-) diff --git a/editor.planx.uk/src/routes/index.tsx b/editor.planx.uk/src/routes/index.tsx index c1cad20ee9..73c77abf78 100644 --- a/editor.planx.uk/src/routes/index.tsx +++ b/editor.planx.uk/src/routes/index.tsx @@ -57,38 +57,48 @@ const editorRoutes = mount({ ), }); -const mountPayRoutes = () => - map(async () => { - compose(withView(loadingView)); - return lazy(() => import("./pay")); - }); +const loadPayRoutes = () => + compose( + withView(loadingView), + lazy(() => import("./pay")), + ); -export default isPreviewOnlyDomain - ? compose( - withView(loadingView), +const loadPublishedRoutes = () => + compose( + withView(loadingView), + lazy(() => import("./published")), + ); + +const loadPreviewRoutes = () => + compose( + withView(loadingView), + lazy(() => import("./preview")), + ); - mount({ - "/:team/:flow/published": lazy(() => import("./published")), // XXX: keeps old URL working, but only for the team listed in the domain. - "/:flow": lazy(() => import("./published")), - "/:flow/pay": mountPayRoutes(), - // XXX: We're not sure where to redirect `/` to so for now we'll just return the default 404 - // "/": redirect("somewhere?"), - }), - ) - : compose( - withView(loadingView), +const loadDraftRoutes = () => + compose( + withView(loadingView), + lazy(() => import("./draft")), + ); - mount({ - "/:team/:flow/published": lazy(() => import("./published")), // loads current published flow if exists, or throws Not Found if unpublished - "/canterbury/find-out-if-you-need-planning-permission/preview": map( - async (req) => - redirect( - `/canterbury/find-out-if-you-need-planning-permission/published${req?.search}`, - ), - ), // temporary redirect while Canterbury works with internal IT to update advertised service links - "/:team/:flow/preview": lazy(() => import("./preview")), // loads current draft flow and latest published external portals, or throws Not Found if any external portal is unpublished - "/:team/:flow/draft": lazy(() => import("./draft")), // loads current draft flow and draft external portals - "/:team/:flow/pay": mountPayRoutes(), - "*": editorRoutes, - }), - ); +export default isPreviewOnlyDomain + ? mount({ + "/:team/:flow/published": loadPublishedRoutes(), // XXX: keeps old URL working, but only for the team listed in the domain. + "/:flow": loadPublishedRoutes(), + "/:flow/pay": loadPayRoutes(), + // XXX: We're not sure where to redirect `/` to so for now we'll just return the default 404 + // "/": redirect("somewhere?"), + }) + : mount({ + "/:team/:flow/published": loadPublishedRoutes(), // loads current published flow if exists, or throws Not Found if unpublished + "/canterbury/find-out-if-you-need-planning-permission/preview": map( + async (req) => + redirect( + `/canterbury/find-out-if-you-need-planning-permission/published${req?.search}`, + ), + ), // temporary redirect while Canterbury works with internal IT to update advertised service links + "/:team/:flow/preview": loadPreviewRoutes(), // loads current draft flow and latest published external portals, or throws Not Found if any external portal is unpublished + "/:team/:flow/draft": loadDraftRoutes(), // loads current draft flow and draft external portals + "/:team/:flow/pay": loadPayRoutes(), + "*": editorRoutes, + });