Get yesterday's note

Hello here!

I could not find anything in the documentation, but it is possible to get yesterday’s note content in my extension?

I would like to build an extension to move all unchecked tasks from yesterday to today :slight_smile:

I don’t believe that’s possible from what I’ve read in the documentation

Correct, that’s not (yet) available. We are working though on enabling accessing other pages than the currently open one.

@balint I’m looking very much forward to be able to query the other documents in the current space. This will enable so many cool extensions!

@victorgdb here’s the code I’m using to do the filtering part:

async function copyAndFilterTheCurrentPage() {
  // Query the page which is currently opened
  const result = await craft.dataApi.getCurrentPage()

  // Check if the query succeeded
  if (result.status !== "success") {
    throw new Error(result.message)
  }

  const pageBlock = result.data
  // Save the data into a global variable

  var blocksToKeep: CraftBlock[] = []

  pageBlock.subblocks.filter(async block => {
    if (block.listStyle.type === "todo" && block.listStyle.state === "checked") {
      return
    } else {
      blocksToKeep.push(block)
    }
  })

  loadedBlocks = blocksToKeep
}

async function paste() {
  const blocks = loadedBlocks
  const result = await craft.dataApi.addBlocks(blocks)

  // Check if the update succeeded
  if (result.status !== "success") {
    throw new Error(result.message)
  }
}

I’m using React/Typescript. I’m just copying/pasting between Today notes as seen here.

Semi-related: When creating a new today note the current note loses focus, and focus is moved to the previous note. You can see them flicker in the gif. That’s some new behavior that just I just noticed this morning.

2021-12-04 11.34.49

1 Like

Wonderful, it’s really straightforward! Thanks mate!

@Leatherbeardy If I recognize this correct, this is exactly what i’m looking for :heart_eyes:. are you willing to (already) share this as a *.craftx ?

1 Like

@trugschluss sure! You can find it here. I had to upload to Google Drive because we can’t upload .craftx files to the forum yet.

Pardon the silly icon & name. I’ll find something more appropriate soon and re-upload & notify.

@balint what’s the best way to share extensions going forward?

1 Like

:astonished: :exploding_head: :partying_face:
great! did this manually each day since weeks…relieving! much thanks man - works perfectly smooth!

one more thing (if you should keep on working on this and following sounds convincing to you):
i used to cut (not copy) the unchecked tasks plus structure, so that i just leave the finished tasks behind. so there is no duplicate blocks (imho better for searching somewhen and to avoid redundancy.)

oh and one more thing i just recognised:
tables are not copied and, according to that, not pasted!

Ah, maybe tables are handled separately. I’ll take a look tomorrow. I can see if I can do cut as well!

1 Like

oh, and i just noticed something else: links aren’t copied aswell…
enjoy your day!

Okay, the new version is up: Todo Filter - Google Drive

I named it “Todo Filter” for now and gave it a better icon.

It now cuts instead of copies.

The API doesn’t seem to copy blocks that are plain links or tables. I’ve filed a bug here.

It does seem to work with links that are part of todo items :thinking:.

Either way, enjoy and let me know if there are any other feature requests, I’ll see what I can do.

Also, I’ll update the thread when I hear back about the tables/links.

Here’s a demo:
2021-12-05 07.50.51

3 Likes

Source is here if anyone wants to contribute: GitHub - IanLeatherbury/todo-filter

thanks a lot! gonna test it instantly! :peacock:

(the copy problems with table/links is too bad. in my daily structure i got both (specially talbes) included…damn… :worried: )

i just tested it.
not sure if you decided consciously for another way (which’d be absolutely alright) or if i expressed myself incorrectly:

now the finished tasks vanish (got cut), but the structure is still there.

i made you a video what i’m doing daily to visualise it:

https://www.craft.do/s/jJXha6j8BVsMQ1

Yep, my bad @trugschluss, 6:30 on a Sunday is not prime brain time for me :sweat_smile:.

Fixed it here, v.02: Todo Filter - Google Drive

EDIT: Found a bug, use v.03 now :slight_smile:

oh my…you’re great!
you made my day, cheers!