diff --git a/apps/mobile/app/components/list/reorderable-list.tsx b/apps/mobile/app/components/list/reorderable-list.tsx index cfd8afd1a..6cb7d831c 100644 --- a/apps/mobile/app/components/list/reorderable-list.tsx +++ b/apps/mobile/app/components/list/reorderable-list.tsx @@ -125,14 +125,13 @@ function ReorderableList({ function getOrderedItems() { const items: T[] = []; - data.forEach((item) => { - const index = itemOrderState.indexOf(item?.id); - if (index === -1) { - items.push(item); - } else { - items.splice(index, 0, item); - } + itemOrderState.forEach((id) => { + const item = data.find((i) => i.id === id); + if (!item) return; + items.push(item); }); + + items.push(...data.filter((i) => !itemOrderState.includes(i.id))); return items; } @@ -148,6 +147,9 @@ function ReorderableList({ hoverDragReleasedStyle: { display: "none" }, + hoverDraggingWithoutReceiverStyle: { + opacity: 0.5 + }, dragReleasedStyle: { opacity: 1 }, @@ -174,6 +176,9 @@ function ReorderableList({ setItemsOrder(newOrder); onListOrderChanged?.(newOrder); }} + onItemDragEnd={(e) => { + console.log(e.receiver?.receiveOffset); + }} keyExtractor={(item) => (item as any).id} /> diff --git a/apps/mobile/app/components/properties/index.js b/apps/mobile/app/components/properties/index.js index 8601fec7e..b91034a8a 100644 --- a/apps/mobile/app/components/properties/index.js +++ b/apps/mobile/app/components/properties/index.js @@ -35,6 +35,7 @@ import { Items } from "./items"; import Notebooks from "./notebooks"; import { Synced } from "./synced"; import { TagStrip, Tags } from "./tags"; +import { useSideBarDraggingStore } from "../side-menu/dragging-store"; const Line = ({ top = 6, bottom = 6 }) => { const { colors } = useThemeColors(); @@ -235,7 +236,12 @@ Properties.present = async (item, buttons = [], isSheet) => { break; case "color": props[0] = await db.colors.color(item.id); - props.push(["trash", "rename-color", "reorder"]); + + props.push([ + "trash", + "rename-color", + ...(useSideBarDraggingStore.getState().dragging ? [] : ["reorder"]) + ]); break; case "reminder": { props[0] = await db.reminders.reminder(item.id); diff --git a/apps/mobile/app/components/side-menu/color-section.tsx b/apps/mobile/app/components/side-menu/color-section.tsx index 7ff280c18..11bd30951 100644 --- a/apps/mobile/app/components/side-menu/color-section.tsx +++ b/apps/mobile/app/components/side-menu/color-section.tsx @@ -33,10 +33,11 @@ import { Properties } from "../properties"; import { PressableButton } from "../ui/pressable"; import Heading from "../ui/typography/heading"; import Paragraph from "../ui/typography/paragraph"; +import { useSideBarDraggingStore } from "./dragging-store"; export const ColorSection = React.memo( function ColorSection() { - const [colorNotes, loadingColors] = useMenuStore((state) => [ + const [colorNotes] = useMenuStore((state) => [ state.colorNotes, state.loadingColors ]); @@ -78,7 +79,6 @@ export const ColorSection = React.memo( const ColorItem = React.memo( function ColorItem({ item }: { item: Color }) { const { colors, isDark } = useThemeColors(); - const setColorNotes = useMenuStore((state) => state.setColorNotes); const isFocused = useNavigationStore( (state) => state.focusedRouteId === item.id ); @@ -92,6 +92,7 @@ const ColorItem = React.memo( }; const onLongPress = () => { + if (useSideBarDraggingStore.getState().dragging) return; Properties.present(item); }; diff --git a/apps/mobile/app/components/side-menu/dragging-store.ts b/apps/mobile/app/components/side-menu/dragging-store.ts index 121b14e93..5fce56be6 100644 --- a/apps/mobile/app/components/side-menu/dragging-store.ts +++ b/apps/mobile/app/components/side-menu/dragging-store.ts @@ -18,6 +18,6 @@ along with this program. If not, see . */ import create from "zustand"; -export const useSideBarDraggingStore = create((set, get) => ({ +export const useSideBarDraggingStore = create(() => ({ dragging: false })); diff --git a/apps/mobile/app/components/side-menu/index.tsx b/apps/mobile/app/components/side-menu/index.tsx index b5b04a023..229a897ca 100644 --- a/apps/mobile/app/components/side-menu/index.tsx +++ b/apps/mobile/app/components/side-menu/index.tsx @@ -33,6 +33,7 @@ import { SUBSCRIPTION_STATUS } from "../../utils/constants"; import { eOpenPremiumDialog } from "../../utils/events"; import { MenuItemsList } from "../../utils/menu-items"; import ReorderableList from "../list/reorderable-list"; +import { Button } from "../ui/button"; import { ColorSection } from "./color-section"; import { useSideBarDraggingStore } from "./dragging-store"; import { MenuItem } from "./menu-item"; @@ -80,6 +81,7 @@ export const SideMenu = React.memo( eSendEvent(eOpenPremiumDialog); } }; + const renderItem = useCallback( () => ( <> @@ -173,14 +175,44 @@ export const SideMenu = React.memo( )} - - - + {dragging ? ( + +