Skip to content

Commit

Permalink
navigate selected users with browser history
Browse files Browse the repository at this point in the history
+ add a todo
+ fix potential undefined with conditional
  • Loading branch information
mrkvon committed Jul 21, 2021
1 parent 780ff46 commit cdba7c8
Show file tree
Hide file tree
Showing 5 changed files with 188 additions and 29 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

## TODO

- add people to history of browser (will allow browsing)
- make people a variable size based on how many people know them
- show clearly what are the directions of :knows
- show also who knows this person
- login for different pod providers
- faster (parallel) crawling
- [x] add people to history of browser (will allow browsing)
- [ ] make people a variable size based on how many people know them
- [ ] show clearly what are the directions of :knows
- [ ] show also who knows this person
- [ ] login for different pod providers
- [ ] faster (parallel) crawling
- [ ] search people
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
"@types/numeric": "^1.2.2",
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"@types/react-helmet": "^6.1.2",
"@types/react-modal": "^3.12.1",
"@types/react-router-dom": "^5.1.8",
"@types/styled-components": "^5.1.11",
"bulma": "^0.9.3",
"classnames": "^2.3.1",
Expand All @@ -31,7 +33,9 @@
"rdf-namespaces": "^1.9.2",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-helmet": "^6.1.0",
"react-modal": "^3.14.3",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.3",
"source-map-explorer": "^2.5.2",
"styled-components": "^5.3.0",
Expand Down
9 changes: 6 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import React from 'react'
import Layout from './components/Layout'
import DataContainer from './components/DataContainer'
import { BrowserRouter as Router } from 'react-router-dom'

const App: React.FC = () => (
<DataContainer>
<Layout />
</DataContainer>
<Router>
<DataContainer>
<Layout />
</DataContainer>
</Router>
)

export default App
46 changes: 30 additions & 16 deletions src/components/VisualizationContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import { Vector } from '../helpers/draw'
import { Grid } from '../helpers/draw'
import numeric from 'numeric'
import PersonCard from './PersonCard'
// import useSimulation from '../hooks/simulation'
import { withRouter, RouteComponentProps } from 'react-router-dom'
import { PeopleContext, Person } from './DataContainer'
import { IriString } from '@inrupt/solid-client'
import { Helmet } from 'react-helmet'

type PeopleGraph = {
[uri: string]: Person
Expand Down Expand Up @@ -91,15 +93,15 @@ const transformLayout = (
}),
)

if (highlighted) {
if (highlighted && transformedNodesDict[highlighted]) {
transformedNodesDict[highlighted].style = 'accent'
}

selectedDependencies.forEach(
uri => (transformedNodesDict[uri].style = 'accent'),
)
selectedDependencies.forEach(uri => {
if (transformedNodesDict[uri]) transformedNodesDict[uri].style = 'accent'
})

if (selected) {
if (selected && transformedNodesDict[selected]) {
transformedNodesDict[selected].style = 'focus'
}

Expand Down Expand Up @@ -129,10 +131,14 @@ const selectNodeDependencies = (
graph: PeopleGraph,
): string[] => {
if (!selectedNodeUri) return []
return Array.from(graph?.[selectedNodeUri].knows ?? new Set())
return Array.from(graph?.[selectedNodeUri]?.knows ?? new Set())
}

const VisualizationContainer: React.FC = props => {
const VisualizationContainer: React.FC<RouteComponentProps> = ({
location,
history,
...props
}: RouteComponentProps) => {
const [simulation] = useState(new Simulation())

const [layout, setLayout] = useState<SimulationGraph>({
Expand All @@ -141,7 +147,6 @@ const VisualizationContainer: React.FC = props => {
})

const [highlightedNode, setHighlightedNode] = useState<string | undefined>()
const [selectedNode, setSelectedNode] = useState<string | undefined>()

const people = useContext(PeopleContext)

Expand Down Expand Up @@ -207,7 +212,13 @@ const VisualizationContainer: React.FC = props => {
}

const handleHover = withNode(setHighlightedNode)
const handleSelect = withNode(setSelectedNode)
const selectNode = (node: IriString) => {
const uri = node ? `/${encodeURIComponent(node)}` : '/'
if (uri !== history.location.pathname) history.push(uri)
}
const handleSelect = withNode(selectNode)

const selectedNode = decodeURIComponent(location.pathname.slice(1))

const selectedNodeDependencies = selectNodeDependencies(selectedNode, people)
// transform layout to TransformedLayout
Expand Down Expand Up @@ -242,15 +253,18 @@ const VisualizationContainer: React.FC = props => {
{...props}
/>

<Helmet>
<title>
{selectedNode && `${people[selectedNode]?.name || selectedNode} - `}
Friend Crawler
</title>
</Helmet>

{person && knows && (
<PersonCard
person={person}
knows={knows}
onSelectPerson={uri => setSelectedNode(uri)}
/>
<PersonCard person={person} knows={knows} onSelectPerson={selectNode} />
)}
</>
)
}

export default VisualizationContainer
export default withRouter(VisualizationContainer)
Loading

0 comments on commit cdba7c8

Please sign in to comment.