const viewItem = (state = INITIAL_STATE, action) => { if (lastPath() == REDUXPATH.PlayedVideos) { return state; // nothing should change when you are on the PlayedVideos page } // remove the duplicate videos and put the latest played video on the top return { ...state, ...{ viewedItems: [ action.item, ...state.viewedItems.filter( (item) => item.id.videoId !== action.item.id.videoId ), ], }, }; }