From c01ba92021ded3f931b92e4e571209d8a2ddaaee Mon Sep 17 00:00:00 2001 From: Joshua Shoemaker Date: Fri, 26 May 2023 19:13:18 -0500 Subject: [PATCH] refact: fixed front end type, removed dead code --- .../createUiCanvasInteractions.ts | 24 +-- frontend/components/DocumentCanvas/types.ts | 19 +++ .../workspace/Sidebar/DocumentLineItem.tsx | 48 +----- .../workspace/Sidebar/GroupLineItem.tsx | 143 +----------------- .../workspace/Sidebar/makeDefaultSidebar.ts | 4 + .../workspace/Sidebar/navigationProps.ts | 4 +- 6 files changed, 28 insertions(+), 214 deletions(-) create mode 100644 frontend/components/DocumentCanvas/types.ts diff --git a/frontend/components/DocumentCanvas/createUiCanvasInteractions.ts b/frontend/components/DocumentCanvas/createUiCanvasInteractions.ts index 4bbd903..1840341 100644 --- a/frontend/components/DocumentCanvas/createUiCanvasInteractions.ts +++ b/frontend/components/DocumentCanvas/createUiCanvasInteractions.ts @@ -1,28 +1,6 @@ import isInBounds from '../../utils/isInBounds' import { entities } from '../../wailsjs/wailsjs/go/models' - - -type MouseCoordinates = { - startMouseX: number, startMouseY: number, endMouseX: number, endMouseY: number -} - -type RectangleCoordinates = { - startX: number, startY: number, endX: number, endY: number -} - -type AddAreaToStoreCallback = - (startX: number, startY: number, endX: number, endY: number) - => Promise - -type SetZoomCallback = (newZoomLevel: number) => void - -type ZoomDetails = { - currentZoomLevel: number, - maxZoomLevel: number, - zoomStep: number -} - -type HoverOverAreaCallback = (areaId?: string) => void +import { AddAreaToStoreCallback, HoverOverAreaCallback, MouseCoordinates, RectangleCoordinates, SetZoomCallback, ZoomDetails } from './types' /** * @param uiCanvas diff --git a/frontend/components/DocumentCanvas/types.ts b/frontend/components/DocumentCanvas/types.ts new file mode 100644 index 0000000..cf61d59 --- /dev/null +++ b/frontend/components/DocumentCanvas/types.ts @@ -0,0 +1,19 @@ +export type MouseCoordinates = { + startMouseX: number, startMouseY: number, endMouseX: number, endMouseY: number +} + +export type RectangleCoordinates = { + startX: number, startY: number, endX: number, endY: number +} + +export type AddAreaToStoreCallback = (startX: number, startY: number, endX: number, endY: number) => Promise + +export type SetZoomCallback = (newZoomLevel: number) => void + +export type ZoomDetails = { + currentZoomLevel: number, + maxZoomLevel: number, + zoomStep: number +} + +export type HoverOverAreaCallback = (areaId?: string) => void \ No newline at end of file diff --git a/frontend/components/workspace/Sidebar/DocumentLineItem.tsx b/frontend/components/workspace/Sidebar/DocumentLineItem.tsx index cc0e25a..aa2890f 100644 --- a/frontend/components/workspace/Sidebar/DocumentLineItem.tsx +++ b/frontend/components/workspace/Sidebar/DocumentLineItem.tsx @@ -56,7 +56,7 @@ const DocumentLineItem = (props: { document: SidebarDocument, groupId: string, i return (
  • - {!props.document.areas.length + {!props.document.areas?.length ?
    onDocumentClickHandler(props.document.id)} @@ -149,52 +149,6 @@ const DocumentLineItem = (props: { document: SidebarDocument, groupId: string, i diff --git a/frontend/components/workspace/Sidebar/GroupLineItem.tsx b/frontend/components/workspace/Sidebar/GroupLineItem.tsx index 45839fa..4900d73 100644 --- a/frontend/components/workspace/Sidebar/GroupLineItem.tsx +++ b/frontend/components/workspace/Sidebar/GroupLineItem.tsx @@ -1,17 +1,14 @@ 'use client' import { DocumentPlusIcon, PlusIcon, XMarkIcon } from '@heroicons/react/24/outline' -import React, { useRef, useState } from 'react' +import React, { useRef } from 'react' import { useProject } from '../../../context/Project/provider' import classNames from '../../../utils/classNames' import onEnterHandler from '../../../utils/onEnterHandler' -import AddGroupInput from './AddGroupInput' import DocumentLineItem from './DocumentLineItem' import { useSidebar } from './provider' import { SidebarGroup } from './types' - - const GroupLineItem = (props: { group: SidebarGroup, dragOverGroupId?: string }) => { const { requestAddDocument, @@ -58,10 +55,6 @@ const GroupLineItem = (props: { group: SidebarGroup, dragOverGroupId?: string }) setDragOverGroupId(groupId) } - const onGroupDragStart = (groupId: string) => { - setSelectedGroupId(groupId) - } - const onGroupDropEnd = (groupId: string) => { if (!groupId || groupId == dragOverGroupId) return @@ -136,140 +129,6 @@ const GroupLineItem = (props: { group: SidebarGroup, dragOverGroupId?: string })
      {props.group.documents.map((d, index) => ( - //
    • - // {!d.areas.length - // ? - //
      onDocumentClickHandler(d.id)} - // onDoubleClick={() => onDocumentDoubleClickHandler(d.id)} - // className={classNames( - // d.id === selectedDocumentId - // ? 'bg-gray-900 text-white' - // : 'text-gray-300 hover:bg-gray-700 hover:text-white', - // 'group items-center py-2 text-base font-medium rounded-b-md pl-10', - // index !== 0 ? 'rounded-t-md' : '', - // )}> - // {selectedDocumentId === d.id && isEditDocumentNameInputShowing - // ? { - // onEnterHandler(event, - // () => onConfirmDocumentNameChangeHandler(event.currentTarget.value)) - // }} - // ref={editDocumentNameTextInput} - // /> - // : - // {d.name} - // - // } - //
      - // :
      - // onDocumentClickHandler(d.id)} - // onDoubleClick={() => onDocumentDoubleClickHandler(d.id)} - // className={classNames( - // d.id === selectedDocumentId - // ? 'bg-gray-900 text-white' - // : 'text-gray-300 hover:bg-gray-700 hover:text-white', - // 'group items-center py-2 text-base font-medium rounded-b-md pl-6', - // index !== 0 ? 'rounded-t-md' : '', - - // )}> - // {selectedDocumentId === d.id && isEditDocumentNameInputShowing - // ? { - // onEnterHandler(event, - // () => onConfirmDocumentNameChangeHandler(event.currentTarget.value)) - // }} - // ref={editDocumentNameTextInput} - // /> - // : - // {d.name} - // - // } - // - // - //
      - // } - //
    • ))} {renderAddNewDocument(props.group.id)} diff --git a/frontend/components/workspace/Sidebar/makeDefaultSidebar.ts b/frontend/components/workspace/Sidebar/makeDefaultSidebar.ts index cc45a09..1db8b35 100644 --- a/frontend/components/workspace/Sidebar/makeDefaultSidebar.ts +++ b/frontend/components/workspace/Sidebar/makeDefaultSidebar.ts @@ -16,6 +16,10 @@ const makeDefaultSidebar = (): SidebarContextType => ({ setIsAddNewGroupInputShowing: (_: boolean) => {}, isEditAreaNameInputShowing: false, setIsEditAreaNameInputShowing: (_: boolean) => {}, + dragOverGroupId: '', + setDragOverGroupId: (_: string) => {}, + dragOverAreaId: '', + setDragOverAreaId: (_: string) => {}, }) export default makeDefaultSidebar \ No newline at end of file diff --git a/frontend/components/workspace/Sidebar/navigationProps.ts b/frontend/components/workspace/Sidebar/navigationProps.ts index f357b1f..6144101 100644 --- a/frontend/components/workspace/Sidebar/navigationProps.ts +++ b/frontend/components/workspace/Sidebar/navigationProps.ts @@ -8,7 +8,7 @@ const getNavigationProps = (documents: entities.Document[], groups: entities.Gro .map(d => ({ id: d.id, name: d.name, - areas: d.areas.map(a => ({ id: a.id, name: a.name, order: a.order }))//.sort((a, b) => a.order - b.order) + areas: d.areas?.map(a => ({ id: a.id, name: a.name, order: a.order }))//.sort((a, b) => a.order - b.order) })) return { @@ -23,7 +23,7 @@ const getNavigationProps = (documents: entities.Document[], groups: entities.Gro .map(d => ({ id: d.id, name: d.name, - areas: d.areas.map(a => ({ id: a.id, name: a.name, order: a.order }))//.sort((a, b) => a.order - b.order) + areas: d.areas?.map(a => ({ id: a.id, name: a.name, order: a.order }))//.sort((a, b) => a.order - b.order) })) return [