diff --git a/src/blog/Blog.tsx b/src/blog/Blog.tsx
index 13f00d7..9f0668d 100644
--- a/src/blog/Blog.tsx
+++ b/src/blog/Blog.tsx
@@ -67,6 +67,7 @@ export default function Blog(props: { disableCustomTheme?: boolean }) {
type ViewComponentEntry
= {
component: React.ComponentType
;
extraProps?: (ctx: RouterContext) => Partial
;
+ navigationMap?: Record;
};
const VIEW_COMPONENTS: Record> = {
@@ -76,6 +77,9 @@ export default function Blog(props: { disableCustomTheme?: boolean }) {
login: {
component: Login,
+ navigationMap: {
+ open_register: 'onRegister',
+ },
},
register: {
@@ -88,6 +92,9 @@ export default function Blog(props: { disableCustomTheme?: boolean }) {
article: {
component: ArticleView,
+ navigationMap: {
+ open_editor: 'onEdit',
+ },
extraProps: ({ ui, articles }) => ({
article: articles[ui.selectedArticle!],
}) satisfies Partial,
@@ -110,9 +117,13 @@ export default function Blog(props: { disableCustomTheme?: boolean }) {
const renderView = () => {
const entry = VIEW_COMPONENTS[ui.view];
+ const navigationMap= entry['navigationMap'] || {}
const ViewComponent = entry.component;
- const childNav = navigateToChildren(ui.view);
+ const childNav = navigateToChildren(
+ ui.view,
+ navigationMap
+ );
const ctx: RouterContext = {
ui,
diff --git a/src/blog/components/Article/ArticleView.tsx b/src/blog/components/Article/ArticleView.tsx
index 47b2a24..d7f5973 100644
--- a/src/blog/components/Article/ArticleView.tsx
+++ b/src/blog/components/Article/ArticleView.tsx
@@ -28,11 +28,10 @@ const CoverImage = styled('img')({
export default function ArticleView({
article,
onBack,
- open_editor,
+ onEdit,
}: ArticleViewProps) {
const { currentUser } = useAuth();
- const onEdit = open_editor;
return (
diff --git a/src/blog/components/Register.tsx b/src/blog/components/Register.tsx
index 58d9a5d..22ebe72 100644
--- a/src/blog/components/Register.tsx
+++ b/src/blog/components/Register.tsx
@@ -13,7 +13,7 @@ export default function Register({
const [password2, setPassword2] = React.useState('');
const [localError, setLocalError] = React.useState(null);
- const handleSubmit = async (e: React.FormEvent) => {
+ const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
setLocalError(null);
diff --git a/src/blog/types/props.ts b/src/blog/types/props.ts
index 549cccb..bbcf63e 100644
--- a/src/blog/types/props.ts
+++ b/src/blog/types/props.ts
@@ -27,7 +27,7 @@ export interface RegisterProps {
export interface ArticleViewProps {
article: ArticleModel;
onBack: () => void;
- open_editor: () => void;
+ onEdit: () => void;
}
export interface ArticleEditorProps {
diff --git a/src/blog/types/views.ts b/src/blog/types/views.ts
index b36c3de..ded0e8c 100644
--- a/src/blog/types/views.ts
+++ b/src/blog/types/views.ts
@@ -57,12 +57,18 @@ export function useViewRouter(setUI: any) {
};
// auto child navigators from children[]
- const navigateToChildren = (view: View) => {
+ const navigateToChildren = (
+ view: View,
+ navigationMap?: Record,
+ ) => {
const node = VIEW_TREE[view];
const funcs: Record void> = {};
node.children?.forEach((child) => {
- funcs[`open_${child}`] = () => navigate(child);
+ const funcName = `open_${child}`;
+ const customFuncName = navigationMap?.[funcName];
+ funcs[funcName] = () => navigate(child);
+ if (customFuncName) funcs[customFuncName] = () => navigate(child);
});
return funcs;