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:
@@ -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));
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -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';
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user