Skip to content

Commit

Permalink
refactor(block.ts): insert scheduled string as the second line in a b…
Browse files Browse the repository at this point in the history
…lock
  • Loading branch information
e-zz committed Apr 7, 2024
1 parent 77b144d commit da770d5
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/Agenda3/helpers/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ import { updateBlock } from '@/util/logseq'
import { secondsToHHmmss } from './fullCalendar'
import type { BlockFromQuery } from './task'

/**
* insert `<SCHEDULED: ...>` string into a block without any `<SCHEDULED: ...>` string
*/
const insertScheduled = (content: string, scheduled: string) => {
if (/^SCHEDULED: </gm.test(content)) return content // make sure the task hasn't been scheduled yet (prevent duplicate)

// Split the content into lines
const [firstLine, ...restLines] = content.split('\n')

// Insert the scheduled string as the second line of the content
return [firstLine, scheduled, ...restLines].join('\n')
}

/**
* change task date and estimated time
*/
Expand Down Expand Up @@ -49,7 +62,7 @@ export const updateBlockDateInfo = async ({
return line
})
.join('\n')
: `${originalBlock.content}\n${scheduledText}`
: insertScheduled(originalBlock.content, scheduledText)
// update estimated time and end date
const newContent2 = updateBlockAgendaDrawer(newContent, {
estimated: estimatedTime,
Expand Down

0 comments on commit da770d5

Please sign in to comment.