| 169 | |
| 170 | /** The totals scroll sideways on phones: an arrow shows on the side with more */ |
| 171 | const MetricsRow = ({ children }: { children: ReactNode }): ReactElement => { |
| 172 | const rowRef = useRef<HTMLDivElement>(null); |
| 173 | const [more, setMore] = useState({ before: false, after: false }); |
| 174 | |
| 175 | useEffect(() => { |
| 176 | const row = rowRef.current; |
| 177 | if (!row) { |
| 178 | return undefined; |
| 179 | } |
| 180 | |
| 181 | const update = () => |
| 182 | setMore({ |
| 183 | before: row.scrollLeft > 1, |
| 184 | after: row.scrollLeft + row.clientWidth < row.scrollWidth - 1, |
| 185 | }); |
| 186 | update(); |
| 187 | const observer = new ResizeObserver(update); |
| 188 | observer.observe(row); |
| 189 | row.addEventListener('scroll', update, { passive: true }); |
| 190 | |
| 191 | return () => { |
| 192 | observer.disconnect(); |
| 193 | row.removeEventListener('scroll', update); |
| 194 | }; |
| 195 | }, []); |
| 196 | |
| 197 | const scroll = (direction: 1 | -1) => |
| 198 | rowRef.current?.scrollBy({ |
| 199 | left: direction * rowRef.current.clientWidth * 0.8, |
| 200 | behavior: 'smooth', |
| 201 | }); |
| 202 | |
| 203 | return ( |
| 204 | <div className="relative"> |
| 205 | <div |
| 206 | ref={rowRef} |
| 207 | className="no-scrollbar flex snap-x snap-mandatory gap-px overflow-x-auto overscroll-x-contain bg-border-subtlest-tertiary tablet:grid tablet:auto-cols-fr tablet:grid-flow-col" |
| 208 | > |
| 209 | {children} |
| 210 | </div> |
| 211 | {more.before && <MetricsArrow side="before" onClick={() => scroll(-1)} />} |
| 212 | {more.after && <MetricsArrow side="after" onClick={() => scroll(1)} />} |
| 213 | </div> |
| 214 | ); |
| 215 | }; |
| 216 | |
| 217 | /** All boosts' totals, all time: the API has no daily breakdown to chart */ |
| 218 | const BoostMetrics = (): ReactElement => { |