11import { useState , useEffect , useRef } from 'react' ;
22import { motion , AnimatePresence } from 'framer-motion' ;
3- import { FiMenu , FiX , FiSettings , FiMoon , FiSun , FiUser , FiMaximize , FiMinimize , FiEdit , FiSave , FiGlobe , FiPlus } from 'react-icons/fi' ;
3+ import { FiMenu , FiX , FiSettings , FiMoon , FiSun , FiUser , FiMaximize , FiMinimize , FiEdit , FiSave , FiGlobe , FiPlus , FiShare2 } from 'react-icons/fi' ;
44import { useTimers } from '../../context/TimerContext' ;
55import { useTheme } from '../../context/ThemeContext' ;
66import { useTranslation } from '../../hooks/useTranslation' ;
77import LoginModal from '../UI/LoginModal' ;
8+ import ShareModal from '../UI/ShareModal' ;
89import TimerTypeModal from '../UI/TimerTypeModal' ;
910import AddTimerModal from '../UI/AddTimerModal' ;
1011import AddStopwatchModal from '../UI/AddStopwatchModal' ;
@@ -18,6 +19,7 @@ export default function Header() {
1819 const [ isMenuOpen , setIsMenuOpen ] = useState ( false ) ;
1920 const [ isManageOpen , setIsManageOpen ] = useState ( false ) ;
2021 const [ isLoginOpen , setIsLoginOpen ] = useState ( false ) ;
22+ const [ isShareOpen , setIsShareOpen ] = useState ( false ) ;
2123 const [ isFullscreen , setIsFullscreen ] = useState ( false ) ;
2224 const [ editingTimer , setEditingTimer ] = useState ( null ) ;
2325 const [ showColorPicker , setShowColorPicker ] = useState ( false ) ;
@@ -483,6 +485,20 @@ export default function Header() {
483485 < FiPlus className = "text-xl" />
484486 </ button >
485487
488+ { /* 分享按钮 */ }
489+ < button
490+ className = "p-2 rounded-full hover:bg-gray-100 dark:hover:bg-gray-800 text-gray-700 dark:text-gray-300 cursor-pointer"
491+ onClick = { ( ) => {
492+ setIsShareOpen ( true ) ;
493+ if ( window . location . hash !== '#share' ) {
494+ window . location . hash = 'share' ;
495+ }
496+ } }
497+ data-umami-event = { t ( 'timer.share' ) }
498+ >
499+ < FiShare2 className = "text-xl" />
500+ </ button >
501+
486502 { /* 全屏按钮 */ }
487503 < button
488504 className = "p-2 rounded-full hover:bg-gray-100 dark:hover:bg-gray-800 text-gray-700 dark:text-gray-300 cursor-pointer"
@@ -625,7 +641,7 @@ export default function Header() {
625641
626642 { /* 添加"添加计时器"按钮 */ }
627643 < button
628- className = "flex items-center justify-between p-3 rounded-lg col-span-2 bg-white/10 dark:bg-black/10 backdrop-blur-sm border border-gray-200/60 dark:border-white/10 text-gray-700 dark:text-gray-300 hover:bg-white/20 dark:hover:bg-black/20 cursor-pointer transition-colors"
644+ className = "flex items-center justify-between p-3 rounded-lg bg-white/10 dark:bg-black/10 backdrop-blur-sm border border-gray-200/60 dark:border-white/10 text-gray-700 dark:text-gray-300 hover:bg-white/20 dark:hover:bg-black/20 cursor-pointer transition-colors"
629645 onClick = { ( ) => {
630646 setIsTimerTypeModalOpen ( true ) ;
631647 setIsMenuOpen ( false ) ;
@@ -638,6 +654,22 @@ export default function Header() {
638654 < FiPlus className = "text-xl" />
639655 < span className = "text-xs ml-2 flex-1 text-right" > { t ( 'timer.create' ) } </ span >
640656 </ button >
657+
658+ { /* 添加"分享"按钮 */ }
659+ < button
660+ className = "flex items-center justify-between p-3 rounded-lg bg-white/10 dark:bg-black/10 backdrop-blur-sm border border-gray-200/60 dark:border-white/10 text-gray-700 dark:text-gray-300 hover:bg-white/20 dark:hover:bg-black/20 cursor-pointer transition-colors"
661+ onClick = { ( ) => {
662+ setIsShareOpen ( true ) ;
663+ setIsMenuOpen ( false ) ;
664+ if ( window . location . hash !== '#share' ) {
665+ window . location . hash = 'share' ;
666+ }
667+ } }
668+ data-umami-event = { t ( 'timer.share' ) }
669+ >
670+ < FiShare2 className = "text-xl" />
671+ < span className = "text-xs ml-2 flex-1 text-right" > { t ( 'timer.share' ) } </ span >
672+ </ button >
641673 </ div >
642674 </ div >
643675
@@ -944,6 +976,18 @@ export default function Header() {
944976 < AddWorldClockModal onClose = { closeAllModals } />
945977 ) }
946978 </ AnimatePresence >
979+
980+ { /* 分享模态框 */ }
981+ < AnimatePresence >
982+ { isShareOpen && (
983+ < ShareModal onClose = { ( ) => {
984+ setIsShareOpen ( false ) ;
985+ if ( window . location . hash === '#share' ) {
986+ window . location . hash = '' ;
987+ }
988+ } } />
989+ ) }
990+ </ AnimatePresence >
947991 </ header >
948992 ) ;
949993}
0 commit comments