Skip to content

Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.

add functions for handling task descriptions and excerpts

Khuram Niazd4d42f03bc81
diff --git a/__tests__/taskDescription.spec.ts b/__tests__/taskDescription.spec.ts
new file mode 100644
index 0000000..6d59072
--- /dev/null
+++ b/__tests__/taskDescription.spec.ts
@@ -0,0 +1,79 @@
+import { describe, expect, it } from "vitest";
+import {
+ getDescriptionExcerpt,
+ hasDescription,
+ toPlainText,
+} from "@/lib/tasks/description";
+
+describe("toPlainText", () => {
+ it("returns empty string for null/undefined/empty input", () => {
+ expect(toPlainText(null)).toBe("");
+ expect(toPlainText(undefined)).toBe("");
+ expect(toPlainText("")).toBe("");
+ });
+
+ it("strips tags and collapses whitespace", () => {
+ expect(toPlainText("<p>Call <strong>Jane</strong> back</p>")).toBe(
+ "Call Jane back",
+ );
+ });
+
+ it("joins block-level content with a space", () => {
+ expect(toPlainText("<p>First</p><p>Second</p>")).toBe("First Second");
+ });
+
+ it("decodes non-breaking spaces to whitespace", () => {
+ expect(toPlainText("<p>a&nbsp;b</p>")).toBe("a b");
+ });
+});
+
+describe("hasDescription", () => {
+ it("is false for the empty Tiptap document", () => {
+ expect(hasDescription("<p></p>")).toBe(false);
+ });
+
+ it("is false for a whitespace-only Tiptap document", () => {
+ expect(hasDescription("<p>&nbsp;</p>")).toBe(false);
+ expect(hasDescription("<p> </p>")).toBe(false);
+ });
+
+ it("is false for null/undefined/empty input", () => {
+ expect(hasDescription(null)).toBe(false);
+ expect(hasDescription(undefined)).toBe(false);
+ expect(hasDescription("")).toBe(false);
+ });
+
+ it("is true when there is real content", () => {
+ expect(hasDescription("<p>Prep interview notes</p>")).toBe(true);
+ });
+
+ it("is true for content held only in a list item", () => {
+ expect(hasDescription("<ul><li>Follow up</li></ul>")).toBe(true);
+ });
+});
+
+describe("getDescriptionExcerpt", () => {
+ it("returns the full text when under the limit", () => {
+ expect(getDescriptionExcerpt("<p>Short note</p>")).toBe("Short note");
+ });
+
+ it("returns text untruncated at exactly the limit", () => {
+ const text = "a".repeat(200);
+ expect(getDescriptionExcerpt(`<p>${text}</p>`)).toBe(text);
+ });
+
+ it("truncates and appends an ellipsis past the limit", () => {
+ const excerpt = getDescriptionExcerpt(`<p>${"a".repeat(201)}</p>`);
+ expect(excerpt).toBe(`${"a".repeat(200)}…`);
+ expect(excerpt).toHaveLength(201);
+ });
+
+ it("does not leave a dangling space before the ellipsis", () => {
+ const html = `<p>${"a".repeat(199)} trailing words</p>`;
+ expect(getDescriptionExcerpt(html)).toBe(`${"a".repeat(199)}…`);
+ });
+
+ it("returns empty string for an empty description", () => {
+ expect(getDescriptionExcerpt("<p></p>")).toBe("");
+ });
+});
diff --git a/src/components/tasks/TasksTable.tsx b/src/components/tasks/TasksTable.tsx
index b9cd351..0731ae4 100644
--- a/src/components/tasks/TasksTable.tsx
+++ b/src/components/tasks/TasksTable.tsx
@@ -18,7 +18,14 @@ import {
ArrowRight,
ArrowUp,
Flame,
+ AlignLeft,
} from "lucide-react";
+import {
+ Tooltip,
+ TooltipContent,
+ TooltipProvider,
+ TooltipTrigger,
+} from "../ui/tooltip";
import { cn } from "@/lib/utils";
import { StatusBadge } from "../StatusBadge";
import { TASK_STATUS_BADGE_COLORS } from "@/lib/badge-colors";
@@ -52,6 +59,7 @@ import {
TaskStatus,
} from "@/models/task.model";
import { DeleteAlertDialog } from "../DeleteAlertDialog";
+import { getDescriptionExcerpt, hasDescription } from "@/lib/tasks/description";
type TasksTableProps = {
tasks: Task[];
@@ -237,13 +245,29 @@ function TasksTable({
task.status === "complete" && "line-through",
)}
>
- <button
- onClick={() => editTask(task.id)}
- className="text-left hover:underline cursor-pointer"
- aria-label={`Edit ${task.title}`}
- >
- {task.title}
- </button>
+ <span className="inline-flex items-center gap-1.5">
+ <button
+ onClick={() => editTask(task.id)}
+ className="text-left hover:underline cursor-pointer"
+ aria-label={`Edit ${task.title}`}
+ >
+ {task.title}
+ </button>
+ {hasDescription(task.description) && (
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <AlignLeft
+ className="h-3.5 w-3.5 shrink-0 text-muted-foreground"
+ aria-label="Has description"
+ data-testid="task-description-indicator"
+ />
+ </TooltipTrigger>
+ <TooltipContent className="max-w-sm text-xs">
+ {getDescriptionExcerpt(task.description)}
+ </TooltipContent>
+ </Tooltip>
+ )}
+ </span>
</TableCell>
<TableCell className="py-1 px-2">
{task.activityType?.label || "—"}
@@ -386,7 +410,7 @@ function TasksTable({
);
const renderGroupedTables = (entries: [string, Task[]][]) => (
- <>
+ <TooltipProvider delayDuration={300}>
{entries.map(([label, groupTasks]) => (
<div key={label} className="mb-6">
<h3 className="text-sm font-semibold mb-2 px-2 py-1">
@@ -404,7 +428,7 @@ function TasksTable({
onOpenChange={setAlertOpen}
onDelete={() => deleteTask(taskIdToDelete)}
/>
- </>
+ </TooltipProvider>
);
const formatDateLabel = (dateStr: string) => {
@@ -457,7 +481,7 @@ function TasksTable({
}
return (
- <>
+ <TooltipProvider delayDuration={300}>
<Table>
{renderTableHeader()}
<TableBody>{tasks.map(renderTaskRow)}</TableBody>
@@ -468,7 +492,7 @@ function TasksTable({
onOpenChange={setAlertOpen}
onDelete={() => deleteTask(taskIdToDelete)}
/>
- </>
+ </TooltipProvider>
);
}
diff --git a/src/lib/tasks/description.ts b/src/lib/tasks/description.ts
new file mode 100644
index 0000000..e808cc3
--- /dev/null
+++ b/src/lib/tasks/description.ts
@@ -0,0 +1,23 @@
+// Task descriptions are Tiptap HTML, so an "empty" one is "" or "<p></p>"
+const EXCERPT_MAX_LENGTH = 200;
+
+export function toPlainText(html?: string | null): string {
+ if (!html) return "";
+
+ return html
+ .replace(/<[^>]+>/g, " ")
+ .replace(/&nbsp;/g, " ")
+ .replace(/\s+/g, " ")
+ .trim();
+}
+
+export function hasDescription(html?: string | null): boolean {
+ return toPlainText(html).length > 0;
+}
+
+export function getDescriptionExcerpt(html?: string | null): string {
+ const text = toPlainText(html);
+ if (text.length <= EXCERPT_MAX_LENGTH) return text;
+
+ return `${text.slice(0, EXCERPT_MAX_LENGTH).trimEnd()}…`;
+}