Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion apps/code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@
"@posthog/electron-trpc": "workspace:*",
"@posthog/git": "workspace:*",
"@posthog/hedgehog-mode": "^0.0.48",
"@posthog/quill": "0.1.0-alpha.7",
"@posthog/platform": "workspace:*",
"@posthog/quill": "0.1.0-alpha.7",
"@posthog/shared": "workspace:*",
"@radix-ui/react-collapsible": "^1.1.12",
"@radix-ui/react-icons": "^1.3.2",
Expand Down
58 changes: 40 additions & 18 deletions apps/code/src/renderer/features/sidebar/components/TaskListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import { Flex, Text } from "@radix-ui/themes";
import { useWorkspace } from "@renderer/features/workspace/hooks/useWorkspace";
import { normalizeRepoKey } from "@shared/utils/repo";
import { useNavigationStore } from "@stores/navigationStore";
import { useCallback, useEffect } from "react";
import { getRelativeDateGroup } from "@utils/time";
import { Fragment, useCallback, useEffect, useMemo } from "react";
import type { TaskData, TaskGroup } from "../hooks/useSidebarData";
import { useSidebarStore } from "../stores/sidebarStore";
import { DraggableFolder } from "./DraggableFolder";
Expand Down Expand Up @@ -246,6 +247,20 @@ export function TaskListView({
const timestampKey: "lastActivityAt" | "createdAt" =
sortMode === "updated" ? "lastActivityAt" : "createdAt";

const dateGroupedTasks = useMemo(() => {
const groups: { label: string | null; tasks: TaskData[] }[] = [];
for (const task of flatTasks) {
const label = getRelativeDateGroup(task[timestampKey]);
const last = groups[groups.length - 1];
if (last && last.label === label) {
last.tasks.push(task);
} else {
groups.push({ label, tasks: [task] });
}
}
return groups;
}, [flatTasks, timestampKey]);

return (
<Flex direction="column">
{pinnedTasks.length > 0 && (
Expand Down Expand Up @@ -363,23 +378,30 @@ export function TaskListView({
</DragDropProvider>
) : (
<Flex direction="column" gap="1px">
{flatTasks.map((task) => (
<TaskRow
key={task.id}
task={task}
isActive={activeTaskId === task.id}
isEditing={editingTaskId === task.id}
onClick={() => onTaskClick(task.id)}
onDoubleClick={() => onTaskDoubleClick(task.id)}
onContextMenu={(e, isPinned) =>
onTaskContextMenu(task.id, e, isPinned)
}
onArchive={() => onTaskArchive(task.id)}
onTogglePin={() => onTaskTogglePin(task.id)}
onEditSubmit={(newTitle) => onTaskEditSubmit(task.id, newTitle)}
onEditCancel={onTaskEditCancel}
timestamp={task[timestampKey]}
/>
{dateGroupedTasks.map((group) => (
<Fragment key={group.label ?? "today"}>
{group.label && <SectionLabel label={group.label} />}
{group.tasks.map((task) => (
<TaskRow
key={task.id}
task={task}
isActive={activeTaskId === task.id}
isEditing={editingTaskId === task.id}
onClick={() => onTaskClick(task.id)}
onDoubleClick={() => onTaskDoubleClick(task.id)}
onContextMenu={(e, isPinned) =>
onTaskContextMenu(task.id, e, isPinned)
}
onArchive={() => onTaskArchive(task.id)}
onTogglePin={() => onTaskTogglePin(task.id)}
onEditSubmit={(newTitle) =>
onTaskEditSubmit(task.id, newTitle)
}
onEditCancel={onTaskEditCancel}
timestamp={task[timestampKey]}
/>
))}
</Fragment>
))}
{hasMore && (
<div className="px-2 py-2">
Expand Down
19 changes: 19 additions & 0 deletions apps/code/src/renderer/utils/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,22 @@ export function formatRelativeTimeLong(timestamp: number | string): string {
year: "numeric",
});
}

export function getRelativeDateGroup(
timestamp: number | string,
): string | null {
const date =
typeof timestamp === "string" ? new Date(timestamp) : new Date(timestamp);
Comment on lines +57 to +58
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Redundant conditional — both branches are identical

Both arms of the ternary produce new Date(timestamp), so the conditional is superfluous. new Date() already handles both string and number inputs, so the whole expression can be collapsed to one line.

Suggested change
const date =
typeof timestamp === "string" ? new Date(timestamp) : new Date(timestamp);
const date = new Date(timestamp);
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/code/src/renderer/utils/time.ts
Line: 55-56

Comment:
**Redundant conditional — both branches are identical**

Both arms of the ternary produce `new Date(timestamp)`, so the conditional is superfluous. `new Date()` already handles both `string` and `number` inputs, so the whole expression can be collapsed to one line.

```suggestion
  const date = new Date(timestamp);
```

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

that tru 😛

const startOfToday = new Date();
startOfToday.setHours(0, 0, 0, 0);
const startOfDate = new Date(date);
startOfDate.setHours(0, 0, 0, 0);
const days = Math.round(
(startOfToday.getTime() - startOfDate.getTime()) / 86_400_000,
);
if (days <= 0) return null;
if (days === 1) return "Yesterday";
if (days < 7) return "This week";
if (days < 30) return "This month";
return "Earlier";
}
Loading