Skip to content

Commit

Permalink
feat: supports slash command: insert today's task
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenull committed May 13, 2022
1 parent de666b8 commit 24a6aba
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
22 changes: 19 additions & 3 deletions src/components/TodayTaskModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { todayTasksAtom } from '@/model/schedule'
import { getBlockData } from '@/util/logseq'
import { BlockEntity } from '@logseq/libs/dist/LSPlugin.user'
import { Modal, Checkbox, Divider, Row, Col } from 'antd'
import { useAtom } from 'jotai'
import React, { useEffect, useState } from 'react'
Expand All @@ -25,8 +27,22 @@ const TodayTaskModal: React.FC<{
setValue(options.map(option => option.value))
}
}
const onClickOk = () => {
// const txt = value.map((id) => {
const onClickOk = async () => {
let blockList: BlockEntity[] = []
for (let i = 0; i < value.length; i++) {
const block = await getBlockData({ id: Number(value[i]?.replace('overdue-', '')) })
blockList.push(block)
}
logseq.Editor.insertBatchBlock(
uuid,
blockList.map((block) => ({
content: `((${block?.uuid}))`,
})),
{
before: false,
sibling: true,
}
)
onSave()
}

Expand All @@ -39,7 +55,7 @@ const TodayTaskModal: React.FC<{
}
}, [value?.length, options?.length])

console.log('[faiz:] === options', options, tasks)
console.log('[faiz:] === options', options, tasks, uuid)

return (
<Modal
Expand Down
2 changes: 1 addition & 1 deletion src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ if (isDevelopment) {
}
logseq.showMainUI()
})
logseq.Editor.registerSlashCommand("Agenda: Insert Today Tasks", (e) => {
logseq.Editor.registerSlashCommand("Agenda: Insert Today's Task", (e) => {
console.log('[faiz:] === registerSlashCommand', e)
renderModalApp({
type: 'insertTodaySchedule',
Expand Down

0 comments on commit 24a6aba

Please sign in to comment.