1
0
mirror of https://github.com/mgerb/mywebsite synced 2026-01-12 02:42:48 +00:00

fixed end point - fixed posts in metadata

This commit is contained in:
2016-09-13 04:37:56 +00:00
parent e558fe5da2
commit e5d340df5d
10 changed files with 102 additions and 18 deletions

View File

@@ -38,7 +38,7 @@ ReactDOM.render((
<Router history={history}>
<Route path="/" component={App}>
<IndexRoute component={Preview}/>
<Route path="post/:category/:post" component={Post}/>
<Route path="post(/:category)/:post" component={Post}/>
<Route path="sensor/:location" component={SensorInfo}/>
</Route>
</Router>

View File

@@ -21,7 +21,7 @@ export default class Post extends React.Component {
componentDidMount() {
const params = this.props.params;
this.props.appActions.fetchPost(params.category, params.post);
this.props.appActions.fetchPost(params.post, params.category);
}
render() {

View File

@@ -1,11 +1,31 @@
import React from 'react';
let location, sensor, actions, uniqueDates;
export default class SensorInfo extends React.Component{
componentDidMount(){
location = this.props.params.location;
actions = this.props.sensorActions;
sensor = this.props.sensor;
actions.fetchUniqueDates(location);
/*
this.props.sensorActions.fetchSensorInfoYear('Grand Meadow', '2016');
this.props.sensorActions.fetchSensorInfoMonth('Grand Meadow', '2016', 'May');
this.props.sensorActions.fetchUniqueDates('Grand Meadow');
*/
}
componentWillReceiveProps(){
if(sensor.fetchedUniqueDates){
uniqueDates = sensor.uniqueDates;
//!sensor.fetchedInfoMonth ? actions.fetchSensorInfoMonth(location, )
}
}
render(){
return(
<div class="Content">Test123</div>

View File

@@ -44,10 +44,14 @@ export function fetchPreview() {
}
}
export function fetchPost(category, post) {
//adjust url according to parameters
//mainly used to load md files in the parent directory within /posts
export function fetchPost(post, category = null) {
let url;
return (dispatch) => {
dispatch(fetching());
return fetch(`/public/posts/${category}/${post}.md`)
url = category !== null || typeof category === 'undefined' ? `/public/posts/${category}/${post}.md` : `/public/posts/${post}.md`;
return fetch(url)
.then(response => response.text())
.then(response => {
dispatch(loadPost(response));

View File

@@ -22,6 +22,13 @@ function loadSensorInfoMonth(sensor_info){
}
}
function loadUniqueDates(dates){
return{
type: types.LOAD_UNIQUE_DATES,
dates
}
}
function fetchingList(){
return {
type: types.FETCHING_LIST
@@ -40,6 +47,12 @@ function fetchingInfoMonth(){
}
}
function fetchingUniqueDates(){
return {
type: types.FETCHING_UNIQUE_DATES
}
}
export function fetchSensorList(){
return (dispatch) => {
dispatch(fetchingList());
@@ -80,4 +93,18 @@ export function fetchSensorInfoMonth(location, year, month){
console.log(error);
});
}
}
export function fetchUniqueDates(location){
return (dispatch) => {
dispatch(fetchingUniqueDates());
return fetch(`/api/uniquedates/${location}`)
.then(response => response.json())
.then(json => {
dispatch(loadUniqueDates(json));
})
.catch(error => {
console.log(error);
});
}
}

View File

@@ -2,9 +2,10 @@
export const LOAD_SENSOR_LIST = 'LOAD_SENSOR_LIST';
export const LOAD_SENSOR_INFO_YEAR = 'LOAD_SENSOR_INFO_YEAR';
export const LOAD_SENSOR_INFO_MONTH = 'LOAD_SENSOR_INFO_MONTH';
export const LOAD_UNIQUE_DATES = 'LOAD_UNIQUE_DATES';
//fetching
export const FETCHING_LIST = 'FETCHING_LIST';
export const FETCHING_INFO_YEAR = 'FETCHING_INFO_YEAR';
export const FETCHING_INFO_MONTH = 'FETCHING_INFO_MONTH';
export const FETCHING_INFO_MONTH = 'FETCHING_INFO_MONTH';
export const FETCHING_UNIQUE_DATES = 'FETCHING_UNIQUE_DATES';

View File

@@ -6,19 +6,23 @@ const defaultState = {
list : [],
infoMonth: [],
infoYear: [],
uniqueDates: {},
fetchingList: false,
fetchingInfoMonth: false,
fetchingInfoYear: false,
fetchingUniqueDates: false,
fetchedList: false,
fetchedInfoMonth: false,
fetchedInfoYear: false
fetchedInfoYear: false,
fetchedUniqueDates: false
};
//default reducer
export default function app(state = defaultState, action) {
switch(action.type){
//fetching functions - we use a fetching state to display loading images
case types.FETCHING_LIST:
return Object.assign({}, state, {
fetchingList: true,
@@ -34,7 +38,13 @@ export default function app(state = defaultState, action) {
fetchingInfoYear: true,
fetchedInfoYear: false
});
case types:FETCHING_UNIQUE_DATES:
return Object.assign({}, state, {
fetchingUniqueDates: true,
fetchedUniqueDates: false
});
//other functions
case types.LOAD_SENSOR_LIST:
return Object.assign({}, state, {
list: action.sensor_list,
@@ -53,6 +63,12 @@ export default function app(state = defaultState, action) {
fetchingInfoYear: false,
fetchedInfoYear: true
});
case types.LOAD_UNIQUE_DATES:
return Object.assign({}, state, {
uniqueDates: action.dates,
fetchingUniqueDates: false,
fetchedUniqueDates: true
});
}
//return present state if no actions get called
return state;