diff --git a/src/components/SelectionActionDetail.tsx b/src/components/SelectionActionDetail.tsx new file mode 100644 index 0000000..7661acb --- /dev/null +++ b/src/components/SelectionActionDetail.tsx @@ -0,0 +1,65 @@ +import { IonBadge, IonButton, IonContent, IonIcon, IonInput, IonItem, IonLabel, IonPopover } from "@ionic/react" +import { trashOutline, eyeOutline, chevronForward, downloadOutline, checkmark } from "ionicons/icons" +import { useEffect, useState } from "react" + +import { InventorySelection } from "../context/inventory-selection.model" +import { useOffline } from "../context/offline" +import { useSelection } from "../context/selection" + +const SelectionActionDetail: React.FC<{selection: InventorySelection}> = ({ selection }) => { + // context to handle the name changes + const [currentTitle, setCurrentTitle] = useState('') + + // subscribe to the current active selection + const { activeSelection, setActiveSelection } = useSelection() + + // get some selection context functions + const { dropSelection, updateSelection } = useOffline() + + // add a handler to change the title + const onUpdateTitle = () => { + updateSelection({...selection, title: currentTitle}) + } + + useEffect(() => { + if (selection.title) { + setCurrentTitle(selection.title) + } + }, [selection]) + + return ( + + {selection.title} + {selection.treeIds.length} + { activeSelection?.selection.id === selection.id ? (<> + + + + + + + setCurrentTitle(e.target.value as string)} /> + + + + + + + + + dropSelection(selection.id)}> + + + + + + ) : ( + setActiveSelection(selection.id)}> + + + )} + + ) +} + +export default SelectionActionDetail \ No newline at end of file diff --git a/src/components/SelectionList.tsx b/src/components/SelectionList.tsx index 693a849..b13e82b 100644 --- a/src/components/SelectionList.tsx +++ b/src/components/SelectionList.tsx @@ -1,35 +1,29 @@ -import { IonBadge, IonButton, IonIcon, IonItem, IonLabel, IonList } from "@ionic/react" -import { trashOutline } from "ionicons/icons" +import { IonBadge, IonButton, IonContent, IonIcon, IonInput, IonItem, IonLabel, IonList, IonPopover } from "@ionic/react" +import { trashOutline, eyeOutline, chevronForward, downloadOutline, addCircleOutline, checkmark } from "ionicons/icons" import { useOffline } from "../context/offline" import { useSelection } from "../context/selection" +import SelectionActionDetail from "./SelectionActionDetail" const SelectionList: React.FC = () => { // load the selection-related functions from the offline context - // TODO: replace with data context, once implemented - const { createSelection, dropSelection } = useOffline() - const { selections } = useSelection() + const { createSelection } = useOffline() + const { selections, setActiveSelection } = useSelection() - // create random selection - DEBUG ONLY - const onCreateNewSelection = () => { - createSelection( - [42, 43, 44], - 'Deleopment Selection', - ) + // controller for adding new selections + const onNewSelection = () => { + createSelection([]).then(newSelection => { + setActiveSelection(newSelection.id) + }) } return ( {selections?.map((s) => ( - - {s.title} - {s.treeIds.length} - dropSelection(s.id)}> - - - + ))} - {/* NEW SELECTION */} - DELETE ALl + + + ) } diff --git a/src/pages/DesktopPage.tsx b/src/pages/DesktopPage.tsx index dcab8c0..15d583f 100644 --- a/src/pages/DesktopPage.tsx +++ b/src/pages/DesktopPage.tsx @@ -13,6 +13,8 @@ import { IonLabel, IonPage, IonRow, + IonSegment, + IonSegmentButton, IonTitle, IonToolbar, } from "@ionic/react"; @@ -21,7 +23,7 @@ import { closeCircleOutline, settingsOutline, } from "ionicons/icons"; -import React from "react"; +import React, { useState } from "react"; import InventoryList from "../components/InventoryList"; import MainMap from "../components/map-components/MainMapMaplibre"; import BaseLayerPopover from "../components/popover/BaseLayerPopover"; @@ -32,8 +34,12 @@ import FilterBarPopover from "../components/popover/RangeFilterPopover"; import MapButtonGroup from "../components/MapButtonGroup"; import ActiveMapSelectionButton from "../components/ActiveMapSelectionButton"; import VariableSelectionPopover from "../components/popover/VariableSelectionPopover"; +import SelectionList from "../components/SelectionList"; const DesktopPage: React.FC = () => { + // component state for rendering the correct sidebar + const [sidebarContent, setSidebarContent] = useState<'inventory' | 'selection'>('inventory') + return ( @@ -51,7 +57,15 @@ const DesktopPage: React.FC = () => {
- + setSidebarContent(e.target.value as 'inventory' | 'selection')}> + + Inventory + + + Selections + + + { sidebarContent === 'inventory' ? : }