Skip to content

Commit

Permalink
feat(agenda3): ✨ refresh data when the page is focused
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenull committed Nov 6, 2023
1 parent a02393f commit b686486
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/pages/NewDashboard/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Analytics } from '@vercel/analytics/react'
import { FloatButton, Modal, message } from 'antd'
import { useAtom, useAtomValue, useSetAtom } from 'jotai'
import { Modal, message } from 'antd'
import { useAtomValue, useSetAtom } from 'jotai'
import { useEffect, useState } from 'react'
import { TbComet, TbSettings } from 'react-icons/tb'

import useAgendaTasks from '@/hooks/useAgendaTasks'
import useNewProjects from '@/hooks/useNewProjects'
Expand All @@ -13,7 +12,8 @@ import Backlog from './components/Backlog'
import MultipleView from './components/MultipleView'
import ProjectSidebar from './components/ProjectSidebar'
import TimeBox from './components/TimeBox'
import TimeBoxActual from './components/TimeBoxActual'

// import TimeBoxActual from './components/TimeBoxActual'

export type TimeBoxType = 'estimated' | 'actual'
const Dashboard = () => {
Expand All @@ -24,15 +24,29 @@ const Dashboard = () => {
const { refreshProjects } = useNewProjects()
const [connectionErrorModal, setConnectionErrorModal] = useState(false)

// get tasks and projects
useEffect(() => {
const loadData = async () => {
refreshTasks().catch(() => {
setConnectionErrorModal(true)
})
refreshProjects()
// logseq.App.getCurrentGraph().then((res) => {
// console.log('getUserConfigs', res)
// })
}
// get tasks and projects
useEffect(() => {
const handleWindowFocus = () => {
// 在浏览器获得焦点时刷新数据
loadData()
}
// 添加窗口焦点事件监听器
window.addEventListener('focus', handleWindowFocus)
// 在页面初次加载时刷新数据
loadData()
// 在组件卸载时移除事件监听器
return () => {
window.removeEventListener('focus', handleWindowFocus)
}
}, [])
// set logseq app and user info
useEffect(() => {
Expand Down

0 comments on commit b686486

Please sign in to comment.