22
33import { memo , useCallback , useEffect , useLayoutEffect , useMemo , useRef , useState } from 'react'
44import { createLogger } from '@sim/logger'
5- import { Compass , MoreHorizontal } from 'lucide-react'
5+ import { Compass , MoreHorizontal , Pin } from 'lucide-react'
66import Image from 'next/image'
77import Link from 'next/link'
88import { useParams , usePathname , useRouter } from 'next/navigation'
@@ -91,6 +91,7 @@ import {
9191 useMarkTaskRead ,
9292 useMarkTaskUnread ,
9393 useRenameTask ,
94+ useSetTaskPinned ,
9495 useTasks ,
9596} from '@/hooks/queries/tasks'
9697import { useUpdateWorkflow } from '@/hooks/queries/workflows'
@@ -144,6 +145,7 @@ const SidebarTaskItem = memo(function SidebarTaskItem({
144145 isSelected,
145146 isActive,
146147 isUnread,
148+ isPinned,
147149 isMenuOpen,
148150 showCollapsedTooltips,
149151 onMultiSelectClick,
@@ -156,6 +158,7 @@ const SidebarTaskItem = memo(function SidebarTaskItem({
156158 isSelected : boolean
157159 isActive : boolean
158160 isUnread : boolean
161+ isPinned : boolean
159162 isMenuOpen : boolean
160163 showCollapsedTooltips : boolean
161164 onMultiSelectClick : ( taskId : string , shiftKey : boolean ) => void
@@ -219,6 +222,9 @@ const SidebarTaskItem = memo(function SidebarTaskItem({
219222 { ! isActive && isUnread && ! isCurrentRoute && ! isMenuOpen && (
220223 < span className = 'absolute size-[7px] rounded-full bg-[var(--brand-accent)] group-hover:hidden' />
221224 ) }
225+ { ! isActive && ! isUnread && isPinned && ! isCurrentRoute && ! isMenuOpen && (
226+ < Pin className = 'absolute size-[12px] text-[var(--text-icon)] group-hover:hidden' />
227+ ) }
222228 < button
223229 type = 'button'
224230 aria-label = 'Task options'
@@ -581,6 +587,7 @@ export const Sidebar = memo(function Sidebar() {
581587 const deleteTasksMutation = useDeleteTasks ( workspaceId )
582588 const markTaskReadMutation = useMarkTaskRead ( workspaceId )
583589 const markTaskUnreadMutation = useMarkTaskUnread ( workspaceId )
590+ const setTaskPinnedMutation = useSetTaskPinned ( workspaceId )
584591 const renameTaskMutation = useRenameTask ( workspaceId )
585592 const tasksHover = useHoverMenu ( )
586593 const workflowsHover = useHoverMenu ( )
@@ -930,6 +937,15 @@ export const Sidebar = memo(function Sidebar() {
930937 markTaskUnreadMutation . mutate ( ids [ 0 ] )
931938 } , [ ] )
932939
940+ const handleToggleTaskPin = useCallback ( ( ) => {
941+ const { taskIds : ids } = contextMenuSelectionRef . current
942+ if ( ids . length !== 1 ) return
943+ const taskId = ids [ 0 ]
944+ const task = tasks . find ( ( t ) => t . id === taskId )
945+ if ( ! task ) return
946+ setTaskPinnedMutation . mutate ( { chatId : taskId , pinned : ! task . isPinned } )
947+ } , [ tasks ] )
948+
933949 const handleStartTaskRename = useCallback ( ( ) => {
934950 const { taskIds : ids } = contextMenuSelectionRef . current
935951 if ( ids . length !== 1 ) return
@@ -1521,6 +1537,7 @@ export const Sidebar = memo(function Sidebar() {
15211537 isSelected = { isSelected }
15221538 isActive = { ! ! task . isActive }
15231539 isUnread = { ! ! task . isUnread }
1540+ isPinned = { ! ! task . isPinned }
15241541 isMenuOpen = { menuOpenTaskId === task . id }
15251542 showCollapsedTooltips = { showCollapsedTooltips }
15261543 onMultiSelectClick = { handleTaskClick }
@@ -1771,6 +1788,7 @@ export const Sidebar = memo(function Sidebar() {
17711788 onOpenInNewTab = { handleTaskOpenInNewTab }
17721789 onMarkAsRead = { handleMarkTaskAsRead }
17731790 onMarkAsUnread = { handleMarkTaskAsUnread }
1791+ onTogglePin = { handleToggleTaskPin }
17741792 onRename = { handleStartTaskRename }
17751793 onDelete = { handleDeleteTask }
17761794 showOpenInNewTab = { ! isMultiTaskContextMenu }
@@ -1780,6 +1798,8 @@ export const Sidebar = memo(function Sidebar() {
17801798 ! ! activeTaskContextMenuItem &&
17811799 ! activeTaskContextMenuItem . isUnread
17821800 }
1801+ showPin = { ! isMultiTaskContextMenu && ! ! activeTaskContextMenuItem }
1802+ isPinned = { ! ! activeTaskContextMenuItem ?. isPinned }
17831803 showRename = { ! isMultiTaskContextMenu }
17841804 showDuplicate = { false }
17851805 showColorChange = { false }
0 commit comments