<%* // ======================================== // ๐ŸŒฟ STUDY NOOK: SCHEDULE WORK SESSION // ========================================

// Find unfinished assignments const folder = "study nook/School/Assignments";

const assignments = app.vault.getMarkdownFiles() .filter(file โ‰ฅ file.path.startsWith(folder + "/")) .filter(file โ‰ฅ { const data = app.metadataCache .getFileCache(file)?.frontmatter || {};

const status = String(data.status || "")
  .trim()
  .toLowerCase();

return !["done", "complete", "completed"]
  .includes(status) && data.completed !== true;

}) .sort((a, b) โ‰ฅ a.basename.localeCompare(b.basename));

if (assignments.length === 0) { new Notice("๐ŸŒธ No unfinished assignments found!"); return; }

// 1. Select an assignment const selected = await tp.system.suggester( assignments.map(file โ‰ฅ file.basename), assignments, false, "๐ŸŒฟ Which assignment would you like to schedule?" );

if (!selected) return;

// 2. Choose the workday const defaultDate = window.moment() .format("MM/DD/YY");

const input = await tp.system.prompt( "๐Ÿ“… Work session date (MM/DD/YY)", defaultDate );

if (!input) return;

const date = window.moment( input.trim(), "MM/DD/YY", true );

if (!date.isValid()) { new Notice("๐ŸŒธ Please enter a valid MM/DD/YY date."); return; }

// Keep dates in the familiar display format const workDate = date.format("MM/DD/YY");

// 3. Add the date to the existing work_days list let alreadyScheduled = false;

await app.fileManager.processFrontMatter( selected, frontmatter โ‰ฅ {

const existing = frontmatter.work_days || [];

const days = Array.isArray(existing)
  ? [...existing]
  : [existing];

// Normalize for comparison
const normalized = days.map(value &ge; {
  const parsed = window.moment(
    String(value),
    ["MM/DD/YY", "MM/DD/YYYY", "YYYY-MM-DD"],
    true
  );

  return parsed.isValid()
    ? parsed.format("YYYY-MM-DD")
    : String(value);
});

if (normalized.includes(date.format("YYYY-MM-DD"))) {
  alreadyScheduled = true;
  return;
}

days.push(workDate);

frontmatter.work_days = days;

} );

// 4. Confirmation if (alreadyScheduled) { new Notice("๐ŸŒท This assignment is already scheduled for that day."); } else { new Notice( "๐ŸŒฟ Scheduled " + selected.basename + " for " + date.format("MMMM D") + "!" ); }

// Don't insert text into the dashboard tR = ""; %>

Built with LogoFlowershow