2023-10-22 12:47:56 +00:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
import { useScoresaberScoresStore } from "@/store/scoresaberScoresStore";
|
2023-10-23 08:54:26 +00:00
|
|
|
import { useSettingsStore } from "@/store/settingsStore";
|
|
|
|
import React from "react";
|
|
|
|
const UPDATE_INTERVAL = 1000 * 60 * 15; // 15 minutes
|
2023-10-22 12:47:56 +00:00
|
|
|
|
2023-10-23 08:54:26 +00:00
|
|
|
export default class AppProvider extends React.Component {
|
|
|
|
_state = {
|
|
|
|
mounted: false, // Whether the component has mounted
|
|
|
|
// Whether the data from the async storage has been loaded
|
|
|
|
dataLoaded: {
|
|
|
|
scores: false,
|
|
|
|
settings: false,
|
|
|
|
},
|
|
|
|
};
|
2023-10-22 12:47:56 +00:00
|
|
|
|
2023-10-23 08:54:26 +00:00
|
|
|
async componentDidMount(): Promise<void> {
|
|
|
|
if (this._state.mounted) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this._state.mounted = true;
|
2023-10-22 12:47:56 +00:00
|
|
|
|
2023-10-23 08:54:26 +00:00
|
|
|
// Load data from async storage
|
|
|
|
await useSettingsStore.persist.rehydrate();
|
|
|
|
await useScoresaberScoresStore.persist.rehydrate();
|
|
|
|
|
|
|
|
await useSettingsStore.getState().refreshProfiles();
|
|
|
|
setInterval(() => {
|
|
|
|
useSettingsStore.getState().refreshProfiles();
|
|
|
|
}, UPDATE_INTERVAL);
|
2023-10-22 12:47:56 +00:00
|
|
|
|
2023-10-23 08:54:26 +00:00
|
|
|
await useScoresaberScoresStore.getState().updatePlayerScores();
|
|
|
|
setInterval(() => {
|
|
|
|
useScoresaberScoresStore.getState().updatePlayerScores();
|
|
|
|
}, UPDATE_INTERVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor(props: any) {
|
|
|
|
super(props);
|
|
|
|
}
|
|
|
|
|
|
|
|
render(): React.ReactNode {
|
|
|
|
const props: any = this.props;
|
|
|
|
|
|
|
|
return <>{props.children}</>;
|
|
|
|
}
|
|
|
|
}
|