-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(layers): fetch layer definitions (#79)
- Loading branch information
1 parent
38f966b
commit 13a7199
Showing
11 changed files
with
156 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[ | ||
{ | ||
"id": "layer1", | ||
"name": "Layer 1", | ||
"description": "This is the first layer", | ||
"metadataUrl": "https://..." | ||
}, | ||
{ | ||
"id": "layer1a", | ||
"name": "Layer 1a", | ||
"description": "This is the first sublayer", | ||
"metadataUrl": "https://...", | ||
"parentId": "layer1" | ||
}, | ||
{ | ||
"id": "layer2", | ||
"name": "Layer 2", | ||
"description": "This is the second layer", | ||
"metadataUrl": "https://..." | ||
} | ||
] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import {Dispatch} from 'redux'; | ||
import config from '../config/main'; | ||
|
||
export const FETCH_LAYERS_SUCCESS = 'FETCH_LAYERS_SUCCESS'; | ||
export const FETCH_LAYERS_ERROR = 'FETCH_LAYERS_ERROR'; | ||
|
||
export interface Layer { | ||
id: string; | ||
name: string; | ||
description: string; | ||
metadataUrl: string; | ||
} | ||
|
||
export interface FetchLayersSuccessAction { | ||
type: typeof FETCH_LAYERS_SUCCESS; | ||
layers: Layer[]; | ||
} | ||
|
||
export interface FetchLayersErrorAction { | ||
type: typeof FETCH_LAYERS_ERROR; | ||
message: string; | ||
} | ||
|
||
function fetchLayersSuccessAction(layers: Layer[]) { | ||
return { | ||
type: FETCH_LAYERS_SUCCESS, | ||
layers | ||
}; | ||
} | ||
|
||
function fetchLayersErrorAction(message: string) { | ||
return { | ||
type: FETCH_LAYERS_ERROR, | ||
message | ||
}; | ||
} | ||
|
||
const fetchLayers = () => (dispatch: Dispatch) => { | ||
return fetch(config.api.layers) | ||
.then(res => res.json()) | ||
.then(layers => dispatch(fetchLayersSuccessAction(layers))) | ||
.catch(error => dispatch(fetchLayersErrorAction(error.message))); | ||
}; | ||
|
||
export default fetchLayers; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React, {FunctionComponent} from 'react'; | ||
import {Layer} from '../../actions/fetch-layers'; | ||
|
||
interface Props { | ||
layers: Layer[]; | ||
selected: string; | ||
onSelect: (id: string) => void; | ||
} | ||
|
||
const LayerList: FunctionComponent<Props> = ({layers, selected, onSelect}) => { | ||
return ( | ||
<ul> | ||
{layers.map(layer => ( | ||
<li key={layer.id} onClick={() => onSelect(layer.id)}> | ||
{layer.name} | ||
</li> | ||
))} | ||
</ul> | ||
); | ||
}; | ||
|
||
export default LayerList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import React, {FunctionComponent, useEffect, useState} from 'react'; | ||
import {useSelector, useDispatch} from 'react-redux'; | ||
import {layersSelector} from '../../reducers/layers'; | ||
import fetchLayers from '../../actions/fetch-layers'; | ||
import LayerList from '../layer-list/layer-list'; | ||
import {Dispatch} from 'redux'; | ||
|
||
const LayerSelector: FunctionComponent<{}> = () => { | ||
const layers = useSelector(layersSelector); | ||
const dispatch = useDispatch(); | ||
const [activeTab, setActiveTab] = useState(0); | ||
|
||
useEffect(() => { | ||
dispatch(fetchLayers()); | ||
}, []); | ||
|
||
return ( | ||
<div> | ||
{activeTab === 0 ? ( | ||
<LayerList | ||
layers={layers} | ||
onSelect={id => console.log('clicked', id)} | ||
selected={'layer1'} | ||
/> | ||
) : ( | ||
<LayerList | ||
layers={layers} | ||
onSelect={id => console.log('clicked', id)} | ||
selected={'layer1'} | ||
/> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default LayerSelector; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default { | ||
api: { | ||
layers: 'https://storage.googleapis.com/esa-cfs-storage/layers.json' | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters