import { BiteStyleProps } from '@components/DesignPanel/types'; import { DesignState } from './DesignStore'; import { getNewDesignClasses, getNewDesignList } from './Helpers'; /** * Filters the current design item from options and store * @param store * @returns */ // Function to update the current class in the store export const DesignClassToStore = ( designList: BiteStyleProps[], store: DesignState ) => { const { setCurrentClass } = store; const designClass = getNewDesignClasses(designList); setCurrentClass(designClass); }; // Function to update the current design in the store export const OptionToStore = ( value: string, currentModifierId: string, store: DesignState, errorLog?: boolean ) => { const designList = getNewDesignList(value, currentModifierId, store); if (errorLog) { console.log('Error log OptionStore', [...designList]); } // Update the current design in the store store.setCurrentDesign([...designList]); DesignClassToStore(designList, store); }; export const uniqueDesignList = (designList: BiteStyleProps[]) => { const uniqueDesign = [] as BiteStyleProps[]; designList.forEach((design) => { const index = uniqueDesign.findIndex( (item) => item.id === design.id && item.screen === design.screen && (item.interaction === design.interaction || (item.interaction === undefined && design.interaction === '')) ); if (index === -1) { uniqueDesign.push(design); } }); return uniqueDesign; }; export default { OptionToStore, uniqueDesignList, };