This commit is contained in:
seb
2026-09-19 18:33:27 +02:00
parent d3b4743b66
commit 4011ebfc61
13 changed files with 290 additions and 24 deletions

View File

@@ -11,13 +11,34 @@ import UserMenu from './UserMenu';
import { NAV_ITEMS, SUB_NAV, resolveActiveNav, resolveActiveSub } from '../nav';
import { artikelQueryPath } from '../pages/artikel/artikelQuery';
import { defaultCategoryPath } from '../pages/artikel/categoryRoute';
import { navigationAutomat } from '../automats';
const SIDEBAR_WIDTH = 144;
const SUB_NAV_WIDTH = 88;
class AppSidebar extends PureComponent {
constructor(props) {
super(props);
this.state = {
lastDeliveryPath: navigationAutomat.state.lastDeliveryPath,
lastArticleSku: navigationAutomat.state.lastArticleSku,
};
}
componentDidMount() {
this.unsub = navigationAutomat.subscribe(this, (state) => ({
lastDeliveryPath: state.lastDeliveryPath,
lastArticleSku: state.lastArticleSku,
}));
}
componentWillUnmount() {
this.unsub?.();
}
render() {
const { activeNav, navigate } = this.props;
const { lastDeliveryPath, lastArticleSku } = this.state;
return (
<Box
@@ -45,7 +66,21 @@ class AppSidebar extends PureComponent {
selected={active}
onMouseDown={(e) => e.preventDefault()}
onClick={() => {
navigate(path === '/artikel' ? artikelQueryPath() : path);
if (path === '/artikel') {
if (lastArticleSku) {
navigate(`/artikel/${lastArticleSku}`);
} else {
navigate(artikelQueryPath());
}
} else if (path === '/lieferung') {
if (lastDeliveryPath) {
navigate(lastDeliveryPath);
} else {
navigate(path);
}
} else {
navigate(path);
}
}}
sx={(theme) => ({
borderRadius: 0,

View File

@@ -6,6 +6,7 @@ import {
buildCategoryPath,
defaultCategoryPath,
} from '../../pages/artikel/categoryRoute';
import articleAutomat, { createArticleSelector } from '../../store/articleAutomat';
import ArticleTileTab from './ArticleTileTab';
import ArticlePhotoTile from './ArticlePhotoTile';
@@ -24,34 +25,52 @@ class ArticleView extends PureComponent {
constructor(props, context) {
super(props, context);
const { article, unwatch } = context.article.watch(
props.sku,
(next) => {
this.setState({ article: next });
},
);
this.state = { article };
this.unwatchArticle = unwatch;
const sku = props.sku;
const currentArticle = articleAutomat.state[sku] ?? null;
this.state = { article: currentArticle };
this.handleArticleDeleted = this.handleArticleDeleted.bind(this);
}
componentDidUpdate(prevProps) {
const { sku } = this.props;
if (prevProps.sku !== sku) {
this.unwatchArticle?.();
const { article: next, unwatch } = this.context.article.watch(
sku,
(updated) => this.setState({ article: updated }),
);
this.unwatchArticle = unwatch;
this.setState({ article: next });
if (!currentArticle) {
articleAutomat.actions.loadArticle(sku).catch((err) => {
console.error('Failed to load article:', err);
});
}
}
componentDidMount() {
this.subscribeToArticle();
}
componentDidUpdate(prevProps) {
if (prevProps.sku !== this.props.sku) {
const currentArticle = articleAutomat.state[this.props.sku] ?? null;
this.setState({ article: currentArticle });
if (!currentArticle) {
articleAutomat.actions.loadArticle(this.props.sku).catch((err) => {
console.error('Failed to load article:', err);
});
}
this.subscribeToArticle();
}
}
subscribeToArticle() {
if (this.unsub) this.unsub();
const selector = createArticleSelector(this.props.sku);
this.unsub = articleAutomat.subscribe(this, (state) => ({
article: selector(state),
}));
}
componentWillUnmount() {
this.unwatchArticle?.();
this.unwatchArticle = null;
if (this.unsub) {
this.unsub();
this.unsub = null;
}
}
handleArticleDeleted() {