Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ep 2096 results type label #8

Merged
merged 3 commits into from
Jul 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions packages/earth-map/src/components/list-item/component.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from 'react';
import Link from 'redux-first-router-link';

import './style.scss';

interface IProps {
title: string;
linkTo: {
type: string;
payload?: any;
};
key: string;
labels?: string[];
onClick?: () => void;
}

const ListItem = (props: IProps) => {
const {
title,
labels,
linkTo,
key,
onClick = () => { },
} = props;

return (
<Link
to={linkTo}
onClick={onClick} key={key}
className="ng-c-list-item ng-unstyled ng-padding-small-vertical ng-padding-medium-horizontal"
>
{title}
{labels.map((label, i) => (
<span className="ng-margin-left ng-color-mdgray" key={`${label}-${i}`}>{label}</span>
))}
</Link>
)
};

export default ListItem;
1 change: 1 addition & 0 deletions packages/earth-map/src/components/list-item/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './component';
9 changes: 9 additions & 0 deletions packages/earth-map/src/components/list-item/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@import "~styles/config";

.ng-c-list-item {
display: block;

&:hover {
background-color: rgba($marapp-gray-1, .1);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';
import Link from 'redux-first-router-link';

import PLACEHOLDER from '../../../images/placeholder.png';
import ListItem from 'components/list-item';

interface IFeaturedPlaces {
featured?: {
Expand All @@ -24,25 +23,22 @@ const FeaturedPlacesComponent = (props: IFeaturedPlaces) => {
};

return (
<div className="ng-padding-medium ng-section-background ng-position-relative">
<h2 className="ng-text-display-s ng-body-color ng-margin-medium-bottom">Featured places</h2>
<div className="ng-section-background ng-position-relative ng-padding-medium-bottom">
<h2 className="ng-padding-medium ng-text-display-s ng-body-color ng-margin-remove">Featured places</h2>
<div>
{!!featured.data &&
featured.data.map((place: any) => {
const { slug, name, id, organization } = place;
const { slug, name, id, organization, type } = place;

return (
<Link
key={slug}
to={{ type: 'LOCATION', payload: { slug, id, organization } }}
className="ng-c-panel-link ng-unstyled ng-flex ng-margin-bottom"
>
<span onClick={() => onClickIndex(name)}>
{name}
{group.length > 1 && (
<span className="ng-margin-left ng-color-mdgray">{organization}</span>
)}
</span>
</Link>
<ListItem
title={name} key={slug}
linkTo={{ type: 'LOCATION', payload: { slug, id, organization } }}
onClick={() => onClickIndex(name)}
labels={[
type,
(group.length > 1) && organization
]} />
);
})}
</div>
Expand Down
29 changes: 14 additions & 15 deletions packages/earth-map/src/components/places/list/component.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react';
import Link from 'redux-first-router-link';
import List from '@researchgate/react-intersection-list';

import ListItem from 'components/list-item';

import './styles.scss';

interface IPlacesList {
Expand All @@ -21,6 +22,7 @@ interface IPlacesListItem {
id: string;
name: string;
organization: string;
type: string;
}

const PlacesResultsComponent = (props: IPlacesList) => {
Expand All @@ -38,19 +40,16 @@ const PlacesResultsComponent = (props: IPlacesList) => {
const hasNextPage = results.length >= PAGE_SIZE;
const awaitMore = !loading && !!nextPageCursor && hasNextPage;
const renderItem = (index) => {
const { slug, name, id, organization } = results[index];
const { slug, name, id, organization, type } = results[index];
return (
<div onClick={() => onClickIndex(name)} key={slug}>
<Link
to={{ type: 'LOCATION', payload: { slug, id, organization } }}
className="ng-c-panel-link ng-unstyled ng-margin-bottom"
>
{name}
{group.length > 1 && (
<span className="ng-margin-left ng-color-mdgray">{organization}</span>
)}
</Link>
</div>
<ListItem
title={name} key={slug}
linkTo={{ type: 'LOCATION', payload: { slug, id, organization } }}
onClick={() => onClickIndex(name)}
labels={[
type,
(group.length > 1) && organization
]} />
);
};
const onIntersection = (size, pageSize) => {
Expand All @@ -68,8 +67,8 @@ const PlacesResultsComponent = (props: IPlacesList) => {
};

return (
<div className="ng-padding-medium ng-section-background ng-position-relative">
<h2 className="ng-text-display-s ng-body-color ng-margin-medium-bottom">Search results</h2>
<div className="ng-section-background ng-position-relative ng-padding-medium-bottom">
<h2 className="ng-padding-medium ng-text-display-s ng-body-color ng-margin-remove">Search results</h2>
<List
awaitMore={awaitMore}
pageSize={PAGE_SIZE}
Expand Down