@@ -44,10 +44,9 @@ import {
4444 hasComposerFileDrag ,
4545} from "../lib/composer-drop" ;
4646import {
47- PROJECT_REORDER_LONG_PRESS_MS ,
4847 projectGroupKeyFromPoint ,
4948 projectReorderInsertAfter ,
50- projectReorderMovedTooFar ,
49+ projectReorderShouldArm ,
5150 sameProjectReorderBucket ,
5251} from "../lib/sidebar-project-reorder" ;
5352import {
@@ -145,10 +144,10 @@ type ProjectReorderPointerState = {
145144 lastX : number ;
146145 lastY : number ;
147146 armed : boolean ;
148- timer : number | null ;
149147 dropKey : string | null ;
150148 dropTop : number ;
151149 dropHeight : number ;
150+ insertAfter : boolean ;
152151 onMove : ( event : PointerEvent ) => void ;
153152 onUp : ( event : PointerEvent ) => void ;
154153 onCancel : ( event : PointerEvent ) => void ;
@@ -319,7 +318,7 @@ export function Sidebar({
319318 const [ projectsDropActive , setProjectsDropActive ] = useState ( false ) ;
320319 const [ sidebarResizing , setSidebarResizing ] = useState ( false ) ;
321320 const [ draggingProjectKey , setDraggingProjectKey ] = useState < string | null > ( null ) ;
322- const [ dropTargetProjectKey , setDropTargetProjectKey ] = useState < string | null > ( null ) ;
321+ const [ dropIndicator , setDropIndicator ] = useState < { key : string ; insertAfter : boolean } | null > ( null ) ;
323322 const menuTriggerRef = useRef < HTMLButtonElement | null > ( null ) ;
324323 const menuFirstItemRef = useRef < HTMLButtonElement | null > ( null ) ;
325324 const sessionPrefetchTimerRef = useRef < number | undefined > ( undefined ) ;
@@ -784,15 +783,14 @@ export function Sidebar({
784783 const finishProjectReorderPress = useCallback ( ( opts ?: { keepClickSuppressed ?: boolean } ) => {
785784 const state = projectReorderRef . current ;
786785 if ( state ) {
787- if ( state . timer != null ) window . clearTimeout ( state . timer ) ;
788786 window . removeEventListener ( "pointermove" , state . onMove , true ) ;
789787 window . removeEventListener ( "pointerup" , state . onUp , true ) ;
790788 window . removeEventListener ( "pointercancel" , state . onCancel , true ) ;
791789 projectReorderRef . current = null ;
792790 }
793791 if ( ! opts ?. keepClickSuppressed ) suppressProjectTitleClickRef . current = false ;
794792 setDraggingProjectKey ( null ) ;
795- setDropTargetProjectKey ( null ) ;
793+ setDropIndicator ( null ) ;
796794 document . documentElement . removeAttribute ( "data-project-reordering" ) ;
797795 } , [ ] ) ;
798796
@@ -833,7 +831,9 @@ export function Sidebar({
833831
834832 const beginProjectReorderPress = useCallback (
835833 ( event : ReactPointerEvent < HTMLButtonElement > , projectKey : string ) => {
836- if ( event . button !== 0 || projectReorderRef . current ) return ;
834+ if ( event . button !== 0 || event . pointerType === "touch" || projectReorderRef . current ) {
835+ return ;
836+ }
837837
838838 const onMove = ( moveEvent : PointerEvent ) => {
839839 const current = projectReorderRef . current ;
@@ -842,14 +842,17 @@ export function Sidebar({
842842 current . lastY = moveEvent . clientY ;
843843 if ( ! current . armed ) {
844844 if (
845- projectReorderMovedTooFar (
845+ ! projectReorderShouldArm (
846846 moveEvent . clientX - current . startX ,
847847 moveEvent . clientY - current . startY ,
848848 )
849849 ) {
850- finishProjectReorderPress ( ) ;
850+ return ;
851851 }
852- return ;
852+ current . armed = true ;
853+ suppressProjectTitleClickRef . current = true ;
854+ document . documentElement . setAttribute ( "data-project-reordering" , "true" ) ;
855+ setDraggingProjectKey ( current . projectKey ) ;
853856 }
854857 moveEvent . preventDefault ( ) ;
855858 const target = projectGroupKeyFromPoint ( moveEvent . clientX , moveEvent . clientY ) ;
@@ -864,13 +867,19 @@ export function Sidebar({
864867 target . key !== current . projectKey &&
865868 sameProjectReorderBucket ( source . meta , destination . meta )
866869 ) {
870+ const insertAfter = projectReorderInsertAfter (
871+ moveEvent . clientY ,
872+ target . top ,
873+ target . height ,
874+ ) ;
867875 current . dropKey = target . key ;
868876 current . dropTop = target . top ;
869877 current . dropHeight = target . height ;
870- setDropTargetProjectKey ( target . key ) ;
878+ current . insertAfter = insertAfter ;
879+ setDropIndicator ( { key : target . key , insertAfter } ) ;
871880 } else {
872881 current . dropKey = null ;
873- setDropTargetProjectKey ( null ) ;
882+ setDropIndicator ( null ) ;
874883 }
875884 } ;
876885
@@ -883,7 +892,7 @@ export function Sidebar({
883892 reorderProjectEntriesRef . current (
884893 current . projectKey ,
885894 current . dropKey ,
886- projectReorderInsertAfter ( current . lastY , current . dropTop , current . dropHeight ) ,
895+ current . insertAfter ,
887896 ) ;
888897 }
889898 finishProjectReorderPress ( { keepClickSuppressed : true } ) ;
@@ -906,23 +915,14 @@ export function Sidebar({
906915 lastX : event . clientX ,
907916 lastY : event . clientY ,
908917 armed : false ,
909- timer : null ,
910918 dropKey : null ,
911919 dropTop : 0 ,
912920 dropHeight : 0 ,
921+ insertAfter : false ,
913922 onMove,
914923 onUp,
915924 onCancel,
916925 } ;
917- state . timer = window . setTimeout ( ( ) => {
918- const current = projectReorderRef . current ;
919- if ( current !== state ) return ;
920- current . armed = true ;
921- current . timer = null ;
922- suppressProjectTitleClickRef . current = true ;
923- document . documentElement . setAttribute ( "data-project-reordering" , "true" ) ;
924- setDraggingProjectKey ( current . projectKey ) ;
925- } , PROJECT_REORDER_LONG_PRESS_MS ) ;
926926 projectReorderRef . current = state ;
927927 window . addEventListener ( "pointermove" , onMove , true ) ;
928928 window . addEventListener ( "pointerup" , onUp , true ) ;
@@ -1663,7 +1663,7 @@ export function Sidebar({
16631663 return (
16641664 < section
16651665 key = { entry . key }
1666- className = { `sidebar-session-group project-group ${ entry . active ? "active" : "" } ${ entry . meta . archived ? "archived" : "" } ${ dropProjectKey === entry . key ? "is-drop-target" : "" } ${ draggingProjectKey === entry . key ? "is-dragging" : "" } ${ dropTargetProjectKey === entry . key ? "is-drop-target" : "" } ` }
1666+ className = { `sidebar-session-group project-group ${ entry . active ? "active" : "" } ${ entry . meta . archived ? "archived" : "" } ${ dropProjectKey === entry . key ? "is-drop-target" : "" } ${ draggingProjectKey === entry . key ? "is-dragging" : "" } ${ dropIndicator ?. key === entry . key ? ( dropIndicator . insertAfter ? "is-drop-after" : "is-drop-before" ) : "" } ` }
16671667 aria-labelledby = { projectId }
16681668 data-sidebar-project-group = { entry . key }
16691669 onDragOver = { ( event ) => {
0 commit comments