u
This commit is contained in:
@@ -10,7 +10,7 @@ import { Outlet, useLocation, useNavigate } from 'react-router-dom';
|
||||
import UserMenu from './UserMenu';
|
||||
import HelpBadge from './HelpBadge';
|
||||
import { NAV_ITEMS, SUB_NAV, resolveActiveNav, resolveActiveSub } from '../nav';
|
||||
import { artikelQueryPath } from './article/artikelQuery';
|
||||
import { artikelQueryPath, buildSearchUrl } from './article/artikelQuery';
|
||||
import { defaultCategoryPath } from './category/categoryRoute';
|
||||
import { navigationAutomat } from '../automats';
|
||||
import {
|
||||
@@ -31,6 +31,8 @@ class AppSidebar extends PureComponent {
|
||||
this.state = {
|
||||
lastDeliveryPath: navigationAutomat.state.lastDeliveryPath,
|
||||
lastArticleSku: navigationAutomat.state.lastArticleSku,
|
||||
lastArticleSearchPath: navigationAutomat.state.lastArticleSearchPath,
|
||||
lastSearchTerm: navigationAutomat.state.lastSearchTerm,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -38,6 +40,8 @@ class AppSidebar extends PureComponent {
|
||||
this.unsub = navigationAutomat.subscribe(this, (state) => ({
|
||||
lastDeliveryPath: state.lastDeliveryPath,
|
||||
lastArticleSku: state.lastArticleSku,
|
||||
lastArticleSearchPath: state.lastArticleSearchPath,
|
||||
lastSearchTerm: state.lastSearchTerm,
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -47,7 +51,12 @@ class AppSidebar extends PureComponent {
|
||||
|
||||
render() {
|
||||
const { activeNav, navigate } = this.props;
|
||||
const { lastDeliveryPath, lastArticleSku } = this.state;
|
||||
const {
|
||||
lastDeliveryPath,
|
||||
lastArticleSku,
|
||||
lastArticleSearchPath,
|
||||
lastSearchTerm,
|
||||
} = this.state;
|
||||
|
||||
return (
|
||||
<Box
|
||||
@@ -79,6 +88,10 @@ class AppSidebar extends PureComponent {
|
||||
if (path === '/artikel') {
|
||||
if (lastArticleSku) {
|
||||
navigate(`/artikel/${lastArticleSku}`);
|
||||
} else if (lastArticleSearchPath) {
|
||||
navigate(lastArticleSearchPath);
|
||||
} else if (lastSearchTerm) {
|
||||
navigate(buildSearchUrl(lastSearchTerm));
|
||||
} else {
|
||||
navigate(artikelQueryPath());
|
||||
}
|
||||
@@ -133,8 +146,37 @@ class AppSidebar extends PureComponent {
|
||||
}
|
||||
|
||||
class AppSubNav extends PureComponent {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
lastArticleSearchPath: navigationAutomat.state.lastArticleSearchPath,
|
||||
lastSearchTerm: navigationAutomat.state.lastSearchTerm,
|
||||
lastCategoryPath: navigationAutomat.state.lastCategoryPath,
|
||||
lastCategorySlug: navigationAutomat.state.lastCategorySlug,
|
||||
};
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.unsub = navigationAutomat.subscribe(this, (state) => ({
|
||||
lastArticleSearchPath: state.lastArticleSearchPath,
|
||||
lastSearchTerm: state.lastSearchTerm,
|
||||
lastCategoryPath: state.lastCategoryPath,
|
||||
lastCategorySlug: state.lastCategorySlug,
|
||||
}));
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
this.unsub?.();
|
||||
}
|
||||
|
||||
render() {
|
||||
const { activeNav, activeSub, navigate } = this.props;
|
||||
const {
|
||||
lastArticleSearchPath,
|
||||
lastSearchTerm,
|
||||
lastCategoryPath,
|
||||
lastCategorySlug,
|
||||
} = this.state;
|
||||
const subNav = activeNav ? SUB_NAV[activeNav] : null;
|
||||
|
||||
if (!subNav?.length) {
|
||||
@@ -178,11 +220,19 @@ class AppSubNav extends PureComponent {
|
||||
onMouseDown={(e) => e.preventDefault()}
|
||||
onClick={() => {
|
||||
if (!segment && activeNav === '/artikel') {
|
||||
navigate(artikelQueryPath());
|
||||
const target =
|
||||
lastArticleSearchPath ||
|
||||
(lastSearchTerm ? buildSearchUrl(lastSearchTerm) : null) ||
|
||||
artikelQueryPath();
|
||||
navigate(target);
|
||||
return;
|
||||
}
|
||||
if (segment === 'kategorien') {
|
||||
navigate(defaultCategoryPath());
|
||||
const target =
|
||||
lastCategoryPath ||
|
||||
(lastCategorySlug ? `/kategorien/${lastCategorySlug}` : null) ||
|
||||
defaultCategoryPath();
|
||||
navigate(target);
|
||||
return;
|
||||
}
|
||||
navigate(segment ? `${activeNav}/${segment}` : activeNav);
|
||||
|
||||
Reference in New Issue
Block a user