import React from "react"; import { shiftDays, shiftMonths, formatISO, nowForSite, parseUTCDate, isBefore, isAfter, } from "./date"; import { QueryButton } from "./query"; function renderArrow(query, site, period, prevDate, nextDate) { const insertionDate = parseUTCDate(site.insertedAt); const disabledLeft = isBefore( parseUTCDate(prevDate), insertionDate, period ); const disabledRight = isAfter( parseUTCDate(nextDate), nowForSite(site), period ); const leftClasses = `flex items-center px-2 border-r border-gray-300 rounded-l dark:border-gray-500 dark:text-gray-100 ${ disabledLeft ? "bg-gray-300 dark:bg-gray-950" : "hover:bg-gray-100 dark:hover:bg-gray-900" }`; const rightClasses = `flex items-center px-2 rounded-r dark:text-gray-100 ${ disabledRight ? "bg-gray-300 dark:bg-gray-950" : "hover:bg-gray-100 dark:hover:bg-gray-900" }`; return (
); } export default function DatePickerArrows({site, query}) { if (query.period === "month") { const prevDate = formatISO(shiftMonths(query.date, -1)); const nextDate = formatISO(shiftMonths(query.date, 1)); return renderArrow(query, site, "month", prevDate, nextDate); } if (query.period === "day") { const prevDate = formatISO(shiftDays(query.date, -1)); const nextDate = formatISO(shiftDays(query.date, 1)); return renderArrow(query, site, "day", prevDate, nextDate); } return null }