Skip to content

Commit

Permalink
feat: ✨ Review page supports jumping to block
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenull committed Dec 7, 2022
1 parent cf37300 commit 836f6d2
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 25 deletions.
23 changes: 3 additions & 20 deletions src/components/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { deleteProjectTaskTime, updateProjectTaskTime } from '@/util/schedule'
import ModifySchedule, { IScheduleValue } from '@/components/ModifySchedule'
import Sidebar from '@/components/Sidebar'
import dayjs from 'dayjs'
import { joinPrefixTaskBlockContent, moveBlockToNewPage, moveBlockToSpecificBlock } from '@/util/logseq'
import { joinPrefixTaskBlockContent, moveBlockToNewPage, moveBlockToSpecificBlock, navToBlock, navToPage } from '@/util/logseq'
import { Button, Modal, Segmented, Tooltip } from 'antd'
import { LeftOutlined, RightOutlined, MenuFoldOutlined, MenuUnfoldOutlined } from '@ant-design/icons'
import { ICustomCalendar } from '@/util/type'
Expand Down Expand Up @@ -142,28 +142,11 @@ const CalendarCom: React.FC<{
calendarRef.current.on('clickSchedule', function(info) {
document.querySelector('#faiz-nav-detail')?.addEventListener('click', async (e) => {
const rawData = info.schedule.raw || {}
const { id: pageId, originalName } = rawData?.page || {}
let pageName = originalName
// datascriptQuery 查询出的 block, 没有详细的 page 属性, 需要手动查询
if (!pageName) {
const page = await logseq.Editor.getPage(pageId)
pageName = page?.originalName
}
const { uuid: blockUuid } = await logseq.Editor.getBlock(rawData.id) || { uuid: '' }
logseq.Editor.scrollToBlockInPage(pageName, blockUuid)
logseq.hideMainUI()
navToBlock(rawData)
}, { once: true })
document.querySelector('#faiz-nav-detail-project')?.addEventListener('click', async (e) => {
const rawData = info.schedule.raw || {}
const { id: pageId, originalName } = rawData?.page || {}
let pageName = originalName
// datascriptQuery 查询出的 block, 没有详细的 page 属性, 需要手动查询
if (!pageName) {
const page = await logseq.Editor.getPage(pageId)
pageName = page?.originalName
}
logseq.App.pushState('page', { name: pageName })
logseq.hideMainUI()
navToPage(rawData)
}, { once: true })
})
calendarRef.current.on('beforeCreateSchedule', function(event) {
Expand Down
2 changes: 1 addition & 1 deletion src/helper/transform.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const transformTaskEventToSchedule = (block: IEvent) => {

return {
id: block.uuid,
calendarId: block.addOns.isJournal ? 'Journal' : block.addOns.project,
calendarId: block.addOns.project,
title: block.addOns.showTitle,
body: block.content,
category,
Expand Down
10 changes: 6 additions & 4 deletions src/pages/Review/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { IPomodoroInfo } from '@/helper/pomodoro'
import { copyToClipboard, extractDays } from '@/util/util'
import MixLineBar from './components/MixLineBar'
import TreeMap from './components/TreeMap'
import { navToBlock, navToPage } from '@/util/logseq'


const filterEvents = (rawEvents: IEvent[], filter: IReviewSearchForm) => {
Expand Down Expand Up @@ -117,7 +118,7 @@ const index = () => {
<h1 className="title-text">Review</h1>
<div className="bg-quaternary flex-1 rounded-2xl box-border p-6 overflow-auto">
<SearchForm onSearch={onSearch} initialValues={filter} />
<Table
<Table<IEvent>
dataSource={events}
title={() => (
<div className="flex justify-end">
Expand All @@ -136,13 +137,14 @@ const index = () => {
{
title: 'Title',
dataIndex: ['addOns', 'showTitle'],
width: '240px',
ellipsis: true,
render: (title, record) => <a onClick={() => navToBlock(record)}>{title}</a>,
},
{
title: 'Project',
dataIndex: ['page', 'original-name'],
render: (value, record) => record.addOns.isJournal ? 'Journal' : value,
dataIndex: ['addOns', 'project'],
ellipsis: true,
render: (title, record) => <a onClick={() => navToPage(record)}>{title}</a>,
},
{
title: 'Date',
Expand Down
4 changes: 4 additions & 0 deletions src/style/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ a {
color: var(--ls-tertiary-background-color);
cursor: pointer;
}
a:hover {
color: var(--ls-tertiary-background-color);
cursor: pointer;
}

.page-container {
width: calc(100vw - 90px);
Expand Down
24 changes: 24 additions & 0 deletions src/util/logseq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,28 @@ export const genDBTaskChangeCallback = (cb: (uuid: string) => void, delay = 2000
}
}, delay))
}
}

export const navToBlock = async (block: BlockEntity) => {
const { id: pageId, originalName } = block?.page || {}
let pageName = originalName
// datascriptQuery 查询出的 block, 没有详细的 page 属性, 需要手动查询
if (!pageName) {
const page = await logseq.Editor.getPage(pageId)
pageName = page?.originalName
}
const { uuid: blockUuid } = await logseq.Editor.getBlock(block.id) || { uuid: '' }
logseq.Editor.scrollToBlockInPage(pageName, blockUuid)
logseq.hideMainUI()
}
export const navToPage = async (block: BlockEntity) => {
const { id: pageId, originalName } = block?.page || {}
let pageName = originalName
// datascriptQuery 查询出的 block, 没有详细的 page 属性, 需要手动查询
if (!pageName) {
const page = await logseq.Editor.getPage(pageId)
pageName = page?.originalName
}
logseq.App.pushState('page', { name: pageName })
logseq.hideMainUI()
}

0 comments on commit 836f6d2

Please sign in to comment.