UNPKG

@open-tender/store

Version:

A library of hooks, reducers, utility functions, and types for use with Open Tender applications that utilize our in-store POS API

50 lines (49 loc) 2.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var ui_1 = require("@open-tender/ui"); var react_1 = require("react"); var hooks_1 = require("../app/hooks"); var slices_1 = require("../slices"); var CategoryNavOther = function (_a) { var title = _a.title, path = _a.path, displayImage = _a.displayImage, navigationType = _a.navigationType, navigate = _a.navigate, children = _a.children; var dispatch = (0, hooks_1.useAppDispatch)(); var apiUrl = (0, hooks_1.useAppSelector)(slices_1.selectKioskApi); var _b = (0, hooks_1.useAppSelector)(slices_1.selectKioskConfig), categoryNavItem = _b.categoryNavItem, categoryNavItemSelected = _b.categoryNavItemSelected; var currentSection = (0, hooks_1.useAppSelector)(slices_1.selectCurrentSection); var isCurrent = path === currentSection; var config = isCurrent ? categoryNavItemSelected : categoryNavItem; var _c = (0, hooks_1.useAppSelector)(slices_1.selectMenu), _d = _c.featured, featured = _d === void 0 ? [] : _d, _e = _c.favorites, favorites = _e === void 0 ? [] : _e, _f = _c.recents, recents = _f === void 0 ? [] : _f; var getCategoryItemImage = (0, react_1.useCallback)(function () { switch (title.toLowerCase()) { case 'featured': return featured.length && featured.length > 0 ? (0, ui_1.makeImageUrl)(featured[0]) : null; case 'favorites': return favorites.length && favorites.length > 0 ? (0, ui_1.makeImageUrl)(favorites[0]) : null; default: return recents.length && recents.length > 0 ? (0, ui_1.makeImageUrl)(recents[0]) : null; } }, [favorites, featured, title, recents]); var browse = function () { dispatch((0, slices_1.setCurrentCategory)(null)); navigate(path); }; var handlers = { browse: browse }; if (!config) return null; return children({ config: config, handlers: handlers, title: title, imageUrl: getCategoryItemImage(), apiUrl: apiUrl, displayImage: displayImage, navigationType: navigationType }); }; exports.default = CategoryNavOther;