automat
This commit is contained in:
@@ -1,26 +1,31 @@
|
||||
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
|
||||
* }
|
||||
* @typedef {Object} NavigationState
|
||||
* @property {string|null} lastDeliveryPath Last delivery path visited by the user.
|
||||
* @property {string|null} lastArticleSku Last article SKU visited by the user.
|
||||
*/
|
||||
|
||||
/** @type {NavigationState} */
|
||||
const initialState = {
|
||||
lastDeliveryPath: null,
|
||||
lastArticleSku: null,
|
||||
};
|
||||
|
||||
/**
|
||||
* Stores the user's most recently visited delivery and article so main-menu
|
||||
* navigation can restore the previous context.
|
||||
*
|
||||
* @type {Automat<NavigationState>}
|
||||
*/
|
||||
const navigationAutomat = new Automat(
|
||||
initialState,
|
||||
{
|
||||
/**
|
||||
* Set the last visited delivery path.
|
||||
* @param {string|null} path - Full path like '/lieferung/19' or '/lieferung/neu'
|
||||
*
|
||||
* @param {string|null} path Full path such as `/lieferung/19` or `/lieferung/neu`.
|
||||
* @returns {void}
|
||||
*/
|
||||
setLastDeliveryPath(path) {
|
||||
navigationAutomat.setState({ lastDeliveryPath: path });
|
||||
@@ -28,7 +33,9 @@ const navigationAutomat = new Automat(
|
||||
|
||||
/**
|
||||
* Set the last visited article SKU.
|
||||
*
|
||||
* @param {string|null} sku
|
||||
* @returns {void}
|
||||
*/
|
||||
setLastArticleSku(sku) {
|
||||
navigationAutomat.setState({ lastArticleSku: sku });
|
||||
@@ -36,6 +43,8 @@ const navigationAutomat = new Automat(
|
||||
|
||||
/**
|
||||
* Clear all navigation history.
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
clearNavigation() {
|
||||
navigationAutomat.setState({
|
||||
|
||||
Reference in New Issue
Block a user