Skip to content

Commit

Permalink
Merge pull request #12 from codeformuenster/update-dez
Browse files Browse the repository at this point in the history
Show details for our map items on click
  • Loading branch information
webwurst authored Dec 5, 2017
2 parents e34effc + f6bd52f commit b30da64
Show file tree
Hide file tree
Showing 26 changed files with 205 additions and 166 deletions.
16 changes: 13 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,27 @@ class App extends React.Component<IAppProps, any> {
<div className="tile is-parent">

<div className="tile">
<LunchMap results={this.state.results} updateHandler={this.updateSearchParams} searchParams={this.state.searchParams} districtPolygon={this.state.district} />

<LunchMap
results={this.state.results}
updateHandler={this.updateSearchParams}
searchParams={this.state.searchParams}
districtPolygon={this.state.district}
/>
</div>
</div>
<div className="tile is-parent">
<div className="tile">
<div className="article mainContent">
<div className="innerContent">
<div className="innerContent detailedItem">
{/* Geoselector will only be shown if you forbid GEO position access in your browser */}
{this.hasGeoSelector
&& <GeoSelector updateHandler={this.updateSearchParams} searchParams={this.state.searchParams} />}
<SearchResults updateHandler={this.updateSearchParams} results={this.state.results} searchParams={this.state.searchParams} />
<SearchResults
updateHandler={this.updateSearchParams}
results={this.state.results}
searchParams={this.state.searchParams}
/>
</div>
</div>
</div>
Expand Down
8 changes: 5 additions & 3 deletions src/Components/LunchMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class LunchMap extends React.Component<ILunchMapProps, any> {

const map = (

<Map center={position} zoom={13} ref={(el: any) => {this.mapRef = el; }}>
<Map center={position} zoom={14} ref={(el: any) => {this.mapRef = el; }}>
<TileLayer
url="https://{s}.tiles.mapbox.com/v4/mapbox.streets/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoiY29kZTRtcyIsImEiOiJjaXlpeWNuaW8wMDQ0MnFuNGhocGZjMzVlIn0.QBWu9vI5AYJq68dtVIqCJg"
attribution="&copy;<a href='https://www.mapbox.com/about/maps/'>Mapbox</a> &copy; <a href='http://www.openstreetmap.org/copyright'>OpenStreetMap</a> <strong><a href='https://www.mapbox.com/map-feedback/' target='_blank'>Improve this map</a></strong>"/>
Expand Down Expand Up @@ -74,7 +74,7 @@ class LunchMap extends React.Component<ILunchMapProps, any> {
}

let center = new LatLng( this.props.searchParams.latitude, this.props.searchParams.longitude);
let zoom = 13;
let zoom = 14;

if (this.centerPosition) {
center = this.centerPosition;
Expand Down Expand Up @@ -144,7 +144,9 @@ class LunchMap extends React.Component<ILunchMapProps, any> {
onpopupopen={markerOpenPopup}
ref={markerSaveRef}
>
<Popup>
<Popup
closeButton={false}
>
<span>{location.name}</span>
</Popup>
</Marker>
Expand Down
8 changes: 4 additions & 4 deletions src/Components/Lunchheader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ class Lunchheader extends React.Component<any,any> {
}

render() {
let currentDistrict = <p></p>
let currentDistrict = <p></p>;
if (this.state.district) {
currentDistrict = <p className="control">Du bist hier: {this.state.district}</p>
currentDistrict = <p className="control">Du bist hier: <span className="lunchtext">{this.state.district}</span></p>;
}
return (
<div>
Expand Down Expand Up @@ -86,9 +86,9 @@ class Lunchheader extends React.Component<any,any> {
<a className="navbar-item" href="/copyright">
Copyright
</a>
<a className="navbar-item" href="/team">
{/*<a className="navbar-item" href="/team">
Team
</a>
</a>*/}
<a className="navbar-item" href="/impressum">
Kontakt &amp; Impressum
</a>
Expand Down
20 changes: 20 additions & 0 deletions src/Components/SearchResultDetailled.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
div.properties {
margin-top:20px;
}

div.properties span {
display:block;
margin-top:3px;
}
div.properties span i {
font-weight:bold;
}

.detailedItem {
width:100%;
height:100%
}

.closeBtn {
margin-right:-10px;
}
147 changes: 147 additions & 0 deletions src/Components/SearchResultDetailled.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
import * as React from 'react';
// import { SearchResults } from './SearchResults/SearchResults';
import { ISearchParams, ISearchResult } from '../App';
import './SearchResultDetailled.css';

interface ISearchResultDetailledProps {
result: ISearchResult;
updateHandler: any;
searchParams: ISearchParams;
}

class SearchResultDetailled extends React.Component<ISearchResultDetailledProps, any> {

render() {
console.log('Rendering pool search result');

const result = this.props.result;
console.log('Detailled result:', result);

return (
<article
key={result.id}
className="notification detailedItem"
>
<div className="media">
<div className="media-left">
<p>
<span className="icon is-large">
<i className="mdi mdi-48px mdi-calendar-text"></i>
</span>
</p>
<div className="distanceDiv has-text-centered">
<span className="tag is-white">{this.distancePrettifier(result.distance)}</span>
</div>
</div>
<div className="media-content">
<div className="content">
<div className="pull-right closeBtn">
<button onClick={e => this.toggleSelection()} className="delete" aria-label="delete"></button>
</div>
<span className="title">
<span>{result.name} &nbsp; </span>
<span className="tag is-dark">{result.type}</span> &nbsp;
</span>
<div className="is-clearfix">

{result.url && (
<a href={result.url} target="_blank">
<span className="icon is-large">
<i className="mdi mdi-16px mdi-web"></i>
</span>
Webseite besuchen
</a>
)}

{result.dateStart && (
<div>
<p className="has-text-danger">
<span className="icon">
<i className="mdi mdi-timetable"></i>
</span>
Startdatum: {this.toHumanReadableDate(result.dateStart)}
</p>
<p className="has-text-danger">
<span className="icon">
<i className="mdi mdi-timetable"></i>
</span>
Enddatum: {result.dateEnd ? this.toHumanReadableDate(result.dateEnd) : 'unbekannt'}
</p>
</div>
)}

<div className="properties">
<span><i>Typ:</i> {this.props.result.type}</span>
{this.renderProperties(result.properties)}
</div>
</div>
</div>
</div>
</div>
</article>
);
}

componentDidMount () {
window.scrollTo(0, 0);
}

protected isoDateStringToDate(date: string): any {
return new Date(Date.parse(date));
}

protected toHumanReadableDate(date: any): string {
return this.isoDateStringToDate(date).toLocaleDateString('de-DE');
}

protected distancePrettifier(dist: number): string {
return '' + Math.round(dist) + 'm';
}

protected getMinutesByFeet(dist: number): string {
return Math.round(dist / 80) + ' Min.';
}

protected getMinutesByCar(dist: number): string {
return Math.round(dist / 250) + ' Min.';
}

protected isRunning(wlanStatus: string): boolean {
return wlanStatus === 'in Bearbeitung';
}

private capitalizeFirstLetter(str: string) {
return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
}

private renderProperties(properties: any) {
const response = [];

for (const key in properties) {
if (key) {
switch (key.toLowerCase()) {
case 'rechtswert':
case 'hochwert':
case 'kita_id':
case 'e_name':
case 'rechts':
case 'lfdnr':
case 'hoch':
case 'id':
continue;
default:
}
response.push(<span><i>{this.capitalizeFirstLetter(key)}:</i> {properties[key]}</span>);
}
}
return response;
}

private toggleSelection() {
const sp = this.props.searchParams;
sp.selectedId = 0;
this.props.updateHandler(sp);
}
}

export default SearchResultDetailled;
15 changes: 14 additions & 1 deletion src/Components/SearchResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import SearchResultsWifi from './SearchResults/SearchResultsWifi';
import SearchResultsWebcam from './SearchResults/SearchResultsWebcam';
import SearchResultsDefault from './SearchResults/SearchResultsDefault';
import SearchResultsEvent from './SearchResults/SearchResultsEvent';
import SearchResultDetailled from './SearchResultDetailled';

import './SearchResults.css';

Expand All @@ -27,12 +28,24 @@ class SearchResults extends React.Component<ISearchResultsProps, any> {
let results = this.props.results || [];
const searchParams = this.props.searchParams;

if (searchParams.selectedId) {
const result = results.find((element: ISearchResult) => searchParams.selectedId === element.id);
if (result) {
return (
<SearchResultDetailled
result={result}
searchParams={this.props.searchParams}
updateHandler={this.props.updateHandler}
/>
);
}
}

const limit = this.props.limit ? this.props.limit : 100;
if (results && results.length > limit) {
results = results.slice(0, this.props.limit);
}

console.log('Rendering results');
return (
<div className="search_results">
{results.map((result: ISearchResult) => {
Expand Down
2 changes: 1 addition & 1 deletion src/Components/SearchResults/SearchResults.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { ISearchResult } from '../../App';

interface ISearchResultsProps {
export interface ISearchResultsProps {
result: ISearchResult;
}

Expand Down
18 changes: 0 additions & 18 deletions src/Components/SearchResults/SearchResultsConstruction.css

This file was deleted.

2 changes: 0 additions & 2 deletions src/Components/SearchResults/SearchResultsConstruction.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import * as React from 'react';
import { SearchResults } from './SearchResults';

import './SearchResultsConstruction.css';

class SearchResultsConstruction extends SearchResults {

render() {
Expand Down
2 changes: 0 additions & 2 deletions src/Components/SearchResults/SearchResultsDefault.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import * as React from 'react';
import { SearchResults } from './SearchResults';

import './SearchResultsPool.css';

class SearchResultsDefault extends SearchResults {

render() {
Expand Down
2 changes: 0 additions & 2 deletions src/Components/SearchResults/SearchResultsEvent.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import * as React from 'react';
import { SearchResults } from './SearchResults';

import './SearchResultsPool.css';

class SearchResultsEvent extends SearchResults {

render() {
Expand Down
2 changes: 0 additions & 2 deletions src/Components/SearchResults/SearchResultsKindergarden.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import * as React from 'react';
import { SearchResults } from './SearchResults';

import './SearchResultsKindergarden.css';

class SearchResultsKindergarden extends SearchResults {

render() {
Expand Down
22 changes: 0 additions & 22 deletions src/Components/SearchResults/SearchResultsLunch.css

This file was deleted.

2 changes: 0 additions & 2 deletions src/Components/SearchResults/SearchResultsLunch.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import * as React from 'react';
import { SearchResults } from './SearchResults';

import './SearchResultsLunch.css';

class SearchResultsLunch extends SearchResults {

render() {
Expand Down
Loading

0 comments on commit b30da64

Please sign in to comment.