From 6ddc437c0552f6be5b5890e714b45abd72e6b610 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 14 Oct 2017 18:42:49 -0400 Subject: [PATCH] [add] dynamically grabs all spreadsheets --- .../{Spreadsheet.js => SpreadsheetData.js} | 33 +++++++++++-------- src/components/portal/Category/Creatures.js | 2 +- src/components/portal/Category/Mugic.js | 2 +- src/components/portal/Single/Creature.js | 2 +- 4 files changed, 22 insertions(+), 17 deletions(-) rename src/components/{Spreadsheet.js => SpreadsheetData.js} (75%) diff --git a/src/components/Spreadsheet.js b/src/components/SpreadsheetData.js similarity index 75% rename from src/components/Spreadsheet.js rename to src/components/SpreadsheetData.js index 4eab3a0..0fa569d 100644 --- a/src/components/Spreadsheet.js +++ b/src/components/SpreadsheetData.js @@ -5,21 +5,29 @@ 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 + static base_spreadsheet = "1cUNmwV693zl2zqbH_IG4Wz8o9Va_sOHe7pAZF6M59Es"; get base_image() { return "https://drive.google.com/uc?id="; } - constructor() {} - - // Singleton - static instance = null; - static createInstance() { - var object = new URLS(); - return object; + static path(spreadsheetID) { + return URLS.base_url + spreadsheetID + URLS.data_format; } + constructor() { + // This sets up urls + this.urls = {}; + var self = this; + this.getSpreadsheet(URLS.path(URLS.base_spreadsheet), function(data) { + data.forEach(function(d) { + if (!self.urls[d.gsx$type.$t]) self.urls[d.gsx$type.$t] = {}; + self.urls[d.gsx$type.$t][d.gsx$subtype.$t] = d.gsx$url.$t; + }); + }); + } + + // Singleton + instance = null; static getInstance() { - if (!URLS.instance) { - URLS.instance = URLS.createInstance(); - } + if (!URLS.instance) { URLS.instance = new URLS(); } return URLS.instance; } @@ -35,11 +43,8 @@ class URLS { }); } - static path(spreadsheetID) { - return URLS.base_url + spreadsheetID + URLS.data_format; - } - /* Creatures */ + /* TODO remove legacy getters when introducing state management*/ get Creatures_Card_Data() { return URLS.path("1fUFYhG1NLLkSTzrdbevm6ZMKNP6xLiKUZvM1sY10pVI"); } diff --git a/src/components/portal/Category/Creatures.js b/src/components/portal/Category/Creatures.js index f374a0a..f51e104 100644 --- a/src/components/portal/Category/Creatures.js +++ b/src/components/portal/Category/Creatures.js @@ -2,7 +2,7 @@ import React from 'react'; import Interactive from 'react-interactive'; import { Link } from 'react-router'; import PageNotFound from '../../PageNotFound'; -import API from '../../Spreadsheet'; +import API from '../../SpreadsheetData'; import s from '../../../styles/app.style'; export default class Creatures extends React.Component { diff --git a/src/components/portal/Category/Mugic.js b/src/components/portal/Category/Mugic.js index 8248d91..e043748 100644 --- a/src/components/portal/Category/Mugic.js +++ b/src/components/portal/Category/Mugic.js @@ -3,7 +3,7 @@ import Interactive from 'react-interactive'; import { Link } from 'react-router'; import UnderConstruction from '../../UnderConstruction'; import PageNotFound from '../../PageNotFound'; -import API from '../../Spreadsheet'; +import API from '../../SpreadsheetData'; import s from '../../../styles/app.style'; export default class Mugic extends React.Component { diff --git a/src/components/portal/Single/Creature.js b/src/components/portal/Single/Creature.js index 37e04b2..5c58ffa 100644 --- a/src/components/portal/Single/Creature.js +++ b/src/components/portal/Single/Creature.js @@ -4,7 +4,7 @@ import { Link } from 'react-router'; // import {browserHistory} from 'react-router'; import PageNotFound from '../../PageNotFound'; import UnderConstruction from '../../UnderConstruction'; -import API from '../../Spreadsheet'; +import API from '../../SpreadsheetData'; import s from '../../../styles/app.style'; export default class SingleCreature extends React.Component {