Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a task progress indicator to notes in board view #897

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/ui/views/Board/components/Board/CardList.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<script lang="ts">
// import { Checkbox, InternalLink} from "obsidian-svelte";
import { Checkbox } from "obsidian-svelte";
import { Checkbox, Icon } from "obsidian-svelte";
import InternalLink from "src/ui/components/InternalLink.svelte";

import {
isString,
type DataField,
Expand All @@ -23,7 +22,7 @@
dndzone,
} from "svelte-dnd-action";
import { flip } from "svelte/animate";
import { getDisplayName } from "./boardHelpers";
import { getDisplayName, getTaskProgress } from "./boardHelpers";
import type {
DropTrigger,
OnRecordClick,
Expand Down Expand Up @@ -141,13 +140,22 @@
{/if}
</div>
<CardMetadata fields={includeFields} record={item} />
{#await getTaskProgress(item.id, $app) then taskProgress}
{#if taskProgress}
<div class="task-progress-heading">
<Icon name="check-circle" />
<span>{taskProgress}</span>
</div>
{/if}
{/await}
</ColorItem>
</article>
{/each}
</div>

<style>
div.card-header {
div.card-header,
div.task-progress-heading {
display: flex;
gap: 4px;
align-items: center;
Expand Down
23 changes: 23 additions & 0 deletions src/ui/views/Board/components/Board/boardHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { App } from "obsidian";

export function getDisplayName(recordId: string): string {
const basename = getBasename(recordId);
return basename.slice(0, basename.lastIndexOf("."));
Expand All @@ -13,3 +15,24 @@ function getBasename(str: string) {

return str.slice(lastSlash + 1);
}

export async function getTaskProgress(
recordId: string,
app: App
): Promise<string> {
let progress = "";

const file = app.vault.getFileByPath(recordId);
if (file) {
const totalTasks = app.metadataCache
.getFileCache(file)
?.listItems?.filter((item) => item.task !== undefined);

if (totalTasks) {
Copy link
Contributor Author

@H3mul H3mul Jun 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

totalTasks is an empty array in the present cache but no tasks case; empty arrays are true in js. Fixed

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

const completedTasks = totalTasks?.filter((item) => item.task !== " ");
progress = `${completedTasks.length}/${totalTasks.length}`;
}
}

return progress;
}
Loading