Skip to content
Merged
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
38 changes: 25 additions & 13 deletions apps/desktop/src/components/finder/views/contact-view.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { RiCornerDownLeftLine } from "@remixicon/react";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { ArrowUpAZ, Building2, CircleMinus, FileText, Pencil, Plus, SearchIcon, TrashIcon, User } from "lucide-react";
import { Building2, CircleMinus, FileText, Pencil, Plus, SearchIcon, TrashIcon, User } from "lucide-react";
import React, { useEffect, useRef, useState } from "react";

import { commands as dbCommands } from "@hypr/plugin-db";
Expand All @@ -9,6 +9,7 @@ import { commands as windowsCommands } from "@hypr/plugin-windows";
import { Button } from "@hypr/ui/components/ui/button";
import { Input } from "@hypr/ui/components/ui/input";
import { Popover, PopoverContent, PopoverTrigger } from "@hypr/ui/components/ui/popover";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@hypr/ui/components/ui/select";
import { cn } from "@hypr/ui/lib/utils";
import { getInitials } from "@hypr/utils";
import { LinkProps } from "node_modules/@tanstack/react-router/dist/esm/link";
Expand All @@ -27,7 +28,7 @@ export function ContactView({ userId, initialPersonId, initialOrgId }: ContactVi
const [editingPerson, setEditingPerson] = useState<string | null>(null);
const [editingOrg, setEditingOrg] = useState<string | null>(null);
const [showNewOrg, setShowNewOrg] = useState(false);
const [sortAlphabetically, setSortAlphabetically] = useState(true);
const [sortOption, setSortOption] = useState<"alphabetical" | "oldest" | "newest">("alphabetical");
const queryClient = useQueryClient();

// Load organizations once and keep cached (global data)
Expand Down Expand Up @@ -123,16 +124,18 @@ export function ContactView({ userId, initialPersonId, initialOrgId }: ContactVi
? allPeopleWithUser.filter(person => person.organization_id === selectedOrganization)
: allPeopleWithUser).filter(person => person.id === userId || isValidName(person.full_name));

if (sortAlphabetically) {
if (sortOption === "alphabetical") {
filtered = [...filtered].sort((a, b) => {
const nameA = (a.full_name || a.email || "").toLowerCase();
const nameB = (b.full_name || b.email || "").toLowerCase();
return nameA.localeCompare(nameB);
});
} else if (sortOption === "newest") {
Copy link

Choose a reason for hiding this comment

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

The "oldest" option is presented to users and included in sortOption’s union type but the displayPeople memo never handles sortOption === "oldest", so choosing "Oldest" will not change the ordering, creating a mismatch between UI and behaviour. (Based on your team’s feedback about ensuring new enum values are always fully implemented)

Prompt for AI agents
Address the following comment on apps/desktop/src/components/finder/views/contact-view.tsx at line 133:

<comment>The &quot;oldest&quot; option is presented to users and included in sortOption’s union type but the displayPeople memo never handles sortOption === &quot;oldest&quot;, so choosing &quot;Oldest&quot; will not change the ordering, creating a mismatch between UI and behaviour. (Based on your team’s feedback about ensuring new enum values are always fully implemented)</comment>

<file context>
@@ -123,16 +124,18 @@ export function ContactView({ userId, initialPersonId, initialOrgId }: ContactVi
       ? allPeopleWithUser.filter(person =&gt; person.organization_id === selectedOrganization)
       : allPeopleWithUser).filter(person =&gt; person.id === userId || isValidName(person.full_name));
 
-    if (sortAlphabetically) {
+    if (sortOption === &quot;alphabetical&quot;) {
       filtered = [...filtered].sort((a, b) =&gt; {
         const nameA = (a.full_name || a.email || &quot;&quot;).toLowerCase();
         const nameB = (b.full_name || b.email || &quot;&quot;).toLowerCase();
         return nameA.localeCompare(nameB);
</file context>

filtered = [...filtered].reverse();
}

return filtered;
}, [selectedOrganization, allPeopleWithUser, userId, sortAlphabetically]);
}, [selectedOrganization, allPeopleWithUser, userId, sortOption]);

const selectedPersonData = displayPeople.find(p => p.id === selectedPerson);

Expand Down Expand Up @@ -254,16 +257,25 @@ export function ContactView({ userId, initialPersonId, initialOrgId }: ContactVi
<div className="px-3 py-2 border-b border-neutral-200 flex items-center justify-between">
<h3 className="text-xs font-medium text-neutral-600">People</h3>
<div className="flex items-center gap-1">
<button
onClick={() => setSortAlphabetically(!sortAlphabetically)}
className={cn(
"p-0.5 rounded hover:bg-neutral-100 transition-colors",
sortAlphabetically && "bg-neutral-100",
)}
title={sortAlphabetically ? "Sorted A-Z" : "Sort A-Z"}
<Select
value={sortOption}
onValueChange={(value: "alphabetical" | "oldest" | "newest") => setSortOption(value)}
>
<ArrowUpAZ className="h-3 w-3 text-neutral-500" />
</button>
<SelectTrigger className="w-[90px] h-6 text-xs border-0 bg-transparent hover:bg-neutral-100 focus:ring-0 focus:ring-offset-0">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="alphabetical" className="text-xs">
A-Z
</SelectItem>
<SelectItem value="oldest" className="text-xs">
Oldest
</SelectItem>
<SelectItem value="newest" className="text-xs">
Newest
</SelectItem>
</SelectContent>
</Select>
<button
onClick={() => {
const newPersonId = crypto.randomUUID();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ const exportHandlers = {

// Update frontmatter
const targets = [
{ target: "date", value: new Date().toISOString() },
{ target: "date", value: session?.created_at ?? new Date().toISOString() },
...(sessionTags && sessionTags.length > 0
? [{
target: "tags",
Expand Down
Loading