aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLibravatar Renard 2019-10-05 13:29:38 -0300
committerLibravatar Renard 2019-10-05 13:29:38 -0300
commit4005dfba4568b9666557a8e9a5aa8e58362bb59b (patch)
tree9c66ff0869152b309b5f5a8a31b3fe571b5131ac /src
parentd952d13107ddc4b78e7c9945ac96959b7036f222 (diff)
downloadbai-client-4005dfba4568b9666557a8e9a5aa8e58362bb59b.tar.gz
bai-client-4005dfba4568b9666557a8e9a5aa8e58362bb59b.tar.xz
bai-client-4005dfba4568b9666557a8e9a5aa8e58362bb59b.zip
Cache boardsInfo
Diffstat (limited to 'src')
-rw-r--r--src/App.js44
1 files changed, 21 insertions, 23 deletions
diff --git a/src/App.js b/src/App.js
index 7b16769..0edf262 100644
--- a/src/App.js
+++ b/src/App.js
@@ -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);