Skip to content
Snippets Groups Projects
Unverified Commit 083bb6af authored by Karel Hala's avatar Karel Hala
Browse files

Log rest API to test things on the fly

parent 09fd10a2
No related branches found
No related tags found
No related merge requests found
...@@ -13,51 +13,54 @@ export const useType = () => { ...@@ -13,51 +13,54 @@ export const useType = () => {
export const useRest = (type) => { export const useRest = (type) => {
const { apiSun, apiTemp, apiAir, apiEnergy } = useAuth0(); const { apiSun, apiTemp, apiAir, apiEnergy } = useAuth0();
const [{ resource, rest }, setRestApi] = useState({}); const [{ resource, rest }, setRestApi] = useState({});
const typeMapper = useCallback((resourceType) => { const typeMapper = useCallback(
const apiTypes = { (resourceType) => {
sunshine: { const apiTypes = {
resource: apiSun, sunshine: {
rest: 'sunshine', resource: apiSun,
}, rest: 'sunshine',
snow: { },
resource: apiSun, snow: {
rest: 'snow', resource: apiSun,
}, rest: 'snow',
precipitation: { },
resource: apiSun, precipitation: {
rest: 'precipitation', resource: apiSun,
}, rest: 'precipitation',
speed: { },
resource: apiAir, speed: {
rest: 'wind-speed', resource: apiAir,
}, rest: 'wind-speed',
pressure: { },
resource: apiAir, pressure: {
rest: 'air-pressure', resource: apiAir,
}, rest: 'air-pressure',
moist: { },
resource: apiAir, moist: {
rest: 'air-moist', resource: apiAir,
}, rest: 'air-moist',
'temp-avg': { },
resource: apiTemp, 'temp-avg': {
rest: 'temp-avg', resource: apiTemp,
}, rest: 'temp-avg',
'temp-min': { },
resource: apiTemp, 'temp-min': {
rest: 'temp-min', resource: apiTemp,
}, rest: 'temp-min',
'temp-max': { },
resource: apiTemp, 'temp-max': {
rest: 'temp-max', resource: apiTemp,
}, rest: 'temp-max',
energy: { },
resource: apiEnergy, energy: {
rest: 'price-per-country', resource: apiEnergy,
}, rest: 'price-per-country',
}; },
return apiTypes[resourceType] || apiTypes.sunshine; };
}, []); return apiTypes[resourceType] || apiTypes.sunshine;
},
[type]
);
useEffect(() => { useEffect(() => {
setRestApi(typeMapper(type)); setRestApi(typeMapper(type));
......
...@@ -315,6 +315,7 @@ const chartData = [ ...@@ -315,6 +315,7 @@ const chartData = [
const HomePage = () => { const HomePage = () => {
const type = useType(); const type = useType();
const [{ resource, rest }] = useRest(type); const [{ resource, rest }] = useRest(type);
const [{ resource: energy, rest: restEnergy }] = useRest('energy');
console.log('=========='); console.log('==========');
console.log('type ↓'); console.log('type ↓');
console.log(type); console.log(type);
...@@ -325,6 +326,9 @@ const HomePage = () => { ...@@ -325,6 +326,9 @@ const HomePage = () => {
console.log('rest ↓'); console.log('rest ↓');
console.log(rest); console.log(rest);
console.log('=========='); console.log('==========');
console.log(restEnergy, 'this is restEnergy');
console.log(energy, 'this is energy');
console.log(fetchData);
const dispatch = useDispatch(); const dispatch = useDispatch();
const data = useSelector(({ exampleReducer }) => exampleReducer.data); const data = useSelector(({ exampleReducer }) => exampleReducer.data);
...@@ -343,9 +347,10 @@ const HomePage = () => { ...@@ -343,9 +347,10 @@ const HomePage = () => {
// resource.get(`/rest/sunshine?${queryBuilder({ max: 10, filter: 2000 })}`).then((data) => { // resource.get(`/rest/sunshine?${queryBuilder({ max: 10, filter: 2000 })}`).then((data) => {
// setMyData(data); // setMyData(data);
// }); // });
resource.get(`/rest/${rest}?${queryBuilder({ max: 1000, skip: 2000 })}`).then(console.log);
dispatch(fetchData(resource, rest, max, skip)); dispatch(fetchData(resource, rest, max, skip));
} }
}, [resource, max, skip]); }, [resource, max, skip, rest]);
const chartData2 = (data || []).reduce( const chartData2 = (data || []).reduce(
(acc, { _id, year, month, ...item }) => ({ (acc, { _id, year, month, ...item }) => ({
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment