diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..562cc64 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "pwa-chrome", + "request": "launch", + "name": "Launch Chrome against localhost", + "url": "http://localhost:3000", + "webRoot": "${workspaceFolder}" + } + ] +} \ No newline at end of file diff --git a/src/@types/explorePage.d.ts b/src/@types/explorePage.d.ts index d6dff32..2a90b9f 100644 --- a/src/@types/explorePage.d.ts +++ b/src/@types/explorePage.d.ts @@ -1,5 +1,5 @@ interface ExplorePageSidePanelType extends TogglePanel { - narrative: string; + narrativeStr: string; setNarrative: React.Dispatch>; } @@ -11,7 +11,7 @@ interface NarrativeType { visible: string[]; } -interface ExplorePageSidePanelType extends TogglePanel { +interface NarrativeTopPanelType extends TogglePanel{ narrative: string; setNarrative: React.Dispatch>; } diff --git a/src/App.tsx b/src/App.tsx index 72314ca..48de4c2 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -21,7 +21,9 @@ const MattapanMappingRoutes = () => ( } /> } /> } /> - } /> + }> + }/> + } /> } /> } /> diff --git a/src/molecules/MapStory.tsx b/src/molecules/MapStory.tsx index 7ab2129..7909de2 100644 --- a/src/molecules/MapStory.tsx +++ b/src/molecules/MapStory.tsx @@ -1,8 +1,9 @@ import React from 'react'; import { Scrollama, Step } from 'react-scrollama'; import { MapContext } from 'react-map-gl'; -import { Chapter, Header, Footer } from '@/atoms/MapStoryAtoms'; - +import { Chapter, Footer} from '@/atoms/MapStoryAtoms'; +import { NarrativeMenu } from '@/organisms/NarrativeMenu'; +import styled from '@emotion/styled'; const layerTypes = { 'fill': ['fill-opacity'], @@ -26,7 +27,14 @@ export function Story({ onMarkerCoordsChange, chapterData, headerTitle, headerSu const { map } = React.useContext(MapContext); const [mapRef, setMapRef]: [any, React.Dispatch>] = React.useState(map.current); - + + const StyledHeader = styled.header` + margin: auto; + width: 100%; + position: relative; + z-index: 5; + ` + React.useEffect(() => { setMapRef(map?.current?.getMap()); }, [map]) @@ -120,7 +128,12 @@ export function Story({ onMarkerCoordsChange, chapterData, headerTitle, headerSu return (
-
+ {/*
*/} +
props.theme.colors.white }; @@ -24,10 +26,10 @@ const NarrativeSelection = styled.div` flex-direction: column; `; -const NarrativeContainer = styled.div<{ color: string }>` +const NarrativeContainer = styled.div<{ color: string, width: string }>` background: ${ props => props.color }; height: 100vh; - width: 550px; + width: ${props => props.width}; display: flex; flex-direction: column; justify-content: center; @@ -53,6 +55,15 @@ const SelectedNarrativeTitle = styled(Title)` ` const Narratives = ({ onNarrativeChange }: { onNarrativeChange: (color: string, name: string) => void }) => { + let { narrativeStr } = useParams(); + useEffect(() =>{ + const found = NARRATIVES.find(({name, color, visible},i,ar) =>{ + return {color, name}; + }) + + // onNarrativeChange(found?.color??'', found?.name??''); + console.log('found color', found?.color??'') + },[narrativeStr] ); return ( <> Choose a narrative @@ -67,11 +78,11 @@ const Narratives = ({ onNarrativeChange }: { onNarrativeChange: (color: string, ); } -const NarrativePanel = ({ narrative, data, toggleState, toggleHandler, onNarrativeChange }: NarrativePanelType) => { - if (narrative) { +const NarrativePanel = ({ narrativeStr, data, toggleState, toggleHandler, onNarrativeChange }: NarrativePanelType) => { + if (narrativeStr) { return ( <> - { narrative } + { narrativeStr } onNarrativeChange(Theme.colors.peach, '') }>Choose another Narrative @@ -83,18 +94,49 @@ const NarrativePanel = ({ narrative, data, toggleState, toggleHandler, onNarrati ); } -export const ExplorePageNarratives = ({ narrative, data, toggleState, toggleHandler, setNarrative }: ExplorePageSidePanelType) => { +const NarrativeTopMenuPanel = ({ narrativeStr, data, toggleState, toggleHandler, onNarrativeChange }: NarrativePanelType) => { + if (narrativeStr) { + return ( + <> + { narrativeStr } + onNarrativeChange(Theme.colors.peach, '') }>Choose another Narrative + + ); + } + + return ( + + ); +} + +export const ExplorePageNarratives = ({ narrativeStr, data, toggleState, toggleHandler, setNarrative }: ExplorePageSidePanelType) => { const [narrativeColor, setNarrativeColor] = React.useState(Theme.colors.peach); + + const onNarrativeChange = (selectedNarrativeColor: string, selectedNarrative: string) => { + setNarrativeColor(selectedNarrativeColor);debugger + setNarrative(selectedNarrative) + }; + + return ( + + EXPLORE + + + ) +}; +export const NarrativeTopPanel = ({ narrativeStr, data, toggleState, toggleHandler, setNarrative }: ExplorePageSidePanelType) => { + const [narrativeColor, setNarrativeColor] = React.useState(Theme.colors.peach); + const onNarrativeChange = (selectedNarrativeColor: string, selectedNarrative: string) => { setNarrativeColor(selectedNarrativeColor); setNarrative(selectedNarrative) }; return ( - + EXPLORE - + ) }; diff --git a/src/organisms/NarrativeMenu.tsx b/src/organisms/NarrativeMenu.tsx new file mode 100644 index 0000000..ef193dd --- /dev/null +++ b/src/organisms/NarrativeMenu.tsx @@ -0,0 +1,58 @@ +import { ExplorePageToggleStates } from "@/data/ExplorePageData"; +import { useMapPageQuery } from "@/graphql/generated"; +import React from "react"; +import { NarrativeTopPanel } from "./Narrative"; +import { useNavigate, useParams } from 'react-router-dom'; +//import { useSearchParams } from 'react-router-dom'; + +export const NarrativeMenu = (props: any) => { + const { data: mapData } = useMapPageQuery(); + const [data] = React.useState>([]); + const [narrativeData, setNarrativeData] = React.useState>([]); + const [featureToggle, setFeatureToggle]= React.useState({}); + //const [narrative, setNarrative] = React.useState(''); + const { Narratives: gqlNarrative, Boundaries: gqlBoundaries } = mapData || {}; + const onToggleChange = (id: string) => { + setFeatureToggle({ ...featureToggle, [id]: !featureToggle[id] }); + }; + // let [searchParams, setSearchParams] = useSearchParams(); + let navigate = useNavigate(); + let { narrativeStr } = useParams(); + + React.useEffect(() => { + if (gqlNarrative !== undefined && gqlBoundaries !== undefined) { + const filteredNarratives = gqlNarrative.filter(({ name }) => name === narrativeStr); + if (filteredNarratives.length === 0) { + return; + } + const selectedNarrative = filteredNarratives[0]; + const dataWithNarrative: MapGeoJsonData[] = JSON.parse(JSON.stringify(data)); + + selectedNarrative.boundaries.forEach(({ id }) => { + if (id === undefined || id === null) { + return; + } + const boundaryIndex = gqlBoundaries.findIndex(({ id: bid }) => bid === id); + const boundaryName = gqlBoundaries[boundaryIndex].name; + const idx = dataWithNarrative.findIndex(landmark => landmark.id === boundaryName); + dataWithNarrative[idx].visible = true; + }); + + setNarrativeData(dataWithNarrative); + setFeatureToggle(ExplorePageToggleStates(dataWithNarrative)); + } else { + setNarrativeData(data); + setFeatureToggle({}); + } + }, [narrativeStr, data, gqlNarrative, gqlBoundaries]); + + return( + <> + + ) +} \ No newline at end of file diff --git a/src/pages/MapPage.tsx b/src/pages/MapPage.tsx index 5bc1b83..be28e18 100644 --- a/src/pages/MapPage.tsx +++ b/src/pages/MapPage.tsx @@ -7,6 +7,9 @@ import { Map } from '@/atoms/MapAtoms'; import { MapLayers } from '@/molecules/MapLayers'; import { Layout, StyledHeader, StyledFooter } from '@/templates/StandardLayout' import { useMapPageQuery } from '@/graphql/generated'; +// import { useNavigate } from 'react-router-dom'; +// import { useSearchParams } from 'react-router-dom'; + const MapContainer = styled.div` display: flex; @@ -31,6 +34,8 @@ export default function MapPage() { const [narrativeData, setNarrativeData] = React.useState>([]); const [featureToggle, setFeatureToggle]= React.useState({}); const [narrative, setNarrative] = React.useState(''); + // let [searchParams, setSearchParams] = useSearchParams(); + // let navigate = useNavigate(); const { Narratives: gqlNarrative, Boundaries: gqlBoundaries } = mapData || {}; @@ -40,6 +45,15 @@ export default function MapPage() { setFeatureToggle({ ...featureToggle, [id]: !featureToggle[id] }); }; + // function handleSubmit(event: { preventDefault: () => void; target: any; }) { + // event.preventDefault(); + // // The serialize function here would be responsible for + // // creating an object of { key: value } pairs from the + // // fields in the form that make up the query. + // let params = serializeFormQuery(event.target); + // setSearchParams(params); + // } + React.useEffect(() => { const fetchAll = async () => { try { @@ -98,7 +112,7 @@ export default function MapPage() { ) } + +