Skip to content

Commit

Permalink
implement Milan explorer
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancescoCioria committed Dec 29, 2018
1 parent 546aee2 commit 3e303ab
Show file tree
Hide file tree
Showing 40 changed files with 9,518 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"presets": [
["buildo", {
"env": "react",
"modules": false,
"targets": {
"chrome": 52,
"edge": 13,
"ie": 11
}
}]
]
}
3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "./node_modules/scriptoni/lib/scripts/eslint/eslintrc.json"
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
build
.vscode
7 changes: 7 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*.log
*.log*
node_modules
build/*
*.tags*
.eslintcache
.DS_Store
1 change: 1 addition & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('node_modules/scriptoni/lib/scripts/prettier/.prettierrc.js');
3 changes: 3 additions & 0 deletions .stylelintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "./node_modules/scriptoni/lib/scripts/stylelint/stylelintrc.json"
}
28 changes: 28 additions & 0 deletions config/Config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
Define here inside `bundle` the type of any additional configuration value that you'll need in your app,
and then update `production.json`, `development.json` and `local.json` accordingly.
A typical example is the "api endpoint" configuration key, ex:
bundle: t.strict({
apiEndpoint: t.string
})
Any config value can be overridden at build time by providing an environment variable with the appropriate name.
This envs variables are namspaced under `CONFIG_`.
For instance, to override the `apiEndpoint` configuration key, your CI can run:
CONFIG_API_ENDPOINT=/myDevApi yarn run build
*/

const t = require('io-ts');

module.exports = t.strict(
{
port: t.union([t.number, t.undefined]),
bundle: t.strict({})
},
'Config'
);
3 changes: 3 additions & 0 deletions config/development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"port": 3000
}
1 change: 1 addition & 0 deletions config/production.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
35 changes: 35 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "bike-routes-web",
"version": "1.0.0",
"scripts": {
"start": "bento web-dev -c ./config",
"build": "NODE_ENV=production bento web-build -c ./config",
"lint": "bento lint",
"lint-fix": "bento lint --fix",
"lint-style": "bento lint-style",
"prettier-check": "bento prettier-check",
"prettier-write": "bento prettier-write"
},
"dependencies": {
"@buildo/bento": "^10.0.0",
"classnames": "^2.2.5",
"es6-promise": "^4.2.2",
"geojson-length": "^0.1.1",
"lodash": "^4.17.4",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"string-to-color": "^2.0.1"
},
"devDependencies": {
"@types/classnames": "^2.2.3",
"@types/fixed-data-table": "^0.6.32",
"@types/lodash": "^4.14.93",
"@types/node": "^9.3.0",
"@types/qs": "^6.5.1",
"@types/react": "^16.0.34",
"@types/react-dom": "^16.0.3",
"@types/react-intl": "^2.3.3",
"@types/react-select": "^1.1.0",
"@types/react-transition-group": "^2.0.6"
}
}
26 changes: 26 additions & 0 deletions src/API/API.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Content, GeoJson } from "model";
import flatten = require("lodash/flatten");

export const getRoutes = (): Promise<GeoJson[]> => {
return fetch("https://api.github.com/repos/BikeRoutes/Milano/contents")
.then(res => res.json())
.then((contents: Content[]) => {
const folders = contents.filter(c => c.type === "dir");
return Promise.all(
folders.map(f =>
fetch(f.url).then(res => res.json() as Promise<Content[]>)
)
);
})
.then(flatten)
.then(contents =>
contents.filter(c => c.type === "file" && c.name.includes(".geojson"))
)
.then(contents => {
return Promise.all(
contents.map(c =>
fetch(c.download_url).then(r => r.json() as Promise<GeoJson>)
)
);
});
};
1 change: 1 addition & 0 deletions src/API/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './API';
3 changes: 3 additions & 0 deletions src/commands/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { doUpdateLocation } from "@buildo/bento/data";

export { doUpdateLocation };
1 change: 1 addition & 0 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './commands';
66 changes: 66 additions & 0 deletions src/components/App/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import * as React from "react";
import * as ReactDOMServer from "react-dom/server";
import { declareQueries } from "@buildo/bento/data";
import { collection } from "queries";
import { GeoJson } from "model";

import "./app.scss";

declare const L: any;

const queries = declareQueries({ collection });

type Feature = GeoJson["features"][number];

const Popup = (props: { feature: Feature }) => (
<div>
<div>Name: {props.feature.properties.name}</div>
<div>Length: {props.feature.properties.length} km</div>
<div>Elevation gain: {props.feature.properties.elevationGain} m</div>
</div>
);

class App extends React.Component<typeof queries.Props> {
componentDidUpdate() {
if (this.props.collection.ready) {
const onEachFeature = (feature: Feature, layer: any) => {
if (feature.properties) {
layer.bindPopup(
ReactDOMServer.renderToString(<Popup feature={feature} />)
);
}
};

const style = (feature: Feature) => ({
color: feature.properties.color
});

const map = L.map("map");
L.tileLayer(
"https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}",
{
id: "mapbox.streets",
accessToken:
"pk.eyJ1IjoiZnJhbmNlc2NvY2lvcmlhIiwiYSI6ImNqcThzMDJrejJ1bzgzeGxjZTZ2aXR0cHMifQ.qzCmhZEf3Ta1YHvAfli3bA"
}
).addTo(map);
const layer = L.geoJson(this.props.collection.value, {
onEachFeature,
style
}).addTo(map);
map.fitBounds(layer.getBounds());
}
}

render() {
const { collection } = this.props;

if (!collection.ready) {
return null;
}

return <div id="map" style={{ height: "100%", width: "100%" }} />;
}
}

export default queries(App);
3 changes: 3 additions & 0 deletions src/components/App/app.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.app {
margin: 20px;
}
2 changes: 2 additions & 0 deletions src/components/App/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import App from './App';
export default App;
3 changes: 3 additions & 0 deletions src/components/Dropdown/Dropdown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Dropdown from '@buildo/bento/components/Dropdown';
import './dropdown.scss';
export default Dropdown;
9 changes: 9 additions & 0 deletions src/components/Dropdown/dropdown.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@import '~theme/variables.scss';

$border-color-open: $azure;

$arrow-color: $coolGrey;
$arrow-color-hover: $darkGrey;
$arrow-color-open: $darkGrey;

@import '~@buildo/bento/components/dropdown.scss';
2 changes: 2 additions & 0 deletions src/components/Dropdown/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Dropdown from './Dropdown';
export default Dropdown;
2 changes: 2 additions & 0 deletions src/components/View/View.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import View from '@buildo/bento/components/FlexView';
export default View;
2 changes: 2 additions & 0 deletions src/components/View/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import View from './View';
export default View;
Loading

0 comments on commit 3e303ab

Please sign in to comment.