-
Notifications
You must be signed in to change notification settings - Fork 4
refactor: remove auto-focus from newly created folders and consolidate navigation logic #195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
02a5484
8ee8b13
d4ab59a
da3926a
bdb9d54
c3b5236
c2528cd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import React, { RefObject, useState, useMemo, useCallback } from "react"; | ||
| import { useElementWidth } from "@/hooks/use-element-width"; | ||
| import { useSearchParams } from "next/navigation"; | ||
| import { toast } from "sonner"; | ||
| import { cn } from "@/lib/utils"; | ||
|
|
@@ -164,6 +165,9 @@ export function WorkspaceSection({ | |
| const setSelectedActions = useUIStore((state) => state.setSelectedActions); | ||
| const { data: session } = useSession(); | ||
|
|
||
| // Measure container width for responsive SelectionActionBar | ||
| const containerWidth = useElementWidth(scrollAreaRef); | ||
|
|
||
| // Assistant API for Deep Research action | ||
| // Note: WorkspaceSection is inside WorkspaceRuntimeProvider in DashboardLayout, so this hook works | ||
| const aui = useAui(); | ||
|
|
@@ -416,7 +420,8 @@ export function WorkspaceSection({ | |
| // Clear the selection | ||
| clearCardSelection(); | ||
|
|
||
| // Note: FolderCard auto-focuses the title when name is "New Folder" | ||
| // Navigate to the newly created folder | ||
| handleCreatedItems([folderId]); | ||
| }; | ||
|
|
||
| // Handle PDF upload from BottomActionBar | ||
|
|
@@ -645,22 +650,23 @@ export function WorkspaceSection({ | |
| onCreateNote: () => { | ||
| if (addItem) { | ||
| const itemId = addItem("note"); | ||
| if (handleCreatedItems && itemId) { | ||
| handleCreatedItems([itemId]); | ||
| } | ||
| handleCreatedItems([itemId]); | ||
| } | ||
| }, | ||
| onCreateFolder: () => { | ||
| if (addItem) { | ||
| const itemId = addItem("folder"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Type mismatch: |
||
| handleCreatedItems([itemId]); | ||
| } | ||
| }, | ||
| onCreateFolder: () => { if (addItem) addItem("folder"); }, | ||
| onUpload: () => handleUploadMenuItemClick(), | ||
| onAudio: () => openAudioDialog(), | ||
| onYouTube: () => setShowYouTubeDialog(true), | ||
| onWebsite: () => setShowWebsiteDialog(true), | ||
| onFlashcards: () => { | ||
| if (addItem) { | ||
| const itemId = addItem("flashcard"); | ||
| if (handleCreatedItems && itemId) { | ||
| handleCreatedItems([itemId]); | ||
| } | ||
| handleCreatedItems([itemId]); | ||
| } | ||
| }, | ||
| onQuiz: () => { | ||
|
|
@@ -690,7 +696,7 @@ export function WorkspaceSection({ | |
| onDeleteSelected={handleDeleteRequest} | ||
| onCreateFolderFromSelection={handleCreateFolderFromSelection} | ||
| onMoveSelected={handleMoveSelected} | ||
| isCompactMode={isItemPanelOpen && isChatExpanded} | ||
| isCompactMode={containerWidth !== undefined && containerWidth < 400} | ||
| /> | ||
| )} | ||
| {/* Move To Dialog */} | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,28 +1,23 @@ | ||||||
|
|
||||||
| import { useState, useEffect, useCallback } from "react"; | ||||||
| import { useUIStore } from "@/lib/stores/ui-store"; | ||||||
| import { useNavigateToItem } from "./use-navigate-to-item"; | ||||||
| import type { AgentState } from "@/lib/workspace-state/types"; | ||||||
|
|
||||||
| /** | ||||||
| * Hook to handle navigation and selection after item creation. | ||||||
| * Hook to handle navigation after item creation. | ||||||
| * It waits for the item to appear in the workspace state before attempting to scroll to it, | ||||||
| * solving race conditions and stale closure issues. | ||||||
| */ | ||||||
| export function useReactiveNavigation(workspaceState: AgentState) { | ||||||
| const [pendingNavigationId, setPendingNavigationId] = useState<string | null>(null); | ||||||
| const navigateToItem = useNavigateToItem(); | ||||||
| const selectMultipleCards = useUIStore((state) => state.selectMultipleCards); | ||||||
|
|
||||||
| const handleCreatedItems = useCallback((createdIds: string[]) => { | ||||||
| // Select the newly created items | ||||||
| selectMultipleCards(createdIds); | ||||||
|
|
||||||
| // Set pending navigation to trigger in useEffect once item is available in state | ||||||
| if (createdIds.length > 0) { | ||||||
| setPendingNavigationId(createdIds[0]); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. accepts array but only uses first item
Suggested change
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||||||
| } | ||||||
| }, [selectMultipleCards]); | ||||||
| }, []); | ||||||
|
|
||||||
| // Effect to handle navigation once item appears in state | ||||||
| useEffect(() => { | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passing possibly undefined ID
addItemis typed to returnstring, but several call sites pass its return value directly intohandleCreatedItems([itemId])(e.g. note/folder/flashcard). IfaddItemever returnsundefined(as noted elsewhere in this PR),useReactiveNavigationwill setpendingNavigationIdtoundefinedand then callnavigateToItem(undefined), which is a runtime bug. Either makeaddItemconsistently return a string everywhere, or guard before callinghandleCreatedItems.Also appears at
src/components/workspace-canvas/WorkspaceSection.tsx:656-670.