From e7db5aa4f3b1dcd090f035e495044e64d6825553 Mon Sep 17 00:00:00 2001 From: Piotr Janosz Date: Tue, 23 Jul 2019 16:04:53 +0200 Subject: [PATCH] Fixed filters, connected to algolia --- .../ts/components/docs/sidebar/filter.tsx | 47 ++--- .../ts/components/docs/sidebar/filters.tsx | 51 ++---- .../components/docs/sidebar/filters_group.tsx | 30 ++++ packages/website/ts/pages/docs/guides.tsx | 42 +---- .../website/ts/pages/docs/page_template.tsx | 42 +---- packages/website/ts/pages/docs/tools.tsx | 168 ++++++------------ 6 files changed, 127 insertions(+), 253 deletions(-) create mode 100644 packages/website/ts/components/docs/sidebar/filters_group.tsx diff --git a/packages/website/ts/components/docs/sidebar/filter.tsx b/packages/website/ts/components/docs/sidebar/filter.tsx index 246c51b02e..49c1b6cf02 100644 --- a/packages/website/ts/components/docs/sidebar/filter.tsx +++ b/packages/website/ts/components/docs/sidebar/filter.tsx @@ -3,46 +3,47 @@ import styled from 'styled-components'; import { colors } from 'ts/style/colors'; -export interface IFilterProps { - name: string; - value: string; +export interface IFilterProps extends IFilterCheckboxProps { label: string; + value: string; + refine: (value: string) => void; } -export const Filter: React.FC = ({ value, name, label }) => ( - - - - {label} - -); +interface IFilterCheckboxProps { + isRefined: boolean; +} + +export const Filter: React.FC = ({ isRefined, label, value, refine }) => { + const handleClick = () => refine(value); + + return ( + + + {label} + + ); +}; const FilterWrapper = styled.label` cursor: pointer; display: flex; align-items: center; - margin-bottom: 0.833333333rem; + margin-bottom: 0.83rem; `; -const FilterInput = styled.input.attrs({ type: 'checkbox' })` - position: absolute; - opacity: 0; -`; - -const FilterCheckbox = styled.div` +const FilterCheckbox = styled.div<{ isRefined: boolean }>` border: 1px solid #cbcbcb; width: 22px; height: 22px; - margin-right: 0.666rem; + margin-right: 0.67rem; - ${FilterInput}:checked ~ & { - background: url("data:image/svg+xml,%3Csvg width='16' height='16' viewBox='0 0 16 16' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M5.983 12.522c-.21 0-.4-.07-.557-.226l-3.46-3.461a.777.777 0 0 1 0-1.113.777.777 0 0 1 1.112 0L6 10.626l6.94-6.922a.777.777 0 0 1 1.112 0c.313.313.313.8 0 1.113l-7.495 7.479a.83.83 0 0 1-.574.226z' fill='currentColor'/%3E%3C/svg%3E") - no-repeat center; - } + ${({ isRefined }) => + isRefined && + `background: url("data:image/svg+xml,%3Csvg width='16' height='16' viewBox='0 0 16 16' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M5.983 12.522c-.21 0-.4-.07-.557-.226l-3.46-3.461a.777.777 0 0 1 0-1.113.777.777 0 0 1 1.112 0L6 10.626l6.94-6.922a.777.777 0 0 1 1.112 0c.313.313.313.8 0 1.113l-7.495 7.479a.83.83 0 0 1-.574.226z' fill='currentColor'/%3E%3C/svg%3E") no-repeat center;`}; `; const FilterLabel = styled.span` - font-size: 0.833rem; color: ${colors.textDarkPrimary}; + font-size: 0.83rem; font-weight: 300; `; diff --git a/packages/website/ts/components/docs/sidebar/filters.tsx b/packages/website/ts/components/docs/sidebar/filters.tsx index 3c03e4fd77..91a741c47c 100644 --- a/packages/website/ts/components/docs/sidebar/filters.tsx +++ b/packages/website/ts/components/docs/sidebar/filters.tsx @@ -1,53 +1,26 @@ import React from 'react'; -import { Filter } from 'ts/components/docs/sidebar/filter'; -import { Heading } from 'ts/components/text'; +import { FiltersGroup } from 'ts/components/docs/sidebar/filters_group'; -import { colors } from 'ts/style/colors'; import { styled } from 'ts/style/theme'; -export interface IFiltersProps { - groups: FilterGroup[]; +interface IFiltersProps { + filters: IFiltersGroupProps[]; } - -export interface FilterGroup { +interface IFiltersGroupProps { + attribute: string; heading: string; - name: string; - filters: IFilterProps[]; } -interface IFilterProps { - value: string; - label: string; -} - -export const Filters: React.FC = ({ groups }) => { - return ( - - {groups.map(({ heading, name, filters }: FilterGroup, groupIndex) => ( - - {heading} - {filters.map(({ value, label }: IFilterProps, filterIndex) => ( - - ))} - - ))} - - ); -}; +export const Filters: React.FC = ({ filters }) => ( + + {filters.map((filter: IFiltersGroupProps, index: number) => ( + + ))} + +); const FiltersWrapper = styled.aside` position: relative; max-width: 700px; `; - -const FiltersGroupWrapper = styled.div` - margin-bottom: 2.22em; -`; - -const FilterGroupHeading = styled(Heading)` - color: ${colors.textDarkPrimary}; - font-size: 1rem !important; - font-weight: 400 !important; - margin-bottom: 1em !important; -`; diff --git a/packages/website/ts/components/docs/sidebar/filters_group.tsx b/packages/website/ts/components/docs/sidebar/filters_group.tsx new file mode 100644 index 0000000000..154d69b8ba --- /dev/null +++ b/packages/website/ts/components/docs/sidebar/filters_group.tsx @@ -0,0 +1,30 @@ +import React from 'react'; +import { connectRefinementList } from 'react-instantsearch-dom'; + +import { Filter, IFilterProps } from 'ts/components/docs/sidebar/filter'; +import { Heading } from 'ts/components/text'; + +import { styled } from 'ts/style/theme'; + +interface IFilterListProps { + heading: string; + items: IFilterProps[]; + refine: (value: string) => void; +} + +const FiltersList: React.FC = ({ items, heading, refine }) => ( + + + {heading} + + {items.map((item: IFilterProps, index: number) => ( + + ))} + +); + +export const FiltersGroup = connectRefinementList(FiltersList); + +const FiltersGroupWrapper = styled.div` + margin-bottom: 2.22em; +`; diff --git a/packages/website/ts/pages/docs/guides.tsx b/packages/website/ts/pages/docs/guides.tsx index d83aa50be4..d0579d38da 100644 --- a/packages/website/ts/pages/docs/guides.tsx +++ b/packages/website/ts/pages/docs/guides.tsx @@ -3,7 +3,7 @@ import styled from 'styled-components'; import { Hero } from 'ts/components/docs/hero'; import { Resource } from 'ts/components/docs/resource/resource'; -import { FilterGroup, Filters } from 'ts/components/docs/sidebar/filters'; +import { Filters } from 'ts/components/docs/sidebar/filters'; import { SiteWrap } from 'ts/components/docs/siteWrap'; import { DocumentTitle } from 'ts/components/document_title'; import { Section } from 'ts/components/newLayout'; @@ -16,7 +16,7 @@ export const DocsGuides: React.FC = () => {
- +
{resources.map((resource, index) => ( @@ -39,46 +39,14 @@ const Columns = styled.div` } `; -const filterGroups: FilterGroup[] = [ +const filters = [ { + attribute: 'Topic', heading: 'Topic', - name: 'topic', - filters: [ - { - value: 'Mesh', - label: 'Mesh', - }, - { - value: 'Testing', - label: 'Testing', - }, - { - value: 'Coordinator Model', - label: 'Coordinator Model', - }, - { - value: 'Protocol developer', - label: 'Protocol developer', - }, - ], }, { + attribute: 'Difficulty', heading: 'Level', - name: 'level', - filters: [ - { - value: 'Beginner', - label: 'Beginner', - }, - { - value: 'Intermediate', - label: 'Intermediate', - }, - { - value: 'Advanced', - label: 'Advanced', - }, - ], }, ]; diff --git a/packages/website/ts/pages/docs/page_template.tsx b/packages/website/ts/pages/docs/page_template.tsx index 384ae8f08c..22f124fc31 100644 --- a/packages/website/ts/pages/docs/page_template.tsx +++ b/packages/website/ts/pages/docs/page_template.tsx @@ -13,7 +13,7 @@ import { Notification } from 'ts/components/docs/notification'; import { OrderedList } from 'ts/components/docs/ordered_list'; import { Resource } from 'ts/components/docs/resource/resource'; import { Separator } from 'ts/components/docs/separator'; -import { FilterGroup, Filters } from 'ts/components/docs/sidebar/filters'; +import { Filters } from 'ts/components/docs/sidebar/filters'; import { SiteWrap } from 'ts/components/docs/siteWrap'; import { IStepLinkConfig } from 'ts/components/docs/step_link'; import { StepLinks } from 'ts/components/docs/step_links'; @@ -32,7 +32,7 @@ export const DocsPageTemplate: React.FC = () => {
- + Large Heading @@ -286,46 +286,14 @@ const usefulLinks: IStepLinkConfig[] = [ }, ]; -const filterGroups: FilterGroup[] = [ +const filters = [ { + attribute: 'Topic', heading: 'Topic', - name: 'topic', - filters: [ - { - value: 'Mesh', - label: 'Mesh', - }, - { - value: 'Testing', - label: 'Testing', - }, - { - value: 'Coordinator Model', - label: 'Coordinator Model', - }, - { - value: 'Protocol developer', - label: 'Protocol developer', - }, - ], }, { + attribute: 'Difficulty', heading: 'Level', - name: 'level', - filters: [ - { - value: 'Beginner', - label: 'Beginner', - }, - { - value: 'Intermediate', - label: 'Intermediate', - }, - { - value: 'Advanced', - label: 'Advanced', - }, - ], }, ]; diff --git a/packages/website/ts/pages/docs/tools.tsx b/packages/website/ts/pages/docs/tools.tsx index 5cf0fc34ed..5bed7168c3 100644 --- a/packages/website/ts/pages/docs/tools.tsx +++ b/packages/website/ts/pages/docs/tools.tsx @@ -4,7 +4,7 @@ import styled from 'styled-components'; import { FeatureLink } from 'ts/components/docs/feature_link'; import { Hero } from 'ts/components/docs/hero'; import { Resource } from 'ts/components/docs/resource/resource'; -import { FilterGroup, Filters } from 'ts/components/docs/sidebar/filters'; +import { Filters } from 'ts/components/docs/sidebar/filters'; import { SiteWrap } from 'ts/components/docs/siteWrap'; import { DocumentTitle } from 'ts/components/document_title'; import { Section } from 'ts/components/newLayout'; @@ -12,51 +12,63 @@ import { Heading } from 'ts/components/text'; import { documentConstants } from 'ts/utils/document_meta_constants'; +import { ClearRefinements, Hits, InstantSearch } from 'react-instantsearch-dom'; + +import algoliasearch from 'algoliasearch/lite'; + +const searchClient = algoliasearch('39X6WOJZKW', '6acba761a34d99781628c6178af1e16c'); + export const DocsTools: React.FC = () => { return (
- - -
- - - Featured Tools - - {featuredLinks.map((link, index) => ( - - ))} - + + - - - Docker Images - + + +
+ - {resources.map((resource, index) => ( - - ))} - + + + Featured Tools + + {featuredLinks.map((link, index) => ( + + ))} + - - - TypeScript Libraries - + + + Docker Images + - {resources.map((resource, index) => ( - - ))} - -
-
+ {resources.map((resource, index) => ( + + ))} +
+ + + + TypeScript Libraries + + + {resources.map((resource, index) => ( + + ))} + +
+
+
); @@ -81,87 +93,9 @@ const ResourcesWrapper = styled.div` margin-bottom: 40px; `; -const filterGroups: FilterGroup[] = [ - { - heading: 'Type', - name: 'type', - filters: [ - { - value: 'Docker images', - label: 'Docker images', - }, - { - value: 'Typescript/Javascript Libraries', - label: 'Typescript/Javascript Libraries', - }, - { - value: 'Python Libraries', - label: 'Python Libraries', - }, - { - value: 'Golang Libraries', - label: 'Golang Libraries', - }, - { - value: 'Starter projects', - label: 'Starter projects', - }, - { - value: 'Command-line tools', - label: 'Command-line tools', - }, - ], - }, - { - heading: 'Developer Persona', - name: 'developerPersona', - filters: [ - { - value: 'Relayer', - label: 'Relayer', - }, - { - value: 'Trader', - label: 'Trader', - }, - { - value: 'Instant integrator', - label: 'Instant integrator', - }, - { - value: 'Protocol developer', - label: 'Protocol developer', - }, - ], - }, - { - heading: 'Level', - name: 'level', - filters: [ - { - value: 'Beginner', - label: 'Beginner', - }, - { - value: 'Intermediate', - label: 'Intermediate', - }, - { - value: 'Advanced', - label: 'Advanced', - }, - ], - }, - { - heading: 'Communtity Maintained', - name: 'communityMaintained', - filters: [ - { - value: '1', - label: 'Include Community Maintained', - }, - ], - }, +const filters = [ + { attribute: 'tags', heading: 'Developer persona' }, + { attribute: 'difficulty', heading: 'Difficulty' }, ]; const featuredLinks = [