|
|
@@ -3,6 +3,7 @@ import { useState, useEffect, useCallback } from "react";
|
|
|
export type HashRoute =
|
|
|
| { page: "dashboard" }
|
|
|
| { page: "book"; bookId: string }
|
|
|
+ | { page: "book-settings"; bookId: string }
|
|
|
| { page: "book-create" }
|
|
|
| { page: "services" }
|
|
|
| { page: "service-detail"; serviceId: string }
|
|
|
@@ -27,6 +28,9 @@ function parseHash(hash: string): HashRoute {
|
|
|
const serviceMatch = path.match(/^services\/([^/]+)$/);
|
|
|
if (serviceMatch) return { page: "service-detail", serviceId: decodeURIComponent(serviceMatch[1]) };
|
|
|
|
|
|
+ const bookSettingsMatch = path.match(/^book\/([^/]+)\/settings$/);
|
|
|
+ if (bookSettingsMatch) return { page: "book-settings", bookId: decodeURIComponent(bookSettingsMatch[1]) };
|
|
|
+
|
|
|
const bookMatch = path.match(/^book\/([^/]+)$/);
|
|
|
if (bookMatch) return { page: "book", bookId: decodeURIComponent(bookMatch[1]) };
|
|
|
|
|
|
@@ -37,6 +41,7 @@ function routeToHash(route: HashRoute): string {
|
|
|
switch (route.page) {
|
|
|
case "dashboard": return "#/";
|
|
|
case "book": return `#/book/${encodeURIComponent(route.bookId)}`;
|
|
|
+ case "book-settings": return `#/book/${encodeURIComponent(route.bookId)}/settings`;
|
|
|
case "book-create": return "#/book/new";
|
|
|
case "services": return "#/services";
|
|
|
case "service-detail": return `#/services/${encodeURIComponent(route.serviceId)}`;
|
|
|
@@ -46,7 +51,7 @@ function routeToHash(route: HashRoute): string {
|
|
|
|
|
|
export { parseHash, routeToHash }; // for testing
|
|
|
|
|
|
-const HASH_PAGES = new Set(["dashboard", "book", "book-create", "services", "service-detail"]);
|
|
|
+const HASH_PAGES = new Set(["dashboard", "book", "book-settings", "book-create", "services", "service-detail"]);
|
|
|
|
|
|
export function useHashRoute() {
|
|
|
const [route, setRouteState] = useState<HashRoute>(() => parseHash(window.location.hash));
|