Compare commits
3 Commits
a8b4f17043
...
1559e603b0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1559e603b0 | ||
|
|
3fdee5cab4 | ||
|
|
7b0afbb27b |
@ -1,5 +1,5 @@
|
||||
import { useMemo } from 'react';
|
||||
import { Stack, Text, Paper, Group, Button } from '@mantine/core';
|
||||
import { useMemo, useRef } from 'react';
|
||||
import { Stack, Text, Paper, Group, Button, Box } from '@mantine/core';
|
||||
import { IconPlus } from '@tabler/icons-react';
|
||||
import { AnniversaryCard } from './AnniversaryCard';
|
||||
import { getHolidaysForYear } from '../../constants/holidays';
|
||||
@ -28,6 +28,42 @@ interface BuiltInHolidayEvent {
|
||||
export function AnniversaryList({ events, onEventClick, onAddClick }: AnniversaryListProps) {
|
||||
const anniversaries = events.filter((e) => e.type === 'anniversary');
|
||||
const showHolidays = useAppStore((state) => state.settings?.showHolidays ?? true);
|
||||
const scrollContainerRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
// 滚动条样式 - 仅在悬停时显示
|
||||
const scrollbarStyle = `
|
||||
.anniversary-scroll::-webkit-scrollbar {
|
||||
width: 4px;
|
||||
height: 4px;
|
||||
}
|
||||
.anniversary-scroll::-webkit-scrollbar-track {
|
||||
background: transparent;
|
||||
}
|
||||
.anniversary-scroll::-webkit-scrollbar-thumb {
|
||||
background: transparent;
|
||||
border-radius: 2px;
|
||||
}
|
||||
.anniversary-scroll:hover::-webkit-scrollbar-thumb {
|
||||
background: rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
`;
|
||||
|
||||
// 处理滚轮事件,实现列表独立滚动
|
||||
const handleWheel = (e: React.WheelEvent) => {
|
||||
const container = scrollContainerRef.current;
|
||||
if (!container) return;
|
||||
|
||||
const { scrollTop, scrollHeight, clientHeight } = container;
|
||||
// 使用 1px 缓冲避免浮点数精度问题
|
||||
const isAtTop = scrollTop <= 0;
|
||||
const isAtBottom = scrollTop + clientHeight >= scrollHeight - 1;
|
||||
|
||||
// 如果已经滚动到顶部且向下滚动,或者已经滚动到底部且向上滚动,则阻止事件冒泡
|
||||
if ((isAtTop && e.deltaY > 0) || (isAtBottom && e.deltaY < 0)) {
|
||||
e.stopPropagation();
|
||||
}
|
||||
// 如果在滚动范围内,允许事件继续传递以实现正常滚动
|
||||
};
|
||||
|
||||
// 获取内置节假日
|
||||
const builtInHolidays = useMemo(() => {
|
||||
@ -88,8 +124,9 @@ export function AnniversaryList({ events, onEventClick, onAddClick }: Anniversar
|
||||
// 空状态
|
||||
if (allAnniversaries.total === 0) {
|
||||
return (
|
||||
<Paper p="md" withBorder radius={4} h="100%">
|
||||
<Stack align="center" justify="center" h="100%">
|
||||
<Paper p="md" withBorder radius={4} style={{ display: 'flex', flexDirection: 'column', height: '100%' }}>
|
||||
<Stack align="center" justify="center" style={{ flex: 1 }}>
|
||||
<style>{scrollbarStyle}</style>
|
||||
<Text c="#999" size="sm" style={{ letterSpacing: '0.05em' }}>
|
||||
暂无纪念日
|
||||
</Text>
|
||||
@ -112,8 +149,10 @@ export function AnniversaryList({ events, onEventClick, onAddClick }: Anniversar
|
||||
}
|
||||
|
||||
return (
|
||||
<Paper p="md" withBorder radius={4} h="100%">
|
||||
<Group justify="space-between" mb="sm">
|
||||
<>
|
||||
<style>{scrollbarStyle}</style>
|
||||
<Paper p="md" withBorder radius={4} data-scroll-container="anniversary" style={{ display: 'flex', flexDirection: 'column', height: '100%' }}>
|
||||
<Group justify="space-between" mb="sm" style={{ flexShrink: 0 }}>
|
||||
<Group gap={8}>
|
||||
<Text fw={500} size="sm" style={{ letterSpacing: '0.1em', color: '#1a1a1a' }}>
|
||||
纪念日
|
||||
@ -136,7 +175,13 @@ export function AnniversaryList({ events, onEventClick, onAddClick }: Anniversar
|
||||
</Button>
|
||||
</Group>
|
||||
|
||||
<Stack gap="xs" style={{ maxHeight: 'calc(100% - 40px)', overflowY: 'auto' }}>
|
||||
<Box
|
||||
ref={scrollContainerRef}
|
||||
onWheel={handleWheel}
|
||||
className="anniversary-scroll"
|
||||
style={{ flex: 1, overflowY: 'auto', minHeight: 0 }}
|
||||
>
|
||||
<Stack gap="xs">
|
||||
{/* 内置节假日 */}
|
||||
{allAnniversaries.builtIn.length > 0 && (
|
||||
<>
|
||||
@ -193,7 +238,9 @@ export function AnniversaryList({ events, onEventClick, onAddClick }: Anniversar
|
||||
))}
|
||||
</>
|
||||
)}
|
||||
</Stack>
|
||||
</Paper>
|
||||
</Stack>
|
||||
</Box>
|
||||
</Paper>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { useState, useEffect, useCallback } from 'react';
|
||||
import { useState, useEffect, useCallback, useRef } from 'react';
|
||||
import {
|
||||
Paper,
|
||||
Textarea,
|
||||
@ -47,6 +47,24 @@ export function NoteEditor({ onSave }: NoteEditorProps) {
|
||||
// Auto-save with 3 second debounce
|
||||
const [debouncedContent] = useDebouncedValue(content, 3000);
|
||||
|
||||
// 滚动条样式 - 仅在悬停时显示
|
||||
const scrollbarStyle = `
|
||||
.note-scroll::-webkit-scrollbar {
|
||||
width: 4px;
|
||||
height: 4px;
|
||||
}
|
||||
.note-scroll::-webkit-scrollbar-track {
|
||||
background: transparent;
|
||||
}
|
||||
.note-scroll::-webkit-scrollbar-thumb {
|
||||
background: transparent;
|
||||
border-radius: 2px;
|
||||
}
|
||||
.note-scroll:hover::-webkit-scrollbar-thumb {
|
||||
background: rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
`;
|
||||
|
||||
useEffect(() => {
|
||||
if (debouncedContent !== undefined && notes && debouncedContent !== content) {
|
||||
handleSave(debouncedContent);
|
||||
@ -87,8 +105,28 @@ export function NoteEditor({ onSave }: NoteEditorProps) {
|
||||
}
|
||||
};
|
||||
|
||||
const scrollContainerRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
// 处理滚轮事件,实现列表独立滚动
|
||||
const handleWheel = (e: React.WheelEvent) => {
|
||||
const container = scrollContainerRef.current;
|
||||
if (!container) return;
|
||||
|
||||
const { scrollTop, scrollHeight, clientHeight } = container;
|
||||
// 使用 1px 缓冲避免浮点数精度问题
|
||||
const isAtTop = scrollTop <= 0;
|
||||
const isAtBottom = scrollTop + clientHeight >= scrollHeight - 1;
|
||||
|
||||
// 如果已经滚动到顶部且向下滚动,或者已经滚动到底部且向上滚动,则阻止事件冒泡
|
||||
if ((isAtTop && e.deltaY > 0) || (isAtBottom && e.deltaY < 0)) {
|
||||
e.stopPropagation();
|
||||
}
|
||||
// 如果在滚动范围内,允许事件继续传递以实现正常滚动
|
||||
};
|
||||
|
||||
return (
|
||||
<Paper p="md" withBorder radius={4} h="100%" style={{ display: 'flex', flexDirection: 'column' }}>
|
||||
<Paper p="md" withBorder radius={4} style={{ display: 'flex', flexDirection: 'column', height: '100%' }}>
|
||||
<style>{scrollbarStyle}</style>
|
||||
<Stack gap="sm" style={{ flex: 1, display: 'flex', flexDirection: 'column' }}>
|
||||
{/* Header */}
|
||||
<Group justify="space-between" style={{ flexShrink: 0 }}>
|
||||
@ -119,7 +157,13 @@ export function NoteEditor({ onSave }: NoteEditorProps) {
|
||||
</Group>
|
||||
|
||||
{/* Editor/Preview Area */}
|
||||
<Box style={{ flex: 1, minHeight: 0, display: 'flex' }}>
|
||||
<Box
|
||||
ref={scrollContainerRef}
|
||||
onWheel={handleWheel}
|
||||
data-scroll-container="note"
|
||||
className="note-scroll"
|
||||
style={{ flex: 1, minHeight: 0, display: 'flex', overflowY: 'auto' }}
|
||||
>
|
||||
{viewMode === 'edit' && (
|
||||
<Textarea
|
||||
value={content}
|
||||
@ -138,7 +182,11 @@ export function NoteEditor({ onSave }: NoteEditorProps) {
|
||||
'&:focus': { outline: 'none' },
|
||||
},
|
||||
}}
|
||||
style={{ flex: 1, width: '100%' }}
|
||||
style={{
|
||||
flex: 1,
|
||||
width: '100%',
|
||||
overflowY: 'auto',
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
|
||||
@ -19,6 +19,31 @@ interface ArchiveReminderModalProps {
|
||||
onDelete: (event: Event) => void;
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化日期显示,根据是否有时间选择显示格式
|
||||
*/
|
||||
function formatArchiveDate(dateStr: string): string {
|
||||
const date = new Date(dateStr);
|
||||
const hours = date.getHours();
|
||||
const minutes = date.getMinutes();
|
||||
const hasExplicitTime = hours !== 0 || minutes !== 0;
|
||||
|
||||
if (hasExplicitTime) {
|
||||
return date.toLocaleString('zh-CN', {
|
||||
month: 'numeric',
|
||||
day: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
hour12: false,
|
||||
});
|
||||
} else {
|
||||
return date.toLocaleString('zh-CN', {
|
||||
month: 'numeric',
|
||||
day: 'numeric',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export function ArchiveReminderModal({
|
||||
opened,
|
||||
onClose,
|
||||
@ -91,12 +116,7 @@ export function ArchiveReminderModal({
|
||||
{event.title}
|
||||
</Text>
|
||||
<Text size="xs" c="#bbb">
|
||||
{new Date(event.date).toLocaleString('zh-CN', {
|
||||
month: 'numeric',
|
||||
day: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
})}
|
||||
{formatArchiveDate(event.date)}
|
||||
</Text>
|
||||
</Stack>
|
||||
<Group gap={4}>
|
||||
|
||||
@ -1,37 +1,67 @@
|
||||
import { useMemo, useState, useEffect } from 'react';
|
||||
import { Paper, Text, Checkbox, Group, Stack, ActionIcon } from '@mantine/core';
|
||||
import { IconDots } from '@tabler/icons-react';
|
||||
import type { Event } from '../../types';
|
||||
import { useMemo, useState } from 'react';
|
||||
import { Paper, Text, Checkbox, Group, Stack, ActionIcon, Box } from '@mantine/core';
|
||||
import { IconDots, IconArrowForward, IconRepeat, IconRepeatOff } from '@tabler/icons-react';
|
||||
import type { Event, RepeatType } from '../../types';
|
||||
import { getRepeatTypeLabel } from '../../utils/repeatCalculator';
|
||||
|
||||
interface ReminderCardProps {
|
||||
event: Event;
|
||||
onToggle: () => void;
|
||||
onClick: () => void;
|
||||
onDelete?: () => void;
|
||||
onPostpone?: () => void;
|
||||
isMissed?: boolean;
|
||||
onMissedToggle?: () => void;
|
||||
}
|
||||
|
||||
export function ReminderCard({ event, onToggle, onClick, isMissed = false }: ReminderCardProps) {
|
||||
export function ReminderCard({ event, onToggle, onClick, onDelete, onPostpone, isMissed = false, onMissedToggle }: ReminderCardProps) {
|
||||
const isCompleted = event.is_completed ?? false;
|
||||
const [isHovered, setIsHovered] = useState(false);
|
||||
const [isAnimating, setIsAnimating] = useState(false);
|
||||
|
||||
// 计算时间信息
|
||||
const timeInfo = useMemo(() => {
|
||||
// 处理空日期情况
|
||||
if (!event.date) {
|
||||
return { isPast: false, isToday: true, timeStr: '未设置时间', diff: 0, hasTime: false };
|
||||
}
|
||||
|
||||
const now = new Date();
|
||||
const eventDate = new Date(event.date);
|
||||
const dateStr = event.date as string;
|
||||
|
||||
// 统一使用 Date 对象处理
|
||||
const eventDate = new Date(dateStr);
|
||||
|
||||
// 检查是否包含有效时间(小时和分钟不全为0)
|
||||
// 对于本地格式(如 "2025-02-05T00:00:00")和 ISO 格式都适用
|
||||
const hours = eventDate.getHours();
|
||||
const minutes = eventDate.getMinutes();
|
||||
const hasExplicitTime = hours !== 0 || minutes !== 0;
|
||||
|
||||
const diff = eventDate.getTime() - now.getTime();
|
||||
const isPast = diff < 0;
|
||||
const isToday = eventDate.toDateString() === now.toDateString();
|
||||
|
||||
const timeStr = eventDate.toLocaleString('zh-CN', {
|
||||
month: 'numeric',
|
||||
day: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
});
|
||||
// 格式化显示
|
||||
let timeStr: string;
|
||||
if (hasExplicitTime) {
|
||||
// 有设置时间,显示日期+时间
|
||||
timeStr = eventDate.toLocaleString('zh-CN', {
|
||||
month: 'numeric',
|
||||
day: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
hour12: false,
|
||||
});
|
||||
} else {
|
||||
// 没有设置时间(00:00),只显示日期
|
||||
timeStr = eventDate.toLocaleString('zh-CN', {
|
||||
month: 'numeric',
|
||||
day: 'numeric',
|
||||
});
|
||||
}
|
||||
|
||||
return { isPast, isToday, timeStr, diff };
|
||||
return { isPast, isToday, timeStr, diff, hasTime: hasExplicitTime };
|
||||
}, [event.date]);
|
||||
|
||||
// 获取文字颜色
|
||||
@ -62,6 +92,18 @@ export function ReminderCard({ event, onToggle, onClick, isMissed = false }: Rem
|
||||
return 'rgba(0, 0, 0, 0.06)';
|
||||
};
|
||||
|
||||
// 获取循环图标颜色
|
||||
const getRepeatIconColor = (type: RepeatType) => {
|
||||
const colors: Record<RepeatType, string> = {
|
||||
daily: '#3b82f6', // 蓝色
|
||||
weekly: '#22c55e', // 绿色
|
||||
monthly: '#a855f7', // 紫色
|
||||
yearly: '#f59e0b', // 橙色
|
||||
none: '#999',
|
||||
};
|
||||
return colors[type] || '#999';
|
||||
};
|
||||
|
||||
return (
|
||||
<Paper
|
||||
p="sm"
|
||||
@ -90,68 +132,70 @@ export function ReminderCard({ event, onToggle, onClick, isMissed = false }: Rem
|
||||
100% { opacity: 0; transform: translateX(20px); }
|
||||
}
|
||||
`}</style>
|
||||
<Group justify="space-between" wrap="nowrap">
|
||||
<Group gap="sm" style={{ flex: 1, minWidth: 0 }}>
|
||||
{/* Checkbox */}
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
animation: isAnimating ? 'reminder-card-pulse 0.3s ease-out' : 'none',
|
||||
{/* 正常提醒卡片:左右分栏布局 */}
|
||||
{!isMissed ? (
|
||||
<Group justify="space-between" wrap="nowrap" align="flex-start">
|
||||
{/* 左侧:Checkbox + 标题 + 内容 */}
|
||||
<Box
|
||||
style={{ flex: 1, minWidth: 0, cursor: 'pointer' }}
|
||||
onClick={(e) => {
|
||||
// 阻止事件冒泡到 Card,避免重复触发
|
||||
e.stopPropagation();
|
||||
onClick();
|
||||
}}
|
||||
>
|
||||
<Checkbox
|
||||
checked={isCompleted}
|
||||
onChange={(e) => {
|
||||
e.stopPropagation();
|
||||
if (isMissed && !isCompleted) {
|
||||
// 已过期提醒:先播放动画,动画结束后再触发 toggle
|
||||
setIsAnimating(true);
|
||||
setTimeout(() => {
|
||||
setIsAnimating(false);
|
||||
<Group gap="sm" wrap="nowrap" align="flex-start">
|
||||
{/* Checkbox - 单独处理,不触发卡片点击 */}
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
alignItems: 'flex-start',
|
||||
paddingTop: 2,
|
||||
animation: isAnimating ? 'reminder-card-pulse 0.3s ease-out' : 'none',
|
||||
}}
|
||||
onClick={(e) => {
|
||||
// 阻止事件冒泡,避免触发卡片点击
|
||||
e.stopPropagation();
|
||||
}}
|
||||
>
|
||||
<Checkbox
|
||||
checked={isCompleted}
|
||||
onChange={(e) => {
|
||||
e.stopPropagation();
|
||||
onToggle();
|
||||
}, 300);
|
||||
} else {
|
||||
onToggle();
|
||||
}
|
||||
}}
|
||||
size="xs"
|
||||
color="#1a1a1a"
|
||||
/>
|
||||
</div>
|
||||
}}
|
||||
size="xs"
|
||||
color="#1a1a1a"
|
||||
style={{
|
||||
animation: isAnimating ? 'reminder-card-pulse 0.3s ease-out' : 'none',
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<Stack gap={2} style={{ flex: 1, minWidth: 0 }} onClick={onClick}>
|
||||
{/* Title */}
|
||||
<Text
|
||||
fw={400}
|
||||
size="xs"
|
||||
lineClamp={1}
|
||||
style={{
|
||||
textDecoration: isCompleted ? 'line-through' : 'none',
|
||||
color: getTextColor(),
|
||||
letterSpacing: '0.03em',
|
||||
transition: 'color 0.2s ease',
|
||||
}}
|
||||
>
|
||||
{event.title}
|
||||
</Text>
|
||||
{/* 标题 */}
|
||||
<Text
|
||||
fw={400}
|
||||
size="xs"
|
||||
lineClamp={1}
|
||||
style={{
|
||||
textDecoration: isCompleted ? 'line-through' : 'none',
|
||||
color: getTextColor(),
|
||||
letterSpacing: '0.03em',
|
||||
transition: 'color 0.2s ease',
|
||||
}}
|
||||
>
|
||||
{event.title}
|
||||
</Text>
|
||||
</Group>
|
||||
|
||||
{/* Time */}
|
||||
<Text
|
||||
size="xs"
|
||||
c={getTimeColor()}
|
||||
style={{ letterSpacing: '0.05em' }}
|
||||
>
|
||||
{timeInfo.timeStr}
|
||||
</Text>
|
||||
|
||||
{/* Content preview - 始终显示 */}
|
||||
{/* 内容在标题下方 */}
|
||||
{event.content && (
|
||||
<Text
|
||||
size="xs"
|
||||
c={isCompleted ? '#bbb' : '#999'}
|
||||
lineClamp={1}
|
||||
style={{
|
||||
marginLeft: 28,
|
||||
opacity: isCompleted ? 0.6 : 1,
|
||||
transition: 'opacity 0.2s ease',
|
||||
}}
|
||||
@ -159,30 +203,154 @@ export function ReminderCard({ event, onToggle, onClick, isMissed = false }: Rem
|
||||
{event.content}
|
||||
</Text>
|
||||
)}
|
||||
</Stack>
|
||||
</Group>
|
||||
</Box>
|
||||
|
||||
{/* Quick actions */}
|
||||
<Group gap={4}>
|
||||
<ActionIcon
|
||||
size="sm"
|
||||
variant="subtle"
|
||||
color="gray"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
onClick();
|
||||
}}
|
||||
style={{
|
||||
color: '#999',
|
||||
opacity: isHovered ? 1 : 0,
|
||||
transition: 'all 0.2s ease',
|
||||
}}
|
||||
title="编辑"
|
||||
>
|
||||
<IconDots size={12} />
|
||||
</ActionIcon>
|
||||
{/* 右侧:循环图标 + 日期时间 */}
|
||||
<Box style={{ flex: '0 0 auto', minWidth: 0, paddingLeft: 12, display: 'flex', alignItems: 'center', gap: 6 }}>
|
||||
{event.repeat_type !== 'none' && (
|
||||
<Box
|
||||
style={{
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
color: getRepeatIconColor(event.repeat_type),
|
||||
}}
|
||||
title={getRepeatTypeLabel(event.repeat_type)}
|
||||
>
|
||||
<IconRepeat size={12} />
|
||||
</Box>
|
||||
)}
|
||||
<Text
|
||||
size="xs"
|
||||
c={getTimeColor()}
|
||||
style={{ letterSpacing: '0.05em', whiteSpace: 'nowrap' }}
|
||||
>
|
||||
{timeInfo.timeStr}
|
||||
</Text>
|
||||
</Box>
|
||||
</Group>
|
||||
</Group>
|
||||
) : (
|
||||
/* 逾期提醒卡片:保持原有结构 */
|
||||
<Group justify="space-between" wrap="nowrap">
|
||||
<Group gap="sm" style={{ flex: 1, minWidth: 0 }}>
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
animation: isAnimating ? 'reminder-card-pulse 0.3s ease-out' : 'none',
|
||||
}}
|
||||
>
|
||||
<Checkbox
|
||||
checked={isCompleted}
|
||||
onChange={(e) => {
|
||||
e.stopPropagation();
|
||||
if (isMissed && !isCompleted) {
|
||||
setIsAnimating(true);
|
||||
setTimeout(() => {
|
||||
setIsAnimating(false);
|
||||
onToggle();
|
||||
onMissedToggle?.();
|
||||
}, 300);
|
||||
} else {
|
||||
onToggle();
|
||||
}
|
||||
}}
|
||||
size="xs"
|
||||
color="#1a1a1a"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<Stack gap={2} style={{ flex: 1, minWidth: 0 }} onClick={onClick}>
|
||||
<Group gap={4} wrap="nowrap">
|
||||
<Text
|
||||
fw={400}
|
||||
size="xs"
|
||||
lineClamp={1}
|
||||
style={{
|
||||
textDecoration: isCompleted ? 'line-through' : 'none',
|
||||
color: getTextColor(),
|
||||
letterSpacing: '0.03em',
|
||||
transition: 'color 0.2s ease',
|
||||
}}
|
||||
>
|
||||
{event.title}
|
||||
</Text>
|
||||
{event.repeat_type !== 'none' && (
|
||||
<Box
|
||||
style={{
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
flexShrink: 0,
|
||||
color: getRepeatIconColor(event.repeat_type),
|
||||
}}
|
||||
title={getRepeatTypeLabel(event.repeat_type)}
|
||||
>
|
||||
<IconRepeat size={10} />
|
||||
</Box>
|
||||
)}
|
||||
</Group>
|
||||
<Text
|
||||
size="xs"
|
||||
c={getTimeColor()}
|
||||
style={{ letterSpacing: '0.05em' }}
|
||||
>
|
||||
{timeInfo.timeStr}
|
||||
</Text>
|
||||
{event.content && (
|
||||
<Text
|
||||
size="xs"
|
||||
c={isCompleted ? '#bbb' : '#999'}
|
||||
lineClamp={1}
|
||||
style={{
|
||||
opacity: isCompleted ? 0.6 : 1,
|
||||
transition: 'opacity 0.2s ease',
|
||||
}}
|
||||
>
|
||||
{event.content}
|
||||
</Text>
|
||||
)}
|
||||
</Stack>
|
||||
</Group>
|
||||
|
||||
<Group gap={4}>
|
||||
{onPostpone && (
|
||||
<ActionIcon
|
||||
size="sm"
|
||||
variant="subtle"
|
||||
color="orange"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
onPostpone();
|
||||
}}
|
||||
style={{
|
||||
color: '#e67e22',
|
||||
opacity: isHovered ? 1 : 0,
|
||||
transition: 'all 0.2s ease',
|
||||
}}
|
||||
title="顺延到今天"
|
||||
>
|
||||
<IconArrowForward size={12} />
|
||||
</ActionIcon>
|
||||
)}
|
||||
<ActionIcon
|
||||
size="sm"
|
||||
variant="subtle"
|
||||
color="gray"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
onClick();
|
||||
}}
|
||||
style={{
|
||||
color: '#999',
|
||||
opacity: isHovered ? 1 : 0,
|
||||
transition: 'all 0.2s ease',
|
||||
}}
|
||||
title="编辑"
|
||||
>
|
||||
<IconDots size={12} />
|
||||
</ActionIcon>
|
||||
</Group>
|
||||
</Group>
|
||||
)}
|
||||
</Paper>
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { useMemo } from 'react';
|
||||
import { useMemo, useRef, useState, useEffect } from 'react';
|
||||
import {
|
||||
Stack,
|
||||
Text,
|
||||
@ -6,11 +6,17 @@ import {
|
||||
Group,
|
||||
Button,
|
||||
Alert,
|
||||
Box,
|
||||
} from '@mantine/core';
|
||||
import {
|
||||
IconPlus,
|
||||
IconAlertCircle,
|
||||
IconArchive,
|
||||
IconChevronDown,
|
||||
IconChevronRight,
|
||||
IconChevronUp,
|
||||
} from '@tabler/icons-react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { ReminderCard } from './ReminderCard';
|
||||
import type { Event } from '../../types';
|
||||
|
||||
@ -20,7 +26,7 @@ interface ReminderListProps {
|
||||
onToggleComplete: (event: Event) => void;
|
||||
onAddClick: () => void;
|
||||
onDelete?: (event: Event) => void;
|
||||
onRestore?: (event: Event) => void;
|
||||
onPostpone?: (event: Event) => void;
|
||||
}
|
||||
|
||||
export function ReminderList({
|
||||
@ -29,19 +35,96 @@ export function ReminderList({
|
||||
onToggleComplete,
|
||||
onAddClick,
|
||||
onDelete,
|
||||
onRestore,
|
||||
onPostpone,
|
||||
}: ReminderListProps) {
|
||||
const navigate = useNavigate();
|
||||
const scrollContainerRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
// 分类折叠状态
|
||||
const [collapsed, setCollapsed] = useState({
|
||||
today: false,
|
||||
tomorrow: false,
|
||||
later: false,
|
||||
});
|
||||
|
||||
// 逾期列表展开状态(默认收起)
|
||||
const [missedExpanded, setMissedExpanded] = useState(false);
|
||||
|
||||
// 归档图标抖动动画状态
|
||||
const [archiveShake, setArchiveShake] = useState(false);
|
||||
|
||||
// 归档图标抖动动画样式
|
||||
const shakeAnimationStyle = `
|
||||
@keyframes archiveShake {
|
||||
0%, 100% { transform: scale(1); }
|
||||
25% { transform: scale(1.3); }
|
||||
50% { transform: scale(1); }
|
||||
75% { transform: scale(1.3); }
|
||||
}
|
||||
`;
|
||||
|
||||
// 触发归档图标抖动动画
|
||||
const triggerArchiveShake = () => {
|
||||
setArchiveShake(true);
|
||||
setTimeout(() => {
|
||||
setArchiveShake(false);
|
||||
}, 400);
|
||||
};
|
||||
|
||||
// 切换分类折叠状态
|
||||
const toggleCollapse = (category: keyof typeof collapsed) => {
|
||||
setCollapsed((prev) => ({
|
||||
...prev,
|
||||
[category]: !prev[category],
|
||||
}));
|
||||
};
|
||||
|
||||
// 滚动条样式 - 仅在悬停时显示
|
||||
const scrollbarStyle = `
|
||||
.reminder-scroll::-webkit-scrollbar {
|
||||
width: 4px;
|
||||
height: 4px;
|
||||
}
|
||||
.reminder-scroll::-webkit-scrollbar-track {
|
||||
background: transparent;
|
||||
}
|
||||
.reminder-scroll::-webkit-scrollbar-thumb {
|
||||
background: transparent;
|
||||
border-radius: 2px;
|
||||
}
|
||||
.reminder-scroll:hover::-webkit-scrollbar-thumb {
|
||||
background: rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
`;
|
||||
|
||||
// 处理滚轮事件,实现列表独立滚动
|
||||
const handleWheel = (e: React.WheelEvent) => {
|
||||
const container = scrollContainerRef.current;
|
||||
if (!container) return;
|
||||
|
||||
const { scrollTop, scrollHeight, clientHeight } = container;
|
||||
// 使用 1px 缓冲避免浮点数精度问题
|
||||
const isAtTop = scrollTop <= 0;
|
||||
const isAtBottom = scrollTop + clientHeight >= scrollHeight - 1;
|
||||
|
||||
// 如果已经滚动到顶部且向下滚动,或者已经滚动到底部且向上滚动,则阻止事件冒泡
|
||||
if ((isAtTop && e.deltaY > 0) || (isAtBottom && e.deltaY < 0)) {
|
||||
e.stopPropagation();
|
||||
}
|
||||
// 如果在滚动范围内,允许事件继续传递以实现正常滚动
|
||||
};
|
||||
|
||||
const grouped = useMemo(() => {
|
||||
const now = new Date();
|
||||
const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
||||
today.setHours(0, 0, 0, 0);
|
||||
const tomorrow = new Date(today);
|
||||
tomorrow.setDate(tomorrow.getDate() + 1);
|
||||
tomorrow.setHours(0, 0, 0, 0);
|
||||
const dayAfterTomorrow = new Date(tomorrow);
|
||||
dayAfterTomorrow.setDate(dayAfterTomorrow.getDate() + 1);
|
||||
dayAfterTomorrow.setHours(0, 0, 0, 0);
|
||||
// 仅按日期部分判断,获取今天的开始时间
|
||||
const todayStart = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
||||
todayStart.setHours(0, 0, 0, 0);
|
||||
const tomorrowStart = new Date(todayStart);
|
||||
tomorrowStart.setDate(tomorrowStart.getDate() + 1);
|
||||
tomorrowStart.setHours(0, 0, 0, 0);
|
||||
const dayAfterTomorrowStart = new Date(tomorrowStart);
|
||||
dayAfterTomorrowStart.setDate(dayAfterTomorrowStart.getDate() + 1);
|
||||
dayAfterTomorrowStart.setHours(0, 0, 0, 0);
|
||||
|
||||
const reminders = events.filter((e) => e.type === 'reminder');
|
||||
|
||||
@ -53,21 +136,29 @@ export function ReminderList({
|
||||
};
|
||||
|
||||
reminders.forEach((event) => {
|
||||
const eventDate = new Date(event.date);
|
||||
|
||||
// 已过期且已完成的去归档页
|
||||
if (event.is_completed && eventDate < now) {
|
||||
// 无日期的提醒不视为逾期,放入今天分组
|
||||
if (!event.date) {
|
||||
result.today.push(event);
|
||||
return;
|
||||
}
|
||||
|
||||
// 未过期或已完成未过期的,按时间分组
|
||||
if (eventDate < now) {
|
||||
const eventDate = new Date(event.date);
|
||||
// 仅取日期部分进行比较(忽略时间)
|
||||
const eventDateOnly = new Date(eventDate.getFullYear(), eventDate.getMonth(), eventDate.getDate());
|
||||
|
||||
// 已过期且已完成的去归档页
|
||||
if (event.is_completed && eventDateOnly < todayStart) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 按日期部分判断是否逾期
|
||||
if (eventDateOnly < todayStart) {
|
||||
// 已过期未完成
|
||||
result.missed.push(event);
|
||||
} else if (eventDate < tomorrow) {
|
||||
} else if (eventDateOnly < tomorrowStart) {
|
||||
// 今天
|
||||
result.today.push(event);
|
||||
} else if (eventDate < dayAfterTomorrow) {
|
||||
} else if (eventDateOnly < dayAfterTomorrowStart) {
|
||||
// 明天
|
||||
result.tomorrow.push(event);
|
||||
} else {
|
||||
@ -98,8 +189,8 @@ export function ReminderList({
|
||||
// 空状态
|
||||
if (!hasActiveReminders) {
|
||||
return (
|
||||
<Paper p="md" withBorder radius={4} h="100%">
|
||||
<Stack align="center" justify="center" h="100%">
|
||||
<Paper p="md" withBorder radius={4} style={{ display: 'flex', flexDirection: 'column', height: '100%' }}>
|
||||
<Stack align="center" justify="center" style={{ flex: 1 }}>
|
||||
<Text c="#999" size="sm" ta="center" style={{ letterSpacing: '0.05em' }}>
|
||||
暂无提醒
|
||||
</Text>
|
||||
@ -125,23 +216,40 @@ export function ReminderList({
|
||||
);
|
||||
}
|
||||
|
||||
// 已过提醒数量提示
|
||||
const missedCount = grouped.missed.length;
|
||||
|
||||
return (
|
||||
<>
|
||||
<Paper p="md" withBorder radius={4} h="100%" style={{ display: 'flex', flexDirection: 'column' }}>
|
||||
<style>{scrollbarStyle}</style>
|
||||
<style>{shakeAnimationStyle}</style>
|
||||
<Paper p="md" withBorder radius={4} data-scroll-container="reminder" style={{ display: 'flex', flexDirection: 'column', height: '100%' }}>
|
||||
{/* Header */}
|
||||
<Group justify="space-between" mb="sm" style={{ flexShrink: 0 }}>
|
||||
<Group gap={8}>
|
||||
<Text fw={500} size="sm" style={{ letterSpacing: '0.1em', color: '#1a1a1a' }}>
|
||||
提醒
|
||||
</Text>
|
||||
{missedCount > 0 && (
|
||||
<Text size="xs" c="#c41c1c" fw={500}>
|
||||
{missedCount}个逾期
|
||||
</Text>
|
||||
)}
|
||||
<Button
|
||||
variant="subtle"
|
||||
size="xs"
|
||||
leftSection={
|
||||
<IconArchive
|
||||
size={12}
|
||||
style={{
|
||||
transform: archiveShake ? 'scale(1.3)' : 'scale(1)',
|
||||
transition: 'transform 0.2s ease',
|
||||
animation: archiveShake ? 'archiveShake 0.4s ease-in-out' : 'none',
|
||||
}}
|
||||
/>
|
||||
}
|
||||
onClick={() => navigate('/archive')}
|
||||
style={{
|
||||
color: '#999',
|
||||
borderRadius: 2,
|
||||
padding: '2px 6px',
|
||||
height: 'auto',
|
||||
}}
|
||||
>
|
||||
归档
|
||||
</Button>
|
||||
</Group>
|
||||
<Button
|
||||
variant="subtle"
|
||||
@ -158,7 +266,17 @@ export function ReminderList({
|
||||
</Group>
|
||||
|
||||
{/* Content */}
|
||||
<Stack gap="xs" style={{ flex: 1, overflowY: 'auto', minHeight: 0 }}>
|
||||
<Box
|
||||
ref={scrollContainerRef}
|
||||
onWheel={handleWheel}
|
||||
className="reminder-scroll"
|
||||
style={{
|
||||
flex: 1,
|
||||
overflowY: 'auto',
|
||||
minHeight: 0,
|
||||
}}
|
||||
>
|
||||
<Stack gap="xs">
|
||||
{/* 逾期提醒 */}
|
||||
{grouped.missed.length > 0 && (
|
||||
<Alert
|
||||
@ -169,20 +287,66 @@ export function ReminderList({
|
||||
title={<Text size="xs" fw={500} c="#c41c1c">已错过 {grouped.missed.length}个</Text>}
|
||||
>
|
||||
<Stack gap={4}>
|
||||
{grouped.missed.slice(0, 3).map((event) => (
|
||||
<ReminderCard
|
||||
key={event.id}
|
||||
event={event}
|
||||
onClick={() => onEventClick(event)}
|
||||
onToggle={() => onToggleComplete(event)}
|
||||
onDelete={onDelete ? () => onDelete(event) : undefined}
|
||||
isMissed={true}
|
||||
/>
|
||||
))}
|
||||
{grouped.missed.length > 3 && (
|
||||
<Text size="xs" c="#999" ta="center">
|
||||
还有 {grouped.missed.length - 3} 个逾期提醒...
|
||||
</Text>
|
||||
{/* 展开时显示所有逾期提醒 */}
|
||||
{missedExpanded ? (
|
||||
<>
|
||||
{grouped.missed.map((event) => (
|
||||
<ReminderCard
|
||||
key={event.id}
|
||||
event={event}
|
||||
onClick={() => onEventClick(event)}
|
||||
onToggle={() => onToggleComplete(event)}
|
||||
onDelete={onDelete ? () => onDelete(event) : undefined}
|
||||
onPostpone={onPostpone ? () => onPostpone(event) : undefined}
|
||||
onMissedToggle={triggerArchiveShake}
|
||||
isMissed={true}
|
||||
/>
|
||||
))}
|
||||
{/* 收起按钮 */}
|
||||
<Button
|
||||
variant="subtle"
|
||||
size="xs"
|
||||
leftSection={<IconChevronUp size={12} />}
|
||||
onClick={() => setMissedExpanded(false)}
|
||||
style={{
|
||||
color: '#999',
|
||||
borderRadius: 2,
|
||||
marginTop: 4,
|
||||
}}
|
||||
>
|
||||
收起
|
||||
</Button>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
{/* 收起状态:只显示前3个 */}
|
||||
{grouped.missed.slice(0, 3).map((event) => (
|
||||
<ReminderCard
|
||||
key={event.id}
|
||||
event={event}
|
||||
onClick={() => onEventClick(event)}
|
||||
onToggle={() => onToggleComplete(event)}
|
||||
onDelete={onDelete ? () => onDelete(event) : undefined}
|
||||
onPostpone={onPostpone ? () => onPostpone(event) : undefined}
|
||||
onMissedToggle={triggerArchiveShake}
|
||||
isMissed={true}
|
||||
/>
|
||||
))}
|
||||
{grouped.missed.length > 3 && (
|
||||
<Text
|
||||
size="xs"
|
||||
c="#999"
|
||||
ta="center"
|
||||
style={{
|
||||
cursor: 'pointer',
|
||||
textDecoration: 'underline',
|
||||
}}
|
||||
onClick={() => setMissedExpanded(true)}
|
||||
>
|
||||
还有 {grouped.missed.length - 3} 个逾期提醒...
|
||||
</Text>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</Stack>
|
||||
</Alert>
|
||||
@ -191,12 +355,21 @@ export function ReminderList({
|
||||
{/* 今天 */}
|
||||
{grouped.today.length > 0 && (
|
||||
<>
|
||||
<Group gap={4}>
|
||||
<Group
|
||||
gap={4}
|
||||
style={{ cursor: 'pointer' }}
|
||||
onClick={() => toggleCollapse('today')}
|
||||
>
|
||||
<Text size="xs" c="#c41c1c" fw={400} style={{ letterSpacing: '0.05em' }}>
|
||||
今天
|
||||
</Text>
|
||||
{collapsed.today ? (
|
||||
<IconChevronRight size={12} color="#999" />
|
||||
) : (
|
||||
<IconChevronDown size={12} color="#999" />
|
||||
)}
|
||||
</Group>
|
||||
{grouped.today.map((event) => (
|
||||
{!collapsed.today && grouped.today.map((event) => (
|
||||
<ReminderCard
|
||||
key={event.id}
|
||||
event={event}
|
||||
@ -211,12 +384,21 @@ export function ReminderList({
|
||||
{/* 明天 */}
|
||||
{grouped.tomorrow.length > 0 && (
|
||||
<>
|
||||
<Group gap={4}>
|
||||
<Group
|
||||
gap={4}
|
||||
style={{ cursor: 'pointer' }}
|
||||
onClick={() => toggleCollapse('tomorrow')}
|
||||
>
|
||||
<Text size="xs" c="#666" fw={400} style={{ letterSpacing: '0.05em' }}>
|
||||
明天
|
||||
</Text>
|
||||
{collapsed.tomorrow ? (
|
||||
<IconChevronRight size={12} color="#999" />
|
||||
) : (
|
||||
<IconChevronDown size={12} color="#999" />
|
||||
)}
|
||||
</Group>
|
||||
{grouped.tomorrow.map((event) => (
|
||||
{!collapsed.tomorrow && grouped.tomorrow.map((event) => (
|
||||
<ReminderCard
|
||||
key={event.id}
|
||||
event={event}
|
||||
@ -231,12 +413,21 @@ export function ReminderList({
|
||||
{/* 更久之后 */}
|
||||
{grouped.later.length > 0 && (
|
||||
<>
|
||||
<Group gap={4}>
|
||||
<Group
|
||||
gap={4}
|
||||
style={{ cursor: 'pointer' }}
|
||||
onClick={() => toggleCollapse('later')}
|
||||
>
|
||||
<Text size="xs" c="#999" fw={400} style={{ letterSpacing: '0.05em' }}>
|
||||
更久之后
|
||||
</Text>
|
||||
{collapsed.later ? (
|
||||
<IconChevronRight size={12} color="#999" />
|
||||
) : (
|
||||
<IconChevronDown size={12} color="#999" />
|
||||
)}
|
||||
</Group>
|
||||
{grouped.later.map((event) => (
|
||||
{!collapsed.later && grouped.later.map((event) => (
|
||||
<ReminderCard
|
||||
key={event.id}
|
||||
event={event}
|
||||
@ -248,6 +439,7 @@ export function ReminderList({
|
||||
</>
|
||||
)}
|
||||
</Stack>
|
||||
</Box>
|
||||
</Paper>
|
||||
</>
|
||||
);
|
||||
|
||||
@ -15,6 +15,31 @@ import { useNavigate } from 'react-router-dom';
|
||||
import { useAppStore } from '../stores';
|
||||
import type { Event } from '../types';
|
||||
|
||||
/**
|
||||
* 格式化日期显示,根据是否有时间选择显示格式
|
||||
*/
|
||||
function formatArchiveDate(dateStr: string): string {
|
||||
const date = new Date(dateStr);
|
||||
const hours = date.getHours();
|
||||
const minutes = date.getMinutes();
|
||||
const hasExplicitTime = hours !== 0 || minutes !== 0;
|
||||
|
||||
if (hasExplicitTime) {
|
||||
return date.toLocaleString('zh-CN', {
|
||||
month: 'numeric',
|
||||
day: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
hour12: false,
|
||||
});
|
||||
} else {
|
||||
return date.toLocaleString('zh-CN', {
|
||||
month: 'numeric',
|
||||
day: 'numeric',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export function ArchivePage() {
|
||||
const navigate = useNavigate();
|
||||
const events = useAppStore((state) => state.events);
|
||||
@ -35,10 +60,14 @@ export function ArchivePage() {
|
||||
// 获取已归档的提醒(已过期且已勾选的)
|
||||
const archivedReminders = events.filter((e) => {
|
||||
if (e.type !== 'reminder' || !e.is_completed) return false;
|
||||
if (!e.date) return false; // 跳过无日期的
|
||||
const eventDate = new Date(e.date);
|
||||
const now = new Date();
|
||||
return eventDate < now; // 仅已过期的
|
||||
}).sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime());
|
||||
}).sort((a, b) => {
|
||||
if (!a.date || !b.date) return 0;
|
||||
return new Date(b.date).getTime() - new Date(a.date).getTime();
|
||||
});
|
||||
|
||||
const handleRestore = async (event: Event) => {
|
||||
await updateEventById(event.id, { is_completed: false });
|
||||
@ -128,12 +157,7 @@ export function ArchivePage() {
|
||||
{event.title}
|
||||
</Text>
|
||||
<Text size="xs" c="#bbb">
|
||||
{new Date(event.date).toLocaleString('zh-CN', {
|
||||
month: 'numeric',
|
||||
day: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
})}
|
||||
{formatArchiveDate(event.date)}
|
||||
</Text>
|
||||
{event.content && (
|
||||
<Text size="xs" c="#bbb" lineClamp={1}>
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import {
|
||||
Container,
|
||||
Grid,
|
||||
Title,
|
||||
Button,
|
||||
Group,
|
||||
@ -14,7 +13,7 @@ import {
|
||||
Stack,
|
||||
} from '@mantine/core';
|
||||
import { DatePickerInput, TimeInput } from '@mantine/dates';
|
||||
import { IconLogout, IconSettings, IconArchive } from '@tabler/icons-react';
|
||||
import { IconLogout, IconSettings } from '@tabler/icons-react';
|
||||
import { useDisclosure } from '@mantine/hooks';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useAppStore } from '../stores';
|
||||
@ -23,6 +22,7 @@ import { ReminderList } from '../components/reminder/ReminderList';
|
||||
import { NoteEditor } from '../components/note/NoteEditor';
|
||||
import { FloatingAIChat } from '../components/ai/FloatingAIChat';
|
||||
import type { Event, EventType, RepeatType } from '../types';
|
||||
import { calculateNextReminderDate } from '../utils/repeatCalculator';
|
||||
|
||||
export function HomePage() {
|
||||
const navigate = useNavigate();
|
||||
@ -57,6 +57,7 @@ export function HomePage() {
|
||||
|
||||
const handleLogout = async () => {
|
||||
await logout();
|
||||
navigate('/landing');
|
||||
};
|
||||
|
||||
const handleEventClick = (event: Event) => {
|
||||
@ -69,6 +70,11 @@ export function HomePage() {
|
||||
setFormIsLunar(event.is_lunar);
|
||||
setFormRepeatType(event.repeat_type);
|
||||
setFormIsHoliday(event.is_holiday || false);
|
||||
// 提取时间(如果日期中包含时间信息)
|
||||
const eventDate = new Date(event.date);
|
||||
const hours = eventDate.getHours();
|
||||
const minutes = eventDate.getMinutes();
|
||||
setFormTime(hours === 0 && minutes === 0 ? '' : `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}`);
|
||||
open();
|
||||
};
|
||||
|
||||
@ -92,20 +98,38 @@ export function HomePage() {
|
||||
// 确保 date 是 Date 对象
|
||||
const dateObj = formDate instanceof Date ? formDate : new Date(formDate as unknown as string);
|
||||
|
||||
const dateStr = formTime
|
||||
? new Date(dateObj.setHours(parseInt(formTime.split(':')[0]), parseInt(formTime.split(':')[1])))
|
||||
: dateObj;
|
||||
let dateStr: string;
|
||||
const year = dateObj.getFullYear();
|
||||
const month = String(dateObj.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(dateObj.getDate()).padStart(2, '0');
|
||||
|
||||
const eventData = {
|
||||
if (formTime) {
|
||||
// 有时间:构建本地时间格式
|
||||
const hours = String(parseInt(formTime.split(':')[0])).padStart(2, '0');
|
||||
const minutes = String(parseInt(formTime.split(':')[1])).padStart(2, '0');
|
||||
dateStr = `${year}-${month}-${day}T${hours}:${minutes}:00`;
|
||||
} else {
|
||||
// 无时间:只保存日期部分
|
||||
dateStr = `${year}-${month}-${day}T00:00:00`;
|
||||
}
|
||||
|
||||
// 构建事件数据,确保不包含 undefined 值
|
||||
const eventData: Record<string, any> = {
|
||||
type: formType,
|
||||
title: formTitle,
|
||||
content: formContent || undefined,
|
||||
date: dateStr.toISOString(),
|
||||
date: dateStr,
|
||||
is_lunar: formIsLunar,
|
||||
repeat_type: formRepeatType,
|
||||
is_holiday: formIsHoliday || undefined,
|
||||
// 计算下一次提醒日期
|
||||
next_reminder_date: calculateNextReminderDate(dateStr, formRepeatType, undefined),
|
||||
is_holiday: formIsHoliday ?? false,
|
||||
};
|
||||
|
||||
// 只有当 content 有值时才包含
|
||||
if (formContent.trim()) {
|
||||
eventData.content = formContent;
|
||||
}
|
||||
|
||||
if (isEdit && selectedEvent) {
|
||||
await updateEventById(selectedEvent.id, eventData);
|
||||
} else {
|
||||
@ -143,12 +167,25 @@ export function HomePage() {
|
||||
fetchEvents();
|
||||
};
|
||||
|
||||
const handleRestore = async (event: Event) => {
|
||||
const handlePostpone = async (event: Event) => {
|
||||
if (event.type !== 'reminder') return;
|
||||
await updateEventById(event.id, {
|
||||
is_completed: false,
|
||||
// 将日期顺延到今天,保留原事件的时间
|
||||
const today = new Date();
|
||||
const originalDate = new Date(event.date);
|
||||
|
||||
// 提取原时间的小时和分钟
|
||||
const hours = originalDate.getHours();
|
||||
const minutes = originalDate.getMinutes();
|
||||
|
||||
// 构建新的本地时间字符串
|
||||
const newDateStr = `${today.getFullYear()}-${String(today.getMonth() + 1).padStart(2, '0')}-${String(today.getDate()).padStart(2, '0')}T${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}:00`;
|
||||
|
||||
const result = await updateEventById(event.id, {
|
||||
date: newDateStr,
|
||||
});
|
||||
fetchEvents();
|
||||
if (result.error) {
|
||||
console.error('顺延失败:', result.error);
|
||||
}
|
||||
};
|
||||
|
||||
const resetForm = () => {
|
||||
@ -173,9 +210,11 @@ export function HomePage() {
|
||||
style={{
|
||||
minHeight: '100vh',
|
||||
background: '#faf9f7',
|
||||
overflow: 'hidden',
|
||||
height: '100vh',
|
||||
}}
|
||||
>
|
||||
<Container size="xl" py="md" h="100vh" style={{ display: 'flex', flexDirection: 'column' }}>
|
||||
<Container size="xl" py="md" h="100vh" style={{ display: 'flex', flexDirection: 'column', overflow: 'hidden' }}>
|
||||
{/* Header */}
|
||||
<Group justify="space-between" mb="md" style={{ flexShrink: 0 }}>
|
||||
<Title
|
||||
@ -190,20 +229,6 @@ export function HomePage() {
|
||||
掐日子
|
||||
</Title>
|
||||
<Group>
|
||||
{/* 归档入口 - 一直显示 */}
|
||||
<Button
|
||||
variant="subtle"
|
||||
color="gray"
|
||||
size="xs"
|
||||
leftSection={<IconArchive size={12} />}
|
||||
onClick={() => navigate('/archive')}
|
||||
style={{
|
||||
letterSpacing: '0.1em',
|
||||
borderRadius: 2,
|
||||
}}
|
||||
>
|
||||
归档
|
||||
</Button>
|
||||
{/* 设置入口 */}
|
||||
<Button
|
||||
variant="subtle"
|
||||
@ -242,39 +267,33 @@ export function HomePage() {
|
||||
</Group>
|
||||
|
||||
{/* Main Content - 3 column horizontal layout */}
|
||||
<Grid grow style={{ flex: 1, minHeight: 0 }} gutter="md">
|
||||
<div style={{ flex: 1, minHeight: 0, display: 'flex', gap: 16, overflow: 'hidden' }}>
|
||||
{/* Left column - Anniversary */}
|
||||
<Grid.Col span={4}>
|
||||
<div style={{ height: '100%', minHeight: 0 }}>
|
||||
<AnniversaryList
|
||||
events={events}
|
||||
onEventClick={handleEventClick}
|
||||
onAddClick={() => handleAddClick('anniversary')}
|
||||
/>
|
||||
</div>
|
||||
</Grid.Col>
|
||||
<div style={{ flex: 1, minWidth: 0, height: '100%', overflow: 'hidden' }}>
|
||||
<AnniversaryList
|
||||
events={events}
|
||||
onEventClick={handleEventClick}
|
||||
onAddClick={() => handleAddClick('anniversary')}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Middle column - Reminder */}
|
||||
<Grid.Col span={4}>
|
||||
<div style={{ height: '100%', minHeight: 0 }}>
|
||||
<ReminderList
|
||||
events={events}
|
||||
onEventClick={handleEventClick}
|
||||
onToggleComplete={handleToggleComplete}
|
||||
onAddClick={() => handleAddClick('reminder')}
|
||||
onDelete={handleDelete}
|
||||
onRestore={handleRestore}
|
||||
/>
|
||||
</div>
|
||||
</Grid.Col>
|
||||
<div style={{ flex: 1, minWidth: 0, height: '100%', overflow: 'hidden' }}>
|
||||
<ReminderList
|
||||
events={events}
|
||||
onEventClick={handleEventClick}
|
||||
onToggleComplete={handleToggleComplete}
|
||||
onAddClick={() => handleAddClick('reminder')}
|
||||
onDelete={handleDelete}
|
||||
onPostpone={handlePostpone}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Right column - Note */}
|
||||
<Grid.Col span={4}>
|
||||
<div style={{ height: '100%', minHeight: 0 }}>
|
||||
<NoteEditor />
|
||||
</div>
|
||||
</Grid.Col>
|
||||
</Grid>
|
||||
<div style={{ flex: 1, minWidth: 0, height: '100%', overflow: 'hidden' }}>
|
||||
<NoteEditor />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* AI Chat - Floating */}
|
||||
<FloatingAIChat onEventCreated={handleAIEventCreated} />
|
||||
@ -426,8 +445,10 @@ export function HomePage() {
|
||||
}
|
||||
data={[
|
||||
{ value: 'none', label: '不重复' },
|
||||
{ value: 'yearly', label: '每年' },
|
||||
{ value: 'daily', label: '每天' },
|
||||
{ value: 'weekly', label: '每周' },
|
||||
{ value: 'monthly', label: '每月' },
|
||||
{ value: 'yearly', label: '每年' },
|
||||
]}
|
||||
value={formRepeatType}
|
||||
onChange={(value) => value && setFormRepeatType(value as RepeatType)}
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
import { create } from 'zustand';
|
||||
import { persist, createJSONStorage } from 'zustand/middleware';
|
||||
import type { User, Event, Note, AIConversation, EventType } from '../types';
|
||||
import type { User, Event, Note, AIConversation, EventType, RepeatType } from '../types';
|
||||
import { api } from '../services/api';
|
||||
import { calculateNextReminderDate, findNextValidReminderDate, isDuplicateReminder } from '../utils/repeatCalculator';
|
||||
|
||||
// 应用设置类型
|
||||
interface AppSettings {
|
||||
@ -134,16 +135,100 @@ export const useAppStore = create<AppState>()(
|
||||
|
||||
updateEventById: async (id, event) => {
|
||||
try {
|
||||
// 乐观更新:立即更新本地状态
|
||||
set((state) => ({
|
||||
events: state.events.map((e) =>
|
||||
e.id === id ? { ...e, ...event } : e
|
||||
),
|
||||
}));
|
||||
// 发送 API 请求
|
||||
await api.events.update(id, event);
|
||||
// 乐观更新已生效,不需要用 API 返回数据覆盖
|
||||
// 避免 API 返回数据不完整导致状态丢失
|
||||
// 使用 set 的回调函数获取当前状态
|
||||
let currentEvent: Event | undefined;
|
||||
let allEvents: Event[] = [];
|
||||
set((state) => {
|
||||
allEvents = state.events;
|
||||
currentEvent = state.events.find((e) => e.id === id);
|
||||
return {
|
||||
events: state.events.map((e) =>
|
||||
e.id === id ? { ...e, ...event } : e
|
||||
),
|
||||
};
|
||||
});
|
||||
|
||||
if (!currentEvent) {
|
||||
return { error: '事件不存在' };
|
||||
}
|
||||
|
||||
// 如果是标记完成,且是重复提醒,自动创建下一周期,并移除当前提醒的重复设置
|
||||
if (event.is_completed && currentEvent.repeat_type !== 'none') {
|
||||
// 从 next_reminder_date 开始查找正确的下一个提醒日期
|
||||
const nextReminderDate = currentEvent.next_reminder_date || currentEvent.date;
|
||||
const nextValidDate = findNextValidReminderDate(
|
||||
nextReminderDate,
|
||||
currentEvent.repeat_type as RepeatType,
|
||||
currentEvent.repeat_interval
|
||||
);
|
||||
|
||||
// 检查是否已存在相同的提醒(去重)
|
||||
const exists = isDuplicateReminder(
|
||||
allEvents,
|
||||
currentEvent.title,
|
||||
nextValidDate,
|
||||
currentEvent.repeat_type as RepeatType
|
||||
);
|
||||
|
||||
if (!exists) {
|
||||
// 计算新提醒的 next_reminder_date
|
||||
const newNextReminderDate = calculateNextReminderDate(
|
||||
nextValidDate,
|
||||
currentEvent.repeat_type as RepeatType,
|
||||
currentEvent.repeat_interval
|
||||
);
|
||||
|
||||
// 创建下一周期的新事件 - 确保所有字段都不包含 undefined
|
||||
const newEventData: Record<string, any> = {
|
||||
type: currentEvent.type,
|
||||
title: currentEvent.title,
|
||||
date: nextValidDate,
|
||||
is_lunar: currentEvent.is_lunar ?? false,
|
||||
repeat_type: currentEvent.repeat_type,
|
||||
// 确保 repeat_interval 为 null 而不是 undefined
|
||||
repeat_interval: currentEvent.repeat_interval ?? null,
|
||||
next_reminder_date: newNextReminderDate,
|
||||
is_holiday: currentEvent.is_holiday ?? false,
|
||||
};
|
||||
// 只有当 content 有值时才包含
|
||||
if (currentEvent.content) {
|
||||
newEventData.content = currentEvent.content;
|
||||
}
|
||||
const newEvent = await api.events.create(newEventData);
|
||||
|
||||
// 添加新事件到本地状态
|
||||
set((state) => ({
|
||||
events: [...state.events, newEvent],
|
||||
}));
|
||||
}
|
||||
|
||||
// 发送 API 请求:标记为已完成并移除重复设置(合并为一个请求)
|
||||
await api.events.update(id, {
|
||||
is_completed: true,
|
||||
repeat_type: 'none',
|
||||
repeat_interval: null,
|
||||
next_reminder_date: null,
|
||||
});
|
||||
|
||||
// 更新本地状态:标记为已完成并移除重复设置
|
||||
set((state) => ({
|
||||
events: state.events.map((e) =>
|
||||
e.id === id
|
||||
? {
|
||||
...e,
|
||||
is_completed: true,
|
||||
repeat_type: 'none',
|
||||
repeat_interval: null,
|
||||
next_reminder_date: null,
|
||||
}
|
||||
: e
|
||||
),
|
||||
}));
|
||||
} else {
|
||||
// 非完成操作,正常发送 API 请求
|
||||
await api.events.update(id, event);
|
||||
}
|
||||
|
||||
return { error: null };
|
||||
} catch (error: any) {
|
||||
// 失败时回滚,重新获取数据
|
||||
|
||||
@ -10,7 +10,8 @@ export interface User {
|
||||
// Event types - for both Anniversary and Reminder
|
||||
export type EventType = 'anniversary' | 'reminder';
|
||||
|
||||
export type RepeatType = 'yearly' | 'monthly' | 'none';
|
||||
// Repeat types: 'daily'每天, 'weekly'每周, 'monthly'每月, 'yearly'每年, 'none'不重复
|
||||
export type RepeatType = 'daily' | 'weekly' | 'monthly' | 'yearly' | 'none';
|
||||
|
||||
// Unified event type (matches backend API)
|
||||
export interface Event {
|
||||
@ -18,12 +19,14 @@ export interface Event {
|
||||
user_id: string;
|
||||
type: EventType;
|
||||
title: string;
|
||||
content?: string; // Only for reminders
|
||||
date: string; // For anniversaries: date, For reminders: reminder time
|
||||
content?: string; // Only for reminders
|
||||
date: string; // 当前提醒日期(展示用)
|
||||
is_lunar: boolean;
|
||||
repeat_type: RepeatType;
|
||||
is_holiday?: boolean; // Only for anniversaries
|
||||
is_completed?: boolean; // Only for reminders
|
||||
repeat_interval?: number | null; // 周数间隔(仅 weekly 类型使用)
|
||||
next_reminder_date?: string | null; // 下一次提醒日期(计算用)
|
||||
is_holiday?: boolean; // Only for anniversaries
|
||||
is_completed?: boolean; // Only for reminders
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
}
|
||||
|
||||
233
src/utils/repeatCalculator.ts
Normal file
233
src/utils/repeatCalculator.ts
Normal file
@ -0,0 +1,233 @@
|
||||
import type { Event, RepeatType } from '../types';
|
||||
|
||||
/**
|
||||
* 计算下一个重复周期日期(单步计算)
|
||||
* @param currentDate 当前日期(ISO 格式)
|
||||
* @param repeatType 重复类型
|
||||
* @param interval 周数间隔(仅 weekly 类型使用,默认1)
|
||||
* @returns 下一次提醒日期(ISO 格式,本地时间)
|
||||
*/
|
||||
export function calculateNextDueDate(
|
||||
currentDate: string,
|
||||
repeatType: RepeatType,
|
||||
interval: number = 1
|
||||
): string {
|
||||
const date = new Date(currentDate);
|
||||
const year = date.getFullYear();
|
||||
const month = date.getMonth();
|
||||
const day = date.getDate();
|
||||
const hours = date.getHours();
|
||||
const minutes = date.getMinutes();
|
||||
|
||||
switch (repeatType) {
|
||||
case 'daily':
|
||||
// 每天:加1天
|
||||
return new Date(year, month, day + 1, hours, minutes).toISOString();
|
||||
|
||||
case 'weekly':
|
||||
// 每周:加7天 * interval
|
||||
return new Date(year, month, day + 7 * interval, hours, minutes).toISOString();
|
||||
|
||||
case 'monthly':
|
||||
// 每月:下月同日
|
||||
const nextMonth = new Date(year, month + 1, day, hours, minutes);
|
||||
// 处理月末日期(如3月31日 -> 4月30日)
|
||||
if (nextMonth.getDate() !== day) {
|
||||
return new Date(year, month + 1, 0, hours, minutes).toISOString();
|
||||
}
|
||||
return nextMonth.toISOString();
|
||||
|
||||
case 'yearly':
|
||||
// 每年:明年同日
|
||||
const nextYearDate = new Date(year + 1, month, day, hours, minutes);
|
||||
// 处理闰年(如2月29日 -> 2月28日)
|
||||
if (nextYearDate.getMonth() !== month) {
|
||||
return new Date(year + 1, month, 0, hours, minutes).toISOString();
|
||||
}
|
||||
return nextYearDate.toISOString();
|
||||
|
||||
case 'none':
|
||||
default:
|
||||
// 不重复:返回原日期
|
||||
return currentDate;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算给定日期的下一次提醒日期
|
||||
* 用于创建新提醒时设置 next_reminder_date
|
||||
* @param date 当前提醒日期
|
||||
* @param repeatType 重复类型
|
||||
* @param interval 周数间隔
|
||||
*/
|
||||
export function calculateNextReminderDate(
|
||||
date: string,
|
||||
repeatType: RepeatType,
|
||||
interval?: number | null
|
||||
): string | null {
|
||||
if (repeatType === 'none' || repeatType === undefined) {
|
||||
return null;
|
||||
}
|
||||
return calculateNextDueDate(date, repeatType, interval ?? 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找正确的下一个提醒日期
|
||||
* 从 nextReminderDate 开始循环,直到找到 >= referenceDate 的日期
|
||||
* @param nextReminderDate 下一次提醒日期(ISO 格式)
|
||||
* @param repeatType 重复类型
|
||||
* @param interval 周数间隔
|
||||
* @param referenceDate 参考日期(通常为当前日期),默认当前时间
|
||||
* @returns 正确的下一个提醒日期(ISO 格式)
|
||||
*/
|
||||
export function findNextValidReminderDate(
|
||||
nextReminderDate: string,
|
||||
repeatType: RepeatType,
|
||||
interval?: number | null,
|
||||
referenceDate?: Date
|
||||
): string {
|
||||
if (repeatType === 'none') {
|
||||
return nextReminderDate;
|
||||
}
|
||||
|
||||
const refDate = referenceDate ?? new Date();
|
||||
let currentNextDate = new Date(nextReminderDate);
|
||||
let loopCount = 0;
|
||||
const maxLoops = 366; // 防止无限循环
|
||||
|
||||
// 循环直到找到 >= referenceDate 的日期
|
||||
while (currentNextDate < refDate && loopCount < maxLoops) {
|
||||
currentNextDate = new Date(calculateNextDueDate(
|
||||
currentNextDate.toISOString(),
|
||||
repeatType,
|
||||
interval ?? 1
|
||||
));
|
||||
loopCount++;
|
||||
}
|
||||
|
||||
return currentNextDate.toISOString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否已存在相同的提醒(去重)
|
||||
* 条件:title + date + repeat_type 完全相同
|
||||
*/
|
||||
export function isDuplicateReminder(
|
||||
events: Event[],
|
||||
title: string,
|
||||
date: string,
|
||||
repeatType: RepeatType
|
||||
): boolean {
|
||||
const normalizedTitle = title.trim();
|
||||
const normalizedDate = new Date(date).toISOString();
|
||||
|
||||
return events.some(event => {
|
||||
// 只检查未完成的提醒
|
||||
if (event.is_completed) return false;
|
||||
|
||||
return (
|
||||
event.title.trim() === normalizedTitle &&
|
||||
new Date(event.date).toISOString() === normalizedDate &&
|
||||
event.repeat_type === repeatType
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为重复提醒
|
||||
*/
|
||||
export function isRecurring(event: Event): boolean {
|
||||
return event.repeat_type !== 'none';
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断提醒是否已逾期(精确到时间点)
|
||||
*/
|
||||
export function isOverdue(event: Event): boolean {
|
||||
if (!event.date) return false;
|
||||
return new Date(event.date) < new Date();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取重复类型的显示名称
|
||||
*/
|
||||
export function getRepeatTypeLabel(type: RepeatType): string {
|
||||
const labels: Record<RepeatType, string> = {
|
||||
daily: '每天',
|
||||
weekly: '每周',
|
||||
monthly: '每月',
|
||||
yearly: '每年',
|
||||
none: '不重复',
|
||||
};
|
||||
return labels[type] || '不重复';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取重复类型的描述
|
||||
*/
|
||||
export function getRepeatTypeDescription(type: RepeatType): string {
|
||||
const descriptions: Record<RepeatType, string> = {
|
||||
daily: '每天同一时间提醒',
|
||||
weekly: '每周同一时间提醒',
|
||||
monthly: '每月同一日期提醒',
|
||||
yearly: '每年同一日期提醒',
|
||||
none: '仅提醒一次',
|
||||
};
|
||||
return descriptions[type] || '仅提醒一次';
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断时间是否在今天范围内
|
||||
*/
|
||||
export function isToday(dateStr: string): boolean {
|
||||
const date = new Date(dateStr);
|
||||
const today = new Date();
|
||||
return date.toDateString() === today.toDateString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断时间是否在明天范围内
|
||||
*/
|
||||
export function isTomorrow(dateStr: string): boolean {
|
||||
const date = new Date(dateStr);
|
||||
const tomorrow = new Date();
|
||||
tomorrow.setDate(tomorrow.getDate() + 1);
|
||||
return date.toDateString() === tomorrow.toDateString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取日期的显示格式
|
||||
* @param dateStr ISO 日期字符串
|
||||
* @param showTime 是否显示时间
|
||||
*/
|
||||
export function formatDateDisplay(dateStr: string, showTime: boolean = true): string {
|
||||
const date = new Date(dateStr);
|
||||
const hours = date.getHours();
|
||||
const minutes = date.getMinutes();
|
||||
|
||||
// 检查是否为默认时间(00:00)
|
||||
const hasTime = hours !== 0 || minutes !== 0;
|
||||
|
||||
if (!hasTime) {
|
||||
// 只显示日期
|
||||
return date.toLocaleString('zh-CN', {
|
||||
month: 'numeric',
|
||||
day: 'numeric',
|
||||
});
|
||||
}
|
||||
|
||||
if (showTime) {
|
||||
return date.toLocaleString('zh-CN', {
|
||||
month: 'numeric',
|
||||
day: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
hour12: false,
|
||||
});
|
||||
}
|
||||
|
||||
return date.toLocaleString('zh-CN', {
|
||||
month: 'numeric',
|
||||
day: 'numeric',
|
||||
});
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user