import React from "react";
import { connect } from "react-redux";
import { generateCardLayout, Card } from "./Card";
import * as selectors from "../../selectors";
import { getFilterIdxFromColorSet } from "../../common/utilities";
import copy from "../../common/data/copy.json";
class CardStack extends React.Component {
constructor() {
super();
this.refs = {};
this.refCardStack = React.createRef();
this.refCardStackContent = React.createRef();
}
componentDidUpdate() {
const isNarrative = !!this.props.narrative;
if (isNarrative) {
this.scrollToCard();
}
}
scrollToCard() {
const duration = 500;
const element = this.refCardStack.current;
const cardScroll =
this.refs[this.props.narrative.current].current.offsetTop;
const start = element.scrollTop;
const change = cardScroll - start;
let currentTime = 0;
const increment = 20;
// t = current time
// b = start value
// c = change in value
// d = duration
Math.easeInOutQuad = function (t, b, c, d) {
t /= d / 2;
if (t < 1) return (c / 2) * t * t + b;
t -= 1;
return (-c / 2) * (t * (t - 2) - 1) + b;
};
const animateScroll = function () {
currentTime += increment;
const val = Math.easeInOutQuad(currentTime, start, change, duration);
element.scrollTop = val;
if (currentTime < duration) setTimeout(animateScroll, increment);
};
animateScroll();
}
renderCards(events, selections) {
// if no selections provided, select all
if (!selections) {
selections = events.map((e) => true);
}
this.refs = [];
const generateTemplate =
generateCardLayout[this.props.cardUI.layout.template];
return events.map((event, idx) => {
const thisRef = React.createRef();
this.refs[idx] = thisRef;
const content = generateTemplate({
event,
colors: this.props.colors,
coloringSet: this.props.coloringSet,
getFilterIdxFromColorSet,
});
return (
{`${this.props.selected.length} ${headerLang}`}