-
Notifications
You must be signed in to change notification settings - Fork 4.8k
feat(web): accept file drops into sidebar threads #7892
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
Open
UtkarshUsername
wants to merge
9
commits into
pingdotgg:main
Choose a base branch
from
UtkarshUsername:feat/sidebar-thread-file-drop
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+225
−3
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7448421
feat(web): sidebar thread rows accept file drops
UtkarshUsername 38543d2
fix(web): address review findings on sidebar file drop
UtkarshUsername 7bd2cdc
fix(web): sidebar drop highlight visible inside clipped rows
UtkarshUsername ec0e9de
Merge branch 'main' into feat/sidebar-thread-file-drop
UtkarshUsername cea44b3
Merge branch 'main' into feat/sidebar-thread-file-drop
UtkarshUsername 16be904
fix(web): release pending drop when dropped-on thread is missing
UtkarshUsername 5d437c4
fix(web): release pending drop even when missing thread cannot redirect
UtkarshUsername edcb2d6
Merge branch 'main' into feat/sidebar-thread-file-drop
UtkarshUsername 8aefb76
Merge branch 'main' into feat/sidebar-thread-file-drop
UtkarshUsername File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import { beforeEach, describe, expect, it } from "vite-plus/test"; | ||
|
|
||
| import { scopeThreadRef } from "@t3tools/client-runtime/environment"; | ||
| import { type EnvironmentId, ThreadId } from "@t3tools/contracts"; | ||
|
|
||
| import { | ||
| useSidebarPendingFileDropStore, | ||
| type SidebarPendingFileDrop, | ||
| } from "./sidebarPendingFileDropStore"; | ||
|
|
||
| function makeFiles(count: number): File[] { | ||
| return Array.from({ length: count }, (_, index) => new File(["x"], `f${index}.png`)); | ||
| } | ||
|
|
||
| function makeEntry(environmentId: string, threadId: string, files: File[]): SidebarPendingFileDrop { | ||
| return { | ||
| threadRef: scopeThreadRef(environmentId as EnvironmentId, ThreadId.make(threadId)), | ||
| files, | ||
| }; | ||
| } | ||
|
|
||
| beforeEach(() => { | ||
| useSidebarPendingFileDropStore.setState({ pending: null }); | ||
| }); | ||
|
|
||
| describe("sidebarPendingFileDropStore", () => { | ||
| it("starts empty", () => { | ||
| expect(useSidebarPendingFileDropStore.getState().pending).toBeNull(); | ||
| }); | ||
|
|
||
| it("stashes and consumes a drop for the matching thread", () => { | ||
| const files = makeFiles(2); | ||
| const entry = makeEntry("env-1", "thread-1", files); | ||
| useSidebarPendingFileDropStore.getState().setPendingFileDrop(entry); | ||
|
|
||
| expect( | ||
| useSidebarPendingFileDropStore.getState().consumePendingFileDrop(entry.threadRef), | ||
| ).toEqual(files); | ||
| expect(useSidebarPendingFileDropStore.getState().pending).toBeNull(); | ||
| }); | ||
|
|
||
| it("refuses to consume for a different thread without clearing the stash", () => { | ||
| const entry = makeEntry("env-1", "thread-1", makeFiles(1)); | ||
| useSidebarPendingFileDropStore.getState().setPendingFileDrop(entry); | ||
|
|
||
| const otherThread = makeEntry("env-1", "thread-2", []).threadRef; | ||
| expect( | ||
| useSidebarPendingFileDropStore.getState().consumePendingFileDrop(otherThread), | ||
| ).toBeNull(); | ||
| expect(useSidebarPendingFileDropStore.getState().pending).toEqual(entry); | ||
|
|
||
| useSidebarPendingFileDropStore.getState().clearPendingFileDrop(); | ||
| expect(useSidebarPendingFileDropStore.getState().pending).toBeNull(); | ||
| }); | ||
|
|
||
| it("replaces an earlier pending drop with a newer one", () => { | ||
| const first = makeEntry("env-1", "thread-1", makeFiles(1)); | ||
| const second = makeEntry("env-2", "thread-2", makeFiles(3)); | ||
| useSidebarPendingFileDropStore.getState().setPendingFileDrop(first); | ||
| useSidebarPendingFileDropStore.getState().setPendingFileDrop(second); | ||
|
|
||
| expect(useSidebarPendingFileDropStore.getState().pending).toEqual(second); | ||
| expect( | ||
| useSidebarPendingFileDropStore.getState().consumePendingFileDrop(first.threadRef), | ||
| ).toBeNull(); | ||
| expect( | ||
| useSidebarPendingFileDropStore.getState().consumePendingFileDrop(second.threadRef), | ||
| ).not.toBeNull(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import { create } from "zustand"; | ||
|
|
||
| import { scopedThreadKey } from "@t3tools/client-runtime/environment"; | ||
| import type { ScopedThreadRef } from "@t3tools/contracts"; | ||
|
|
||
| /** | ||
| * Files dropped onto a sidebar thread row while another thread was open. | ||
| * The row hands these off and navigates; ChatView attaches them through the | ||
| * composer's normal drop path once the dropped-on thread actually becomes | ||
| * active, so they can never land on the wrong thread's draft. | ||
| */ | ||
| export interface SidebarPendingFileDrop { | ||
| threadRef: ScopedThreadRef; | ||
| files: File[]; | ||
| } | ||
|
|
||
| interface SidebarPendingFileDropStoreState { | ||
| pending: SidebarPendingFileDrop | null; | ||
| /** Replaces any earlier pending drop: only the latest handoff matters. */ | ||
| setPendingFileDrop: (entry: SidebarPendingFileDrop) => void; | ||
| clearPendingFileDrop: () => void; | ||
| /** | ||
| * Returns the stashed files when `threadRef` matches the drop target and | ||
| * clears the entry; returns null (leaving state untouched) otherwise. | ||
| */ | ||
| consumePendingFileDrop: (threadRef: ScopedThreadRef) => File[] | null; | ||
| } | ||
|
|
||
| export const useSidebarPendingFileDropStore = create<SidebarPendingFileDropStoreState>()( | ||
| (set, get) => ({ | ||
| pending: null, | ||
| setPendingFileDrop: (entry) => { | ||
| set({ pending: entry }); | ||
| }, | ||
| clearPendingFileDrop: () => { | ||
| set({ pending: null }); | ||
| }, | ||
| consumePendingFileDrop: (threadRef) => { | ||
| const pending = get().pending; | ||
| if (pending === null || scopedThreadKey(pending.threadRef) !== scopedThreadKey(threadRef)) { | ||
| return null; | ||
| } | ||
| set({ pending: null }); | ||
| return pending.files; | ||
| }, | ||
| }), | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.