Schedule Work Session
<%* // ======================================== // ๐ฟ 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 ≥ {
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 = ""; %>