From 9ce310d3feee11df26482aa94ff9b273d38211ad Mon Sep 17 00:00:00 2001 From: mrkvon Date: Thu, 22 Jul 2021 05:02:54 +0200 Subject: [PATCH] implement simple search It's still very inaccessible. Just works by clicking. --- README.md | 3 +- src/components/PersonCard.tsx | 114 ++++++++++------------ src/components/Search.tsx | 37 +++++++ src/components/VisualizationContainer.tsx | 69 +++++++++++-- src/index.scss | 1 + 5 files changed, 152 insertions(+), 72 deletions(-) create mode 100644 src/components/Search.tsx diff --git a/README.md b/README.md index c9daa42..6fa2fdf 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,8 @@ - [x] show also who knows this person - [ ] login for different pod providers - [x] faster (parallel) crawling -- [ ] search people +- [x] search people + - [ ] make it more accessible and easier to navigate - [ ] highlight also people who know the person - [ ] highlight people whose button is crawled in PersonList - [ ] add custom starting point for crawling diff --git a/src/components/PersonCard.tsx b/src/components/PersonCard.tsx index 0e760ea..cc49352 100644 --- a/src/components/PersonCard.tsx +++ b/src/components/PersonCard.tsx @@ -10,70 +10,58 @@ interface Props { const PersonCard = ({ person, knows, known, onSelectPerson }: Props) => { return ( -
-
-
-
-
- - {person.name || person.uri} - -
- {person.photo && ( -
-
- {person.name} -
-
- )} -
-

knows: {knows.length}

-
-
-
    - {knows.map(friend => ( -
  • onSelectPerson(friend.uri)} - key={friend.uri} - className="button is-link" - > - {friend.name} -
  • - ))} -
-
-
-

known by: {known.length}

-
-
-
    - {known.map(friend => ( -
  • onSelectPerson(friend.uri)} - key={friend.uri} - className="button is-link" - > - {friend.name} -
  • - ))} -
-
-
+
+
+

+ {person.name || person.uri} +

+ +
+ {person.photo && ( +
+
+ {person.name} +
-
+ )} +
+

knows: {knows.length}

+
+
+
    + {knows.map(friend => ( +
  • onSelectPerson(friend.uri)} + key={friend.uri} + className="button is-link" + > + {friend.name} +
  • + ))} +
+
+
+

known by: {known.length}

+
+
+
    + {known.map(friend => ( +
  • onSelectPerson(friend.uri)} + key={friend.uri} + className="button is-link" + > + {friend.name} +
  • + ))} +
+
) } diff --git a/src/components/Search.tsx b/src/components/Search.tsx new file mode 100644 index 0000000..c0b4755 --- /dev/null +++ b/src/components/Search.tsx @@ -0,0 +1,37 @@ +import React from 'react' + +interface Props { + onChange: (text: string) => void + onSelect: (text: string) => void + value: string + options: { value: string; label: string }[] +} + +const Search: React.FC = ({ + onChange, + onSelect, + value, + options, + ...props +}: Props) => ( +
+ onChange(e.target.value)} + /> +
+ +
+
+) + +export default Search diff --git a/src/components/VisualizationContainer.tsx b/src/components/VisualizationContainer.tsx index 1ed86f0..0c27347 100644 --- a/src/components/VisualizationContainer.tsx +++ b/src/components/VisualizationContainer.tsx @@ -6,6 +6,7 @@ import { Vector } from '../helpers/draw' import { Grid } from '../helpers/draw' import numeric from 'numeric' import PersonCard from './PersonCard' +import Search from './Search' import { withRouter, RouteComponentProps } from 'react-router-dom' import { PeopleContext, Person } from './DataContainer' import { IriString } from '@inrupt/solid-client' @@ -24,6 +25,31 @@ const transform = (matrix: number[][], vector: Vector): Vector => { return [x, y] } +interface ICProps { + children: React.ReactNode +} +const InfoContainer = ({ children }: ICProps) => ( +
+
+
+
+ {children} +
+
+
+
+) + type VisualizationNode = { x: number y: number @@ -154,6 +180,8 @@ const VisualizationContainer: React.FC = ({ links: [], }) + const [search, setSearch] = useState('') + const [highlightedNode, setHighlightedNode] = useState() const people = useContext(PeopleContext) @@ -268,16 +296,41 @@ const VisualizationContainer: React.FC = ({ - {person && knows && known && ( - - )} + + {person && knows && known ? ( + + ) : ( + + )} + ) } export default withRouter(VisualizationContainer) + +const selectSearchOptions = ( + query: string, + people: PeopleGraph, +): { value: string; label: string }[] => { + if (query.length < 2) return [] + return Object.values(people) + .filter( + ({ name, uri }) => + name.toLowerCase().includes(query.toLowerCase()) || + uri.toLowerCase().includes(query.toLowerCase()), + ) + .sort(({ known: a }, { known: b }) => (b?.size ?? 0) - (a?.size ?? 0)) + .map(({ name, uri }) => ({ value: uri, label: name || uri })) + .slice(0, 10) +} diff --git a/src/index.scss b/src/index.scss index a6489a1..1305564 100644 --- a/src/index.scss +++ b/src/index.scss @@ -4,6 +4,7 @@ @import '~bulma/sass/elements/button.sass'; @import '~bulma/sass/grid/columns.sass'; @import '~bulma/sass/components/card.sass'; +@import '~bulma/sass/components/menu.sass'; // You can use Bulma variables from here on