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";
|
2023-10-23 15:35:01 +00:00
|
|
|
const UPDATE_INTERVAL = 1000 * 60 * 5; // 5 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-24 11:35:59 +00:00
|
|
|
const initUpdater = async () => {
|
|
|
|
// Load data from async storage
|
|
|
|
await useSettingsStore.persist.rehydrate();
|
|
|
|
await useScoresaberScoresStore.persist.rehydrate();
|
|
|
|
|
|
|
|
await useSettingsStore.getState().refreshProfiles();
|
|
|
|
setInterval(() => {
|
|
|
|
useSettingsStore.getState().refreshProfiles();
|
|
|
|
}, UPDATE_INTERVAL);
|
|
|
|
|
|
|
|
await useScoresaberScoresStore.getState().updatePlayerScores();
|
|
|
|
setInterval(() => {
|
|
|
|
useScoresaberScoresStore.getState().updatePlayerScores();
|
|
|
|
}, UPDATE_INTERVAL);
|
|
|
|
};
|
|
|
|
|
|
|
|
initUpdater();
|
2023-10-23 08:54:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
constructor(props: any) {
|
|
|
|
super(props);
|
|
|
|
}
|
|
|
|
|
|
|
|
render(): React.ReactNode {
|
|
|
|
const props: any = this.props;
|
|
|
|
|
|
|
|
return <>{props.children}</>;
|
|
|
|
}
|
|
|
|
}
|