-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #563 from subugoe/global-tree-selection
Add the feature of Global Tree
- Loading branch information
Showing
18 changed files
with
319 additions
and
164 deletions.
There are no files selected for viewing
This file contains 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 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,42 @@ | ||
import { FC, ReactNode, useEffect, useState } from 'react' | ||
|
||
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover' | ||
|
||
interface ModalProps { | ||
children: ReactNode, | ||
TriggerButton?: ReactNode, | ||
showPopover?: boolean, | ||
position?: Position | ||
} | ||
|
||
const Modal: FC<ModalProps> = ({ | ||
children, TriggerButton, showPopover, position | ||
}) => { | ||
|
||
const [isOpen, setIsOpen] = useState(false) | ||
|
||
const handleOpenChange = (open: boolean) => { | ||
setIsOpen(open) | ||
} | ||
|
||
useEffect(() => { | ||
if (showPopover) setIsOpen(true) | ||
}, [position]) | ||
Check warning on line 24 in src/components/Modal.tsx
|
||
|
||
return <div className="local-tree-modal"> | ||
<Popover open={isOpen} onOpenChange={handleOpenChange}> | ||
<PopoverTrigger asChild> | ||
{TriggerButton} | ||
</PopoverTrigger> | ||
<PopoverContent | ||
style={{ | ||
top: `${position?.y + 40}px`, | ||
left: `${position?.x}px`, | ||
}}> | ||
{children} | ||
</PopoverContent> | ||
</Popover> | ||
</div> | ||
} | ||
|
||
export default Modal |
This file contains 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 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 |
---|---|---|
@@ -1,21 +1,52 @@ | ||
import { FC } from 'react' | ||
import { FC, useState } from 'react' | ||
|
||
import { configStore } from '@/store/ConfigStore.tsx' | ||
|
||
import Modal from '@/components/Modal.tsx' | ||
import TreeSelectionModalContent from '@/components/tree-modal/TreeSelectionModalContent.tsx' | ||
import IconRenderer from '@/components/base/IconRenderer.tsx' | ||
|
||
import { tree } from '@/utils/icons' | ||
import { cross } from '@/utils/icons' | ||
import { dataStore } from '@/store/DataStore.tsx' | ||
|
||
import TreeSelectionModal from '@/components/TreeSelectionModal' | ||
|
||
const TopBar: FC = () => { | ||
|
||
const [iconHtmlString, setIconHtmlString] = useState(tree) | ||
const globalTree = configStore(state => state.config.globalTree) | ||
|
||
const setShowGlobalTree = dataStore(state => state.setShowGlobalTree) | ||
|
||
function toggleIcon() { | ||
if (iconHtmlString === tree) { | ||
// we click the tree icon - now we show the global tree (set the value to true) | ||
setShowGlobalTree(true) | ||
setIconHtmlString(cross) | ||
} else if (iconHtmlString === cross) { | ||
setShowGlobalTree(false) | ||
setIconHtmlString(tree) | ||
} | ||
} | ||
|
||
const addButton = | ||
<span | ||
className="t-bg-blue-500 t-text-white t-rounded t-flex t-pl-4 t-items-center t-justify-items-center t-w-16 t-h-10"> | ||
New | ||
New | ||
</span> | ||
|
||
|
||
return <div className="t-flex t-flex-row t-ml-[6%] t-mt-10"> | ||
<TreeSelectionModal TriggerButton={addButton}/> | ||
<button className={`t-mr-2 toggle-global-tree ${!globalTree ? 't-hidden' : ''}`} onClick={() => toggleIcon()}> | ||
<IconRenderer | ||
htmlString={iconHtmlString} | ||
width={8} | ||
height={8}/> | ||
</button> | ||
<Modal TriggerButton={addButton}> | ||
<TreeSelectionModalContent/> | ||
</Modal> | ||
</div> | ||
|
||
} | ||
|
||
export default TopBar |
This file contains 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 was deleted.
Oops, something went wrong.
This file contains 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,30 @@ | ||
import { useEffect, useRef, FC, useState } from 'react' | ||
|
||
interface IconRendererProps { | ||
htmlString: string | ||
width?: number, | ||
height?: number | ||
} | ||
|
||
const IconRenderer: FC<IconRendererProps> = ({ htmlString, width, height }) => { | ||
const ref = useRef<HTMLInputElement>(null) | ||
|
||
const [iconWidth, setIconWidth] = useState(4) | ||
const [iconHeight, setIconHeight] = useState(4) | ||
|
||
useEffect(() => { | ||
if (width) setIconWidth(width) | ||
if (height) setIconHeight(height) | ||
|
||
if (ref?.current) { | ||
(ref.current as HTMLElement).innerHTML = htmlString | ||
const iconEls = ref.current.children | ||
|
||
const iconEl = iconEls[0] | ||
iconEl.classList.add('t-w-' + iconWidth, 't-h-' + iconHeight) | ||
} | ||
}, [htmlString, iconWidth, iconHeight]) | ||
Check warning on line 26 in src/components/base/IconRenderer.tsx
|
||
|
||
return <div ref={ref}></div> | ||
} | ||
export default IconRenderer |
This file contains 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
53 changes: 53 additions & 0 deletions
53
src/components/tree-modal/GlobalTreeSelectionModalContent.tsx
This file contains 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,53 @@ | ||
import { FC } from 'react' | ||
import { configStore } from '@/store/ConfigStore.tsx' | ||
|
||
|
||
interface SelectedItemIndicesType { | ||
collectionUrl: string, | ||
manifestIndex: number, | ||
itemIndex: number, | ||
} | ||
|
||
interface GlobalTreeSelectionModalContentProps { | ||
selectedItemIndices: SelectedItemIndicesType, | ||
} | ||
|
||
const GlobalTreeSelectionModalContent: FC<GlobalTreeSelectionModalContentProps> = ({ selectedItemIndices }) => { | ||
|
||
const panels = configStore(state => state.config.panels) | ||
const addNewPanel = configStore(state => state.addNewPanel) | ||
const updatePanel = configStore(state => state.updatePanel) | ||
|
||
const newPanelConfig = { | ||
entrypoint: { | ||
url: selectedItemIndices.collectionUrl, | ||
type: 'collection', | ||
}, | ||
manifestIndex: selectedItemIndices.manifestIndex, | ||
itemIndex: selectedItemIndices.itemIndex | ||
} | ||
|
||
let buttonsUpdatePanel | ||
if (panels && panels?.length > 0) { | ||
buttonsUpdatePanel = panels?.map((_, i) => <button | ||
className="t-bg-slate-200 t-w-20 t-h-8 t-mr-1 t-rounded-md hover:t-bg-slate-300" key={i} | ||
onClick={() => updatePanel( | ||
newPanelConfig | ||
, i)}>Panel {i + 1}</button>) | ||
} | ||
|
||
|
||
return ( | ||
<div | ||
className="t-flex t-items-center t-h-12 t-border-1 t-border-gray-300 t-px-4 t-py-2 t-shadow-md t-rounded-md "> | ||
<div className="buttons-update-panel t-flex"> | ||
{buttonsUpdatePanel} | ||
</div> | ||
<button className="button-new-panel t-bg-slate-200 t-w-24 t-h-8 t-mr-1 t-rounded-md hover:t-bg-slate-300" | ||
onClick={() => addNewPanel(newPanelConfig)}> New | ||
Panel | ||
</button> | ||
</div>) | ||
} | ||
|
||
export default GlobalTreeSelectionModalContent |
Oops, something went wrong.