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

@@ -0,0 +1,54 @@
import { Automat } from 'react-automat';
/**
* Navigation automat to store last visited delivery and article paths.
* Used to return users to their previous context when clicking main menu items.
*
* State shape:
* {
* lastDeliveryPath: string | null, // Last visited delivery path (e.g., '/lieferung/19' or '/lieferung/neu')
* lastArticleSku: string | null, // Last visited article SKU
* }
*/
const initialState = {
lastDeliveryPath: null,
lastArticleSku: null,
};
const navigationAutomat = new Automat(
initialState,
{
/**
* Set the last visited delivery path.
* @param {string|null} path - Full path like '/lieferung/19' or '/lieferung/neu'
*/
setLastDeliveryPath(path) {
navigationAutomat.setState({ lastDeliveryPath: path });
},
/**
* Set the last visited article SKU.
* @param {string|null} sku
*/
setLastArticleSku(sku) {
navigationAutomat.setState({ lastArticleSku: sku });
},
/**
* Clear all navigation history.
*/
clearNavigation() {
navigationAutomat.setState({
lastDeliveryPath: null,
lastArticleSku: null,
});
},
},
{
name: 'navigation',
persist: false,
}
);
export default navigationAutomat;
export const { setLastDeliveryPath, setLastArticleSku, clearNavigation } = navigationAutomat.actions;