UNPKG

poi-plugin-lock-reminder

Version:

A poi plugin for reminding to lock new kanmusu.

83 lines (66 loc) 2 kB
"use strict"; exports.__esModule = true; exports.reducer = exports.recordPictureData = exports.getCache = void 0; var _redux = require("redux"); var _lodash = require("lodash"); var _selectors = require("subtender/poi/selectors"); var _utils = require("./utils"); // import { keyBy, get, map } from 'lodash' const LS_PATH = '_lock-reminder'; const { getStore } = window; const { originMstIdOf } = (0, _selectors.shipRemodelInfoSelector)(getStore()); // const indexify = data => // keyBy(data, s => get(s, 'api_table_id.0', '1')) const getCache = () => { const item = window.isSafeMode ? '{}' : localStorage.getItem(LS_PATH); return JSON.parse(item || '{}'); }; exports.getCache = getCache; const picture = (state = getCache(), action) => { const { type, payload = {} } = action; const { list = {}, timestamp } = payload; switch (type) { case `@@${_utils.PLUGIN_NAME}@record@pictureBook`: { const newState = (0, _lodash.compact)((0, _lodash.uniq)((0, _lodash.map)((0, _lodash.flatMap)(list), s => originMstIdOf[(0, _lodash.get)(s, 'api_table_id.0')]))); _utils.logger.log('newstate, payload, mapped', newState, payload, (0, _lodash.map)(list)); return { list: newState, timestamp }; } default: return state; } }; const recordPictureData = (data, page) => { const origin = getCache(); _utils.logger.log('recordPicData:', data, page); const payload = { list: { ...(0, _lodash.get)(origin, 'list', {}), [page]: (0, _lodash.get)(data, 'api_list', null) }, timestamp: { ...(0, _lodash.get)(origin, 'timestamp', {}), [page]: Date.now() } }; window.dispatch({ type: `@@${_utils.PLUGIN_NAME}@record@pictureBook`, payload }); localStorage.setItem(LS_PATH, JSON.stringify(payload || {})); }; exports.recordPictureData = recordPictureData; const reducer = (0, _redux.combineReducers)({ picture }); exports.reducer = reducer;