nav
This commit is contained in:
54
src/automats/navigationAutomat.js
Normal file
54
src/automats/navigationAutomat.js
Normal 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;
|
||||
Reference in New Issue
Block a user