diff --git a/package.json b/package.json index c95f088..8777865 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "vite-react-typescript-starter", + "name": "tianji", "private": true, "version": "0.0.0", "scripts": { diff --git a/src/client/components/DateFilter.tsx b/src/client/components/DateFilter.tsx index 9cdffa3..6178e9d 100644 --- a/src/client/components/DateFilter.tsx +++ b/src/client/components/DateFilter.tsx @@ -1,60 +1,161 @@ -import React from 'react'; -import { Dropdown, Select } from 'antd'; +import React, { useState } from 'react'; +import { Button, DatePicker, Dropdown, MenuProps, Modal, Space } from 'antd'; +import { Dayjs } from 'dayjs'; +import { DownOutlined } from '@ant-design/icons'; +import { DateRange, useGlobalStateStore } from '../store/global'; import { compact } from 'lodash-es'; +import clsx from 'clsx'; +import { useGlobalRangeDate } from '../hooks/useGlobalRangeDate'; -export const DateFilter: React.FC<{ - showAllTime?: boolean; -}> = React.memo((props) => { - const options = compact([ - { label: 'Today', value: '1day' }, - { - label: 'Last 24 hours', - value: '24hour', +const { RangePicker } = DatePicker; + +interface DateFilterProps { + className?: string; +} +export const DateFilter: React.FC = React.memo((props) => { + const [showPicker, setShowPicker] = useState(false); + const [showDropdown, setShowDropdown] = useState(false); + + const { label, startDate, endDate } = useGlobalRangeDate(); + const [range, setRange] = useState<[Dayjs, Dayjs]>([startDate, endDate]); + + const menu: MenuProps = { + onClick: () => { + setShowDropdown(false); }, - { - label: 'Yesterday', - value: '-1day', - }, - { - label: 'This Week', - value: '1week', - }, - { - label: 'Last 7 days', - value: '7day', - }, - { - label: 'This Month', - value: '1month', - }, - { - label: 'Last 30 days', - value: '30day', - }, - { - label: 'Last 90 days', - value: '90day', - }, - { label: 'This year', value: '1year' }, - props.showAllTime === true && { - label: 'All time', - value: 'all', - }, - { - label: 'Custom range', - value: 'custom', - }, - ]); + items: compact([ + { + label: 'Today', + onClick: () => { + useGlobalStateStore.setState({ dateRange: DateRange.Today }); + }, + }, + { + label: 'Last 24 Hours', + onClick: () => { + useGlobalStateStore.setState({ dateRange: DateRange.Last24Hours }); + }, + }, + { + label: 'Yesterday', + onClick: () => { + useGlobalStateStore.setState({ dateRange: DateRange.Yesterday }); + }, + }, + { + type: 'divider', + }, + { + label: 'This week', + onClick: () => { + useGlobalStateStore.setState({ dateRange: DateRange.ThisWeek }); + }, + }, + { + label: 'Last 7 days', + onClick: () => { + useGlobalStateStore.setState({ dateRange: DateRange.Last7Days }); + }, + }, + { + type: 'divider', + }, + { + label: 'This Month', + onClick: () => { + useGlobalStateStore.setState({ dateRange: DateRange.ThisMonth }); + }, + }, + { + label: 'Last 30 days', + onClick: () => { + useGlobalStateStore.setState({ dateRange: DateRange.Last30Days }); + }, + }, + { + label: 'Last 90 days', + onClick: () => { + useGlobalStateStore.setState({ dateRange: DateRange.Last90Days }); + }, + }, + { + label: 'This year', + onClick: () => { + useGlobalStateStore.setState({ dateRange: DateRange.ThisYear }); + }, + }, + { + type: 'divider', + }, + { + label: 'Custom', + onClick: () => { + setShowPicker(true); + }, + }, + ] as MenuProps['items']), + }; return ( -
-