diff options
author | Renard | 2019-10-05 13:29:38 -0300 |
---|---|---|
committer | Renard | 2019-10-05 13:29:38 -0300 |
commit | 4005dfba4568b9666557a8e9a5aa8e58362bb59b (patch) | |
tree | 9c66ff0869152b309b5f5a8a31b3fe571b5131ac /src | |
parent | d952d13107ddc4b78e7c9945ac96959b7036f222 (diff) | |
download | bai-client-4005dfba4568b9666557a8e9a5aa8e58362bb59b.tar.gz bai-client-4005dfba4568b9666557a8e9a5aa8e58362bb59b.tar.xz bai-client-4005dfba4568b9666557a8e9a5aa8e58362bb59b.zip |
Cache boardsInfo
Diffstat (limited to 'src')
-rw-r--r-- | src/App.js | 44 |
1 files changed, 21 insertions, 23 deletions
@@ -35,31 +35,29 @@ class App extends Component { } componentDidMount() { - fetch("https://bienvenidoainternet.org/cgi/api/boardsExtra") - .then(response => { - return response.json(); - }) - .then(resource => { - let polka = { - allow_image_replies: 1, - allow_images: 1, - board_type: 1, - dir: "polka", - maxsize: 500, - name: "Testing field", - postarea_desc: "", - disable_name: 0, - disable_subject: 0, - allow_spoilers: 0 - }; - if (localStorage.getItem("thereisnourflevel") === null) { - polka = {}; - } - this.setState({ - boardList: resource["boards"].concat(polka), - isLoaded: true + let boardsInfo = localStorage.getItem("boardsInfo"); + let shouldUpdate = false; + if (boardsInfo !== null) { + shouldUpdate = Date.now() / 1000 - JSON.parse(boardsInfo).time > 10080; + } + if (boardsInfo === null || shouldUpdate) { + fetch("https://bienvenidoainternet.org/cgi/api/boardsExtra") + .then(response => { + return response.json(); + }) + .then(resource => { + localStorage.setItem("boardsInfo", JSON.stringify(resource)); + this.setState({ + boardList: resource["boards"], + isLoaded: true + }); }); + } else { + this.setState({ + boardList: JSON.parse(boardsInfo)["boards"], + isLoaded: true }); + } let lsSettings = localStorage.getItem("settings"); let settings = JSON.parse(lsSettings); |