From 0827cc8a5aa10f3e870ab6d832211d0a670039ae Mon Sep 17 00:00:00 2001 From: Donkie Date: Sun, 24 Nov 2024 14:45:16 +0100 Subject: [PATCH] Improvements to default location --- .../pages/locations/components/location.tsx | 25 ++++++++++--- .../components/locationContainer.tsx | 37 +++++++++++-------- .../pages/locations/components/spoolCard.tsx | 2 +- client/src/pages/locations/functions.ts | 8 ++-- client/src/pages/locations/locations.css | 19 ++++++++-- 5 files changed, 64 insertions(+), 27 deletions(-) diff --git a/client/src/pages/locations/components/location.tsx b/client/src/pages/locations/components/location.tsx index eebd526..2a56996 100644 --- a/client/src/pages/locations/components/location.tsx +++ b/client/src/pages/locations/components/location.tsx @@ -4,9 +4,10 @@ import { useRef, useState } from "react"; import { useDrag, useDrop } from "react-dnd"; import { DeleteOutlined } from "@ant-design/icons"; -import { useUpdate } from "@refinedev/core"; +import { useTranslate, useUpdate } from "@refinedev/core"; import { ISpool } from "../../spools/model"; import { DragItem, ItemTypes, SpoolDragItem } from "../dnd"; +import { EMPTYLOC } from "../functions"; import { SpoolList } from "./spoolList"; export function Location({ @@ -30,6 +31,7 @@ export function Location({ locationSpoolOrder: number[]; setLocationSpoolOrder: (spoolOrder: number[]) => void; }) { + const t = useTranslate(); const [editTitle, setEditTitle] = useState(false); const [newTitle, setNewTitle] = useState(title); const { mutate: updateSpool } = useUpdate({ @@ -47,9 +49,11 @@ export function Location({ }); }; + const dropTypes = title == EMPTYLOC ? [ItemTypes.SPOOL] : [ItemTypes.CONTAINER, ItemTypes.SPOOL]; + const ref = useRef(null); const [{ handlerId }, drop] = useDrop({ - accept: [ItemTypes.CONTAINER, ItemTypes.SPOOL], + accept: dropTypes, collect(monitor) { return { handlerId: monitor.getHandlerId(), @@ -113,7 +117,7 @@ export function Location({ const [{ isDragging }, drag] = useDrag({ type: ItemTypes.CONTAINER, - canDrag: !editTitle, + canDrag: !editTitle && title != EMPTYLOC, item: () => { return { title, index }; }, @@ -122,11 +126,20 @@ export function Location({ }), }); + const displayTitle = title == EMPTYLOC ? t("locations.no_location") : title; + const opacity = isDragging ? 0 : 1; drag(drop(ref)); + const canEditTitle = title != EMPTYLOC; + return ( -
+

{editTitle ? ( ) : ( { + if (!canEditTitle) return; setNewTitle(title); setEditTitle(true); }} > - {title} + {displayTitle} )} {showDelete &&