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
Original file line number Diff line number Diff line change
Expand Up @@ -97,33 +97,35 @@ export function DashboardSidebarWorkspaceContextMenu({
</>
)}
<ContextMenuSeparator />
<ContextMenuSub>
<ContextMenuSubTrigger>
<LuArrowRightLeft className="size-4 mr-2" />
Move to Section
</ContextMenuSubTrigger>
<ContextMenuSubContent>
<ContextMenuItem onSelect={onCreateSection}>
<LuFolderPlus className="size-4 mr-2" />
New Section
</ContextMenuItem>
{sections.length > 0 && <ContextMenuSeparator />}
{sections.map((section) => (
<ContextMenuItem
key={section.id}
onSelect={() => onMoveToSection(section.id)}
>
{section.color && (
<span
className="size-2 shrink-0 rounded-full mr-2"
style={{ backgroundColor: section.color }}
/>
)}
{section.name}
</ContextMenuItem>
))}
</ContextMenuSubContent>
</ContextMenuSub>
<ContextMenuItem onSelect={onCreateSection}>
<LuFolderPlus className="size-4 mr-2" />
Create Section Below
</ContextMenuItem>
{(sections.length > 0 || isInSection) && <ContextMenuSeparator />}
{sections.length > 0 && (
<ContextMenuSub>
<ContextMenuSubTrigger>
<LuArrowRightLeft className="size-4 mr-2" />
Move to Section
</ContextMenuSubTrigger>
<ContextMenuSubContent>
{sections.map((section) => (
<ContextMenuItem
key={section.id}
onSelect={() => onMoveToSection(section.id)}
>
{section.color && (
<span
className="size-2 shrink-0 rounded-full mr-2"
style={{ backgroundColor: section.color }}
/>
)}
{section.name}
</ContextMenuItem>
))}
</ContextMenuSubContent>
</ContextMenuSub>
)}
{isInSection && (
<ContextMenuItem onSelect={() => onMoveToSection(null)}>
<LuArrowUp className="size-4 mr-2" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,9 @@ export function useDashboardSidebarWorkspaceItemActions({
};

const handleCreateSection = () => {
const newSectionId = createSection(projectId);
moveWorkspaceToSection(workspaceId, projectId, newSectionId);
createSection(projectId, {
insertAfterWorkspaceId: workspaceId,
});
};

const resolveWorktreePath = async (): Promise<string | null> => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,25 +182,71 @@ export function useDashboardSidebarState() {
);

const createSection = useCallback(
(projectId: string, name = "New Section") => {
(
projectId: string,
options: { name?: string; insertAfterWorkspaceId?: string } = {},
) => {
const { name = "New Section", insertAfterWorkspaceId } = options;
ensureSidebarProjectRecord(collections, projectId);

const sectionId = crypto.randomUUID();
const sectionOrders = Array.from(
collections.v2SidebarSections.state.values(),
).filter((item) => item.projectId === projectId);

const randomColor =
PROJECT_CUSTOM_COLORS[
Math.floor(Math.random() * PROJECT_CUSTOM_COLORS.length)
].value;

let tabOrder: number;
if (insertAfterWorkspaceId) {
const anchorWorkspace = collections.v2WorkspaceLocalState.get(
insertAfterWorkspaceId,
);
const anchorTabOrder = anchorWorkspace?.sidebarState.sectionId
? (collections.v2SidebarSections.get(
anchorWorkspace.sidebarState.sectionId,
)?.tabOrder ?? 0)
: (anchorWorkspace?.sidebarState.tabOrder ?? 0);

for (const workspace of collections.v2WorkspaceLocalState.state.values()) {
if (
workspace.sidebarState.projectId === projectId &&
workspace.sidebarState.sectionId === null &&
workspace.sidebarState.tabOrder > anchorTabOrder
) {
const nextOrder = workspace.sidebarState.tabOrder + 1;
collections.v2WorkspaceLocalState.update(
workspace.workspaceId,
(draft) => {
draft.sidebarState.tabOrder = nextOrder;
},
);
}
}
for (const section of collections.v2SidebarSections.state.values()) {
if (
section.projectId === projectId &&
section.tabOrder > anchorTabOrder
) {
const nextOrder = section.tabOrder + 1;
collections.v2SidebarSections.update(section.sectionId, (draft) => {
draft.tabOrder = nextOrder;
});
}
}

tabOrder = anchorTabOrder + 1;
} else {
const sectionOrders = Array.from(
collections.v2SidebarSections.state.values(),
).filter((item) => item.projectId === projectId);
tabOrder = getNextTabOrder(sectionOrders);
}

collections.v2SidebarSections.insert({
sectionId,
projectId,
name,
createdAt: new Date(),
tabOrder: getNextTabOrder(sectionOrders),
tabOrder,
isCollapsed: false,
color: randomColor,
});
Expand Down
Loading