Skip to content

Commit 2df6d39

Browse files
committed
feat(sidebar): add empty task state and inline task creation
- Show "No tasks yet" in the Tasks section (expanded and collapsed) when the list is empty - Clicking + now creates a task via the API and navigates directly to it, rather than navigating to home - Add isCreatingTaskRef guard to prevent double-click from spawning multiple tasks - Disable + button while creation is pending - Fall back to home navigation on creation error
1 parent 7a30999 commit 2df6d39

1 file changed

Lines changed: 24 additions & 4 deletions

File tree

  • apps/sim/app/workspace/[workspaceId]/w/components/sidebar

apps/sim/app/workspace/[workspaceId]/w/components/sidebar/sidebar.tsx

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ import { useFolderMap, useFolders } from '@/hooks/queries/folders'
9090
import { useKnowledgeBasesQuery } from '@/hooks/queries/kb/knowledge'
9191
import { useTablesList } from '@/hooks/queries/tables'
9292
import {
93+
useCreateTask,
9394
useDeleteTask,
9495
useDeleteTasks,
9596
useMarkTaskRead,
@@ -593,6 +594,7 @@ export const Sidebar = memo(function Sidebar() {
593594
}
594595
}, [activeNavItemHref])
595596

597+
const createTaskMutation = useCreateTask(workspaceId)
596598
const deleteTaskMutation = useDeleteTask(workspaceId)
597599
const deleteTasksMutation = useDeleteTasks(workspaceId)
598600
const markTaskReadMutation = useMarkTaskRead(workspaceId)
@@ -611,6 +613,7 @@ export const Sidebar = memo(function Sidebar() {
611613
preventDismiss: preventTaskDismiss,
612614
} = useContextMenu()
613615

616+
const isCreatingTaskRef = useRef(false)
614617
const contextMenuSelectionRef = useRef<{ taskIds: string[]; names: string[] }>({
615618
taskIds: [],
616619
names: [],
@@ -1140,10 +1143,19 @@ export const Sidebar = memo(function Sidebar() {
11401143
onSelect: handleCreateWorkflow,
11411144
}
11421145

1143-
const handleNewTask = useCallback(() => {
1144-
useMothershipDraftsStore.getState().clearDraft(`${workspaceId}:new`)
1145-
navigateToPage(`/workspace/${workspaceId}/home`)
1146-
}, [navigateToPage, workspaceId])
1146+
const handleNewTask = useCallback(async () => {
1147+
if (!workspaceId || isCreatingTaskRef.current) return
1148+
isCreatingTaskRef.current = true
1149+
try {
1150+
const { id } = await createTaskMutation.mutateAsync()
1151+
useMothershipDraftsStore.getState().clearDraft(`${workspaceId}:new`)
1152+
navigateToPage(`/workspace/${workspaceId}/task/${id}`)
1153+
} catch {
1154+
navigateToPage(`/workspace/${workspaceId}/home`)
1155+
} finally {
1156+
isCreatingTaskRef.current = false
1157+
}
1158+
}, [workspaceId, navigateToPage])
11471159

11481160
const tasksPrimaryAction = {
11491161
label: 'New task',
@@ -1368,6 +1380,7 @@ export const Sidebar = memo(function Sidebar() {
13681380
variant='quiet'
13691381
className='h-[18px] w-[18px] rounded-sm p-0'
13701382
onClick={handleNewTask}
1383+
disabled={createTaskMutation.isPending}
13711384
>
13721385
<Plus className='h-[16px] w-[16px]' />
13731386
</Button>
@@ -1394,6 +1407,8 @@ export const Sidebar = memo(function Sidebar() {
13941407
<Loader className='h-[14px] w-[14px]' animate />
13951408
Loading...
13961409
</DropdownMenuItem>
1410+
) : tasks.length === 0 ? (
1411+
<DropdownMenuItem disabled>No tasks yet</DropdownMenuItem>
13971412
) : (
13981413
tasks.map((task) => (
13991414
<CollapsedTaskFlyoutItem
@@ -1421,6 +1436,11 @@ export const Sidebar = memo(function Sidebar() {
14211436
<SidebarItemSkeleton />
14221437
) : (
14231438
<>
1439+
{tasks.length === 0 ? (
1440+
<div className='flex h-[30px] items-center px-2 text-[var(--text-muted)] text-small'>
1441+
No tasks yet
1442+
</div>
1443+
) : null}
14241444
{/* `selectTaskOnly` populates `selectedTasks` on every click, so
14251445
a single entry just means "last clicked" — already conveyed by
14261446
`isCurrentRoute`. Highlight from selection only for explicit

0 commit comments

Comments
 (0)