mirror of
https://github.com/chaoticbackup/chaoticbackup.github.io.git
synced 2026-09-07 08:05:24 -05:00
[add] fetch call to database
This commit is contained in:
@@ -1,18 +1,28 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import URLS from '../URLS';
|
||||
import 'whatwg-fetch';
|
||||
|
||||
const propTypes = {
|
||||
children: PropTypes.element,
|
||||
};
|
||||
|
||||
function Creatures({children}) {
|
||||
return (
|
||||
<div>
|
||||
{children||
|
||||
<div>test</div>
|
||||
}
|
||||
</div>
|
||||
);
|
||||
fetch(URLS.Creature_Overworld)
|
||||
.then(function(response) {
|
||||
return response.json();
|
||||
}).then(function(json) {
|
||||
console.log('parsed json', json.feed.entry);
|
||||
}).catch(function(ex) {
|
||||
console.log('parsing failed', ex);
|
||||
})
|
||||
return (
|
||||
<div>
|
||||
{children||
|
||||
<div>test</div>
|
||||
}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Creatures.propTypes = propTypes;
|
||||
|
||||
33
src/components/URLS.js
Normal file
33
src/components/URLS.js
Normal file
@@ -0,0 +1,33 @@
|
||||
import React from 'react';
|
||||
|
||||
class URLS {
|
||||
static base_url = "https://spreadsheets.google.com/feeds/list/";
|
||||
static data_format = "/od6/public/values?alt=json";
|
||||
// + "/od6/public/basic?alt=json"; // Alternate data format
|
||||
|
||||
constructor() {}
|
||||
|
||||
static path(spreadsheetID) {
|
||||
return URLS.base_url + spreadsheetID + URLS.data_format;
|
||||
}
|
||||
|
||||
get Creature_Overworld() {
|
||||
return URLS.path("1Z4_MmlV7uE34nLzrcxslqQKRwL4OBXNA15s7G8eteXU");
|
||||
}
|
||||
|
||||
// Singleton
|
||||
static instance = null;
|
||||
static createInstance() {
|
||||
var object = new URLS();
|
||||
return object;
|
||||
}
|
||||
|
||||
static getInstance() {
|
||||
if (!URLS.instance) {
|
||||
URLS.instance = URLS.createInstance();
|
||||
}
|
||||
return URLS.instance;
|
||||
}
|
||||
}
|
||||
|
||||
export default URLS.getInstance();
|
||||
Reference in New Issue
Block a user