From afc3e187f32d8d43f492187c4a6d43b9c75ecc2c Mon Sep 17 00:00:00 2001 From: Hayden Chen Date: Fri, 10 Nov 2023 08:35:16 +0800 Subject: [PATCH] feat(backlog): :sparkles: display the number of tasks in backlog --- src/newHelper/logseq.ts | 13 ++++++++++ src/pages/NewDashboard/components/Backlog.tsx | 21 +++++++++++++--- src/pages/NewDashboard/components/KanBan.tsx | 24 ++++--------------- .../NewDashboard/components/LogseqLogo.tsx | 13 ++++++++++ 4 files changed, 48 insertions(+), 23 deletions(-) create mode 100644 src/newHelper/logseq.ts create mode 100644 src/pages/NewDashboard/components/LogseqLogo.tsx diff --git a/src/newHelper/logseq.ts b/src/newHelper/logseq.ts new file mode 100644 index 0000000..e1d6267 --- /dev/null +++ b/src/newHelper/logseq.ts @@ -0,0 +1,13 @@ +import type { AgendaTask } from '@/types/task' + +export const navToLogseqBlock = (task: AgendaTask, currentGraph?: { name: string }) => { + const uuid = task.recurringPast ? task.id.split('_')[0] : task.id + if (import.meta.env.VITE_MODE === 'plugin') { + logseq.Editor.scrollToBlockInPage(task.project.originalName, uuid) + logseq.hideMainUI() + } else { + if (!currentGraph) return + // example: logseq://graph/zio?block-id=65385ad5-f4e9-4423-8595-a5e4236cc8ad + window.open(`logseq://graph/${currentGraph.name}?block-id=${uuid}`, '_blank') + } +} diff --git a/src/pages/NewDashboard/components/Backlog.tsx b/src/pages/NewDashboard/components/Backlog.tsx index afdd2a9..9952346 100644 --- a/src/pages/NewDashboard/components/Backlog.tsx +++ b/src/pages/NewDashboard/components/Backlog.tsx @@ -2,18 +2,22 @@ import { CaretRightOutlined } from '@ant-design/icons' import { Draggable } from '@fullcalendar/interaction' import { Collapse, Empty, Select } from 'antd' import clsx from 'clsx' -import { useAtom } from 'jotai' +import { useAtom, useAtomValue } from 'jotai' import { useEffect, useRef, useState } from 'react' import { BsArchive } from 'react-icons/bs' +import { navToLogseqBlock } from '@/newHelper/logseq' import { categorizeTasksByPage, formatTaskTitle } from '@/newHelper/task' +import { logseqAtom } from '@/newModel/logseq' import { backlogTasksAtom } from '@/newModel/tasks' +import LogseqLogo from './LogseqLogo' import s from './backlog.module.less' const Backlog = () => { const taskContainerRef = useRef(null) const [backlogTasks] = useAtom(backlogTasksAtom) + const { currentGraph } = useAtomValue(logseqAtom) const categorizedTasks = categorizeTasksByPage(backlogTasks) const projects = categorizedTasks.map(({ project }) => project) @@ -66,9 +70,11 @@ const Backlog = () => { bordered={false} expandIcon={({ isActive }) => } style={{ background: '#f9fafb' }} + defaultActiveKey={showCategorizedTasks.map((project) => project.project.originalName)} items={showCategorizedTasks.map((project) => ({ key: project.project.originalName, label: project.project.originalName, + extra: {project.tasks.length}, children: (
{project.tasks.map((task) => { @@ -76,14 +82,23 @@ const Backlog = () => { return (
- {showTitle} + {showTitle}{' '} + { + e.stopPropagation() + navToLogseqBlock(task, currentGraph) + }} + > + +
) })} diff --git a/src/pages/NewDashboard/components/KanBan.tsx b/src/pages/NewDashboard/components/KanBan.tsx index 0ae71d3..1205900 100644 --- a/src/pages/NewDashboard/components/KanBan.tsx +++ b/src/pages/NewDashboard/components/KanBan.tsx @@ -11,6 +11,7 @@ import { DEFAULT_ESTIMATED_TIME, recentDaysRange } from '@/constants/agenda' import useAgendaTasks from '@/hooks/useAgendaTasks' import { updateDateInfo, updateTaskStatus } from '@/newHelper/block' import { minutesToHHmm } from '@/newHelper/fullCalendar' +import { navToLogseqBlock } from '@/newHelper/logseq' import { DATE_FORMATTER_FOR_KEY, formatTaskTitle, @@ -25,6 +26,7 @@ import { recentTasksAtom } from '@/newModel/tasks' import type { AgendaTaskWithStart, AgendaTask } from '@/types/task' import { cn, genDays, replaceDateInfo } from '@/util/util' +import LogseqLogo from './LogseqLogo' import TaskModal from './TaskModal' export type KanBanItem = AgendaTaskWithStart & { @@ -75,17 +77,6 @@ const KanBan = (props, ref) => { document.getElementById(`${todayDateStr}`)?.scrollIntoView({ block: 'nearest', inline: 'start' }) kanBanContainerRef.current?.scrollBy({ left: -30, behavior: 'smooth' }) }, []) - const navToLogseqBlock = (task: AgendaTaskWithStart) => { - if (!currentGraph) return - const uuid = task.recurringPast ? task.id.split('_')[0] : task.id - if (import.meta.env.VITE_MODE === 'plugin') { - logseq.Editor.scrollToBlockInPage(task.project.originalName, uuid) - logseq.hideMainUI() - } else { - // example: logseq://graph/zio?block-id=65385ad5-f4e9-4423-8595-a5e4236cc8ad - window.open(`logseq://graph/${currentGraph.name}?block-id=${uuid}`, '_blank') - } - } // scroll to today useEffect(() => { @@ -266,17 +257,10 @@ const KanBan = (props, ref) => { className="text-gray-300 opacity-0 group-hover/card:opacity-100 transition-opacity cursor-pointer" onClick={(e) => { e.stopPropagation() - navToLogseqBlock(task) + navToLogseqBlock(task, currentGraph) }} > - {/* logseq logo */} - - - +
diff --git a/src/pages/NewDashboard/components/LogseqLogo.tsx b/src/pages/NewDashboard/components/LogseqLogo.tsx new file mode 100644 index 0000000..3223d48 --- /dev/null +++ b/src/pages/NewDashboard/components/LogseqLogo.tsx @@ -0,0 +1,13 @@ +const LogseqLogo = () => { + return ( + + + + ) +} + +export default LogseqLogo